Show voice icon for all

Options
Hi. Each of my player's prefab have an object RawImage like as voiceIcon. If I pressing key it should be showed for all.

This is my script:
public class VoiceController : Photon.PunBehaviour
{

private bool _isVoice;
[SerializeField] private GameObject _voiceIcon;

private void Update()
{
if(!PhotonNetwork.inRoom) return;
_isVoice = Input.GetKey(KeyCode.K);
photonView.RPC("CheckVoice", PhotonTargets.All);
}

[PunRPC]
private void CheckVoice()
{
_voiceIcon.SetActive(_isVoice);
}
}

It does not works. If one client pressing K he see icons of others and his icon. But other clients do not see it.

This script attached to player prefab.

Any advices?

Best Answers

  • dNazarik
    dNazarik
    Answer ✓
    Options
    I solved it by next:

    I inherited my script from Photon.MonoBehavior and I have implemented method OnPhotonSerializeView:

    private void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
    if (stream.isWriting)
    {
    stream.SendNext(_voiceIcon.activeSelf);
    }
    else
    {
    _voiceIcon.SetActive( (bool) stream.ReceiveNext() );
    }
    }

    Then I drag and drop this script to the observed components to my photon view component.

    It works good.

    @Ash68 thank you for the answer!

Answers

  • dNazarik
    dNazarik
    Answer ✓
    Options
    I solved it by next:

    I inherited my script from Photon.MonoBehavior and I have implemented method OnPhotonSerializeView:

    private void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
    if (stream.isWriting)
    {
    stream.SendNext(_voiceIcon.activeSelf);
    }
    else
    {
    _voiceIcon.SetActive( (bool) stream.ReceiveNext() );
    }
    }

    Then I drag and drop this script to the observed components to my photon view component.

    It works good.

    @Ash68 thank you for the answer!