不能用Vive控制器拾取球体。未检测到碰撞

时间:2016-08-14 19:28:16

标签: c# unity3d collision-detection virtual-reality

我正在从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);
        }
    }
}

1 个答案:

答案 0 :(得分:1)

这是一个简单的错误。它应该是OnTriggerStay而不是onTriggerStay。请大写O并检测触发器/碰撞。