【问题标题】:Global Audio in unity using photon使用光子统一全局音频
【发布时间】:2022-08-05 10:32:58
【问题描述】:

我试图在统一中使用光子制作多人游戏。我创建了一个房间并加入了我的朋友。当其中一个玩家按下特定键时,我想为所有玩家播放声音。但是当我按下键时,只有我能听到声音。我希望我的朋友听到声音,并且我希望在我的朋友按键时听到相同的声音。

public class PlaySound : MonoBehaviour
{
    public KeyCode buton;
    public AudioSource sunet;
    
    void Update()
    {
        
        if (Input.GetKeyDown(buton))
        {
            sunet.Play();
        }
    } 
}
  • 在 RPC 中调用它。
  • unity是否给出错误或警告?
  • @MattiaRaffaele 不

标签: c# unity3d photon


【解决方案1】:

您需要在 RPC 中播放音频才能让其他人听到音频。我现在无法测试代码,但我相信这会奏效。

public class PlaySound : MonoBehaviourPunCallbacks
{
    public KeyCode buton;
    public AudioSource sunet;
    
    void Update()
    {
        if (Input.GetKeyDown(buton))
        {
            photonView.RPC("PlayAudio", RPCTarget.All);
        }
    }

    [PunRPC]
    void PlayAudio()
    {
        sunet.Play();
    }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-14
    • 2011-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多