我正在从VR Dev School做一个教程。 课程是拾取对象和父变换。 这是我从课程中完全复制的代码。 我有脚本和球形对撞机连接到控制器(左)。 我试过打开/关闭“触发器”。 控制台中未检测到冲突。 我没有收到任何错误或警告。
任何帮助表示赞赏,我会回答任何问题
using UnityEngine; using System.Collections; [RequireComponent(typeof(SteamVR_TrackedObject))] public class PickupParent : MonoBehaviour { SteamVR_TrackedObject trackedObj; SteamVR_Controller.Device device; void Awake () { trackedObj = GetComponent<SteamVR_TrackedObject>(); } void FixedUpdate () { device = SteamVR_Controller.Input((int)trackedObj.index); if(device.GetTouch(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You are holding 'Touch' on the trigger"); } if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You activated touchdown on the trigger"); } if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You activated TouchUp on the trigger"); } if (device.GetPress(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You are holding 'Press' on the trigger"); } if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You activated press down on the trigger"); } if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You activated press Up on the trigger"); } } void onTriggerStay(Collider col) { Debug.Log("You have collided with " + col.name + " and activated onTriggerStay"); if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You have collided with " + col.name + " while holding down Touch"); col.attachedRigidbody.isKinematic = true; col.gameObject.transform.SetParent(gameObject.transform); } } }I am doing a tutorial from VR Dev School. The lesson is Picking Up an Object and Parent the Transform. This is the code I copied exactly from the lesson. I have the script and a sphere collider attached to controlller(left). I've tried toggling 'is trigger' on/off. The collision is not being detected in the console. I am not receiving any errors or warnings.
Any assistance is appreciated and I will answer any questions
using UnityEngine; using System.Collections; [RequireComponent(typeof(SteamVR_TrackedObject))] public class PickupParent : MonoBehaviour { SteamVR_TrackedObject trackedObj; SteamVR_Controller.Device device; void Awake () { trackedObj = GetComponent<SteamVR_TrackedObject>(); } void FixedUpdate () { device = SteamVR_Controller.Input((int)trackedObj.index); if(device.GetTouch(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You are holding 'Touch' on the trigger"); } if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You activated touchdown on the trigger"); } if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You activated TouchUp on the trigger"); } if (device.GetPress(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You are holding 'Press' on the trigger"); } if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You activated press down on the trigger"); } if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You activated press Up on the trigger"); } } void onTriggerStay(Collider col) { Debug.Log("You have collided with " + col.name + " and activated onTriggerStay"); if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You have collided with " + col.name + " while holding down Touch"); col.attachedRigidbody.isKinematic = true; col.gameObject.transform.SetParent(gameObject.transform); } } }最满意答案
这是一个简单的错误。 它应该是OnTriggerStay而不是onTriggerStay 。 请大写O并检测触发/碰撞。
This is a simple mistake. It should be OnTriggerStay not onTriggerStay. Please capitalize the O and trigger/collision should be detected.
更多推荐
发布评论