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:
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?
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);
}
}
{
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?
0
Best Answers
-
Your RPC is incorrect. You aren't sending the bool _iSVoice to other players. The RPC will be called and on the receiving player it will check _isVoice and it will of course still be false as nothing has set it.5
-
I would send the photon_id and the bool value in your RPC call and then you can set the icons according to the owning players based on the sent bool value.5
-
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!0
Answers
-
Your RPC is incorrect. You aren't sending the bool _iSVoice to other players. The RPC will be called and on the receiving player it will check _isVoice and it will of course still be false as nothing has set it.5
-
I would send the photon_id and the bool value in your RPC call and then you can set the icons according to the owning players based on the sent bool value.5
-
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!0