1

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 with Photon Unity Networking. 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();
    }
}
}

As you can probably see, I'm a beginner. With this code, when I put my hand in the cube and press the trigger, nothing happens. If anyone can provide any help or even an alternative, I'd be very grateful.

Kind regards, TheMusiken

TheMusiken
  • 11
  • 3

0 Answers0