Synchronization of player colours

Hello,i implmented a feature that changes the player colour depending if you are the master client or not.The problem is i need to somehow sync the player colour, because if not you see the player the same colour as you are.

I have this code but it does not seem to work.
private void Start()
    {
        spriteRenderer = GetComponent<SpriteRenderer>();
        view = GetComponent<PhotonView>();
        SetColour();
        view.RPC("RPC_SetColor", RpcTarget.AllBuffered, spriteRenderer.color);
    }
    private void SetColour()
    {
        if (PhotonNetwork.IsMasterClient)
        {
            spriteRenderer.color = Color.blue;
        }
        else
        {
            spriteRenderer.color = Color.red;
        }
    }

    [PunRPC]
    void RPC_SetColor(Color transferredColor)
    {
        gameObject.GetComponent<SpriteRenderer>().color = transferredColor;
    }

Comments

  • You dont need to use buffered RPC. In fact, you dont need an RPC at all.
    Just check photonView.Owner.IsMasterClient on start and then each time master client changes (OnMasterClientSwitched event).
  • LeonidB wrote: »
    You dont need to use buffered RPC. In fact, you dont need an RPC at all.
    Just check photonView.Owner.IsMasterClient on start and then each time master client changes (OnMasterClientSwitched event).

    and how would i implement the sprite renderer into it?
  • Judging by your code, you have already done this.
    You are welcome by the way.

  • LeonidB wrote: »
    Judging by your code, you have already done this.
    You are welcome by the way.

    Ill look into it thank you.