How to create a button in VR with PUN?
Options
Hi all,
I've been working on a solution for weeks now and I think it's time to reach out. I'm trying to make a button that plays a sound when pressed by a controller, everyone will hear that sound. Using VRTK and PlayoVR, I'm able to make a non-networked version where the player can put their hand through a cube, click the trigger from the controller, and it makes a sound.
This is the code for that cube:
Kind regards,
TheMusiken
I've been working on a solution for weeks now and I think it's time to reach out. I'm trying to make a button that plays a sound when pressed by a controller, everyone will hear that sound. Using VRTK and PlayoVR, I'm able to make a non-networked version where the player can put their hand through a cube, click the trigger from the controller, and it makes a sound.
This is the code for that cube:
namespace VRTK.Examples { using UnityEngine; public class Whirlygig : VRTK_InteractableObject { public GameObject AudioSource; public AudioSource LeftSpeaker; public override void StartUsing(VRTK_InteractUse currentUsingObject = null) { AudioSource.GetComponent<AudioSource>().Play(); } } }Where I get lost is how to network it. This is what I have:
namespace PlayoVR { using UnityEngine; using VRTK; using UnityEngine.Video; using NetBase; public class PlaySync : Photon.MonoBehaviour { public AudioSource LeftSpeaker; public GameObject Whirlgig; private bool StartUsing; // Use this for initialization void Awake() { GetComponent<VRTK_InteractableObject>().InteractableObjectUsed += new InteractableObjectEventHandler(DoPlay); } void DoPlay(object sender, InteractableObjectEventArgs e) { StartUsing = true; } // Update is called once per frame void Update() { // Handle firing if (StartUsing) { CmdPlay(); StartUsing = false; } } void CmdPlay() { photonView.RPC("NetPlay", PhotonTargets.All); } [PunRPC] void NetPlay() { LeftSpeaker.Play(); } } }It does not work. I'll put my hand in the cube, press the trigger and nothing happens. If anyone can provide any help, I'd be very grateful.
Kind regards,
TheMusiken
0