无法使用 Vive 控制器拾取球体。未检测到碰撞
Can't pickup sphere with Vive controller. Collision not detected
我正在做 VR Dev School 的教程。该课程是拾取一个对象并将转换作为父级。这是我从课程中完全复制的代码。我有脚本和一个球体对撞机连接到控制器(左)。我试过切换 'is trigger' on/off。控制台中未检测到碰撞。我没有收到任何错误或警告。
感谢任何帮助,我会回答任何问题
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
并且 trigger/collision 应该被检测到。
我正在做 VR Dev School 的教程。该课程是拾取一个对象并将转换作为父级。这是我从课程中完全复制的代码。我有脚本和一个球体对撞机连接到控制器(左)。我试过切换 'is trigger' on/off。控制台中未检测到碰撞。我没有收到任何错误或警告。
感谢任何帮助,我会回答任何问题
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
并且 trigger/collision 应该被检测到。