Complete Newbie to both Unity and SteamVR (and C# for that matter). I have managed to get input from the dPad to my debug log.
I am currently seeing anywhere from 12 to 19 responses for every press of the button. I really only one it to trigger once as this is ultimately going to be tied to functionality that will teleport the player to a fixed spot adjacent to their current position. My hunch is, Update may not be the best place to grab this input. Of course, its more likely I am going about this entirely incorrectly. At any rate, here is the script I am using. Any advice would be appreciated.
using UnityEngine;
using System.Collections;
public class MovementController : MonoBehaviour {
private SteamVR_Controller.Device controller { get { return SteamVR_Controller.Input((int)trackedObj.index); } }
private SteamVR_TrackedObject trackedObj;
public bool dUp = false;
public bool dDown = false;
public bool dLeft = false;
public bool dRight = false;
void Start ()
{
trackedObj = GetComponent<SteamVR_TrackedObject>();
}
void Update()
{
if (controller == null)
{
Debug.Log("Controller not initialized");
return;
}
if (controller.GetPress(SteamVR_Controller.ButtonMask.Touchpad))
{
if (controller.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad).y > 0.5f)
{
dUp = true;
Debug.Log(trackedObj.index + " Movement Dpad Up");
}
if (controller.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad).y < -0.5f)
{
dDown = true;
Debug.Log(trackedObj.index + " Movement Dpad Down");
}
if (controller.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad).x > 0.5f)
{
dRight = true;
Debug.Log(trackedObj.index + " Movement Dpad Right");
}
if (controller.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad).x < -0.5f)
{
dLeft = true;
Debug.Log(trackedObj.index + " Movement Dpad Left");
}
}
}
}