I’m using PUN2, When a player connects, I want their sprite render to be a random color, and for that color to be synced for all other players.
For some reason the following code prevents the other players from appearing on the screen however I can still see the player objects in the inspector. If I remove the RPC call, I can see the other players fine, but their colors don’t sync.
public class Player : MonoBehaviour
{
private PhotonView myPV;
public string nickname;
public Color color;
private void Awake()
{
}
// Start is called before the first frame update
void Start()
{
myPV = GetComponent<PhotonView>();
if (myPV.IsMine)
{
gameObject.GetComponentInChildren<Camera>().enabled = true;
gameObject.GetComponentInChildren<TopDownCharacter>().enabled = true;
color = Random.ColorHSV();
myPV.RPC("RPC_SendColor", RpcTarget.AllBuffered);
}
}
[PunRPC]
void RPC_SendColor()
{
gameObject.GetComponentInChildren<SpriteRenderer>().color = color;
}
}