Я хочу просто получить ввод контроллера от пользователя в моей игре VR, и я также хочу использовать систему взаимодействия SteamVR, чтобы я мог легко реализовать элементы пользовательского интерфейса. Однако я не могу получить входные данные от контроллера из сценария Hand.
Все, что я сделал, - это перетащил префаб «Player», а затем написал сценарий для перехода к объекту Hand для получения входных данных от триггеров.
private Hand _hand; // The hand object
private SteamVR_Controller.Device controller; // the controller property of the hand
void Start ()
{
// Get the hand componenet
_hand = GetComponent<Hand>();
// Set the controller reference
controller = _hand.controller;
}
void Update ()
{
// === NULL REFERENCE === //
if ( controller.GetHairTrigger())
{
Debug.Log ("Trigger");
}
}
Это дает мне исключение null ref для объекта «контроллер». Я также пробовал установить компонент контроллера в OnEnable()
и Awake()
, но это тоже не сработало. Даже в Update()
. Поэтому по какой-то причине класс Hand
SteamVR не содержит ссылки на контроллер. Я что-то делаю не так? Мне не хватает какой-то спецификации индекса, когда я получаю контроллер?
Я могу получить ввод от контроллера следующим образом:
private SteamVR_TrackedObject trackedObj; // The tracked object that is the controller
private SteamVR_Controller.Device Controller // The device property that is the controller, so that we can tell what index we are on
{
get { return SteamVR_Controller.Input((int)trackedObj.index); }
}
private void Awake()
{
// Get the tracked object componenet
trackedObj = GetComponent<SteamVR_TrackedObject>();
}
void Update()
{
if(Controller.GetHairTrigger()){
Debug.Log("hey trigger");
}
}
Но тогда я не могу использовать систему взаимодействия. У кого-нибудь есть подсказка?