スタジオおふとん

プログラミング系

VRTKでトリガー検知

注意点は、VRTK_Controller Eventsがアタッチされているオブジェクトにくっつけること。

using VRTK;

public class Controller : MonoBehaviour {

    // Use this for initialization
    void Start () {
        if (GetComponent<VRTK_ControllerEvents>() == null)
        {
            Debug.LogError("VRTK_ControllerEvents_ListenerExample is required to be attached to a Controller that has the VRTK_ControllerEvents script attached to it");
            return;
        }
        GetComponent<VRTK_ControllerEvents>().TriggerPressed += new ControllerInteractionEventHandler(DoTriggerPressed);
    }
    

    private void DoTriggerPressed(object sender, ControllerInteractionEventArgs e)
    {
        Debug.Log("Trigger Press");
    }

}

下記のページを参考にGetComponentと対応する関数を必要な分だけ書けば、トリガー以外もできるはず。

negilab-unity.com