pressing/turning something in VR to do stuff
Hi
I've resolved on my own how to pick up trhings in vr and now I'm trying to make an object that when the contreoller interacts with it performs an action like rotating or play a sound:
public class PlaySound : MonoBehaviour {
public Rigidbody rigidbody;
public AudioSource sound;
private SteamVR_TrackedObject trackedObj;
private SteamVR_Controller.Device Controller {
get { return SteamVR_Controller.Input((int)trackedObj.index); }
}
void Awake()
{
trackedObj = GetComponent<SteamVR_TrackedObject>();
}
void Start()
{
rigidbody = GetComponent<Rigidbody>();
}
private void OnTriggerStay(Collider collider)
{
var device = SteamVR_Controller.Input((int)Controller.index);
// If controller triggers
if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) {
// play sound
sound.Play();
}
}
}
Doesn't work of course :(
How can I make the controller activate the script?
Comment
Your answer
Follow this Question
Related Questions
How to Lock Steam VR camera to the head of the Player model 0 Answers
vr controller control script 0 Answers
Making KeyCodes Equal to Touch Triggers? 1 Answer
How do I resolve, get_isActiveAndEnabled can only be called from the main thread error 1 Answer
Steam Leaderboards in Unity, upload time since level load 0 Answers