So, I started using Unity Photon Engine and RPC very recently. To Summarize, my project is about changing color of a square by using a color picker, but the color of the square should change in all instances of the game, During Run-Time, Master Client can change the color of the square and it changes in all instances(PCs) but, In case of other clients they can neither change the color of their own square nor the color of squares on other instances(PCs). It's like the master client has the permission to change colors but not anybody else.
using System;
using System.Collections;
using System.Collections.Generic;
using Photon.Pun;
using TMPro;
using UnityEngine;
using UnityEngine.Experimental.TerrainAPI;
public class ColorChange : MonoBehaviourPunCallbacks
{
public FlexibleColorPicker colorPickerReference;
private SpriteRenderer sqaureReference;
private PhotonView myPhotonView;
private PhotonView colorPickerReferencePhotonView;
private Color colorReference;
private void Start()
{
myPhotonView = GetComponent<PhotonView>();
sqaureReference = GetComponent<SpriteRenderer>();
colorPickerReferencePhotonView = colorPickerReference.gameObject.GetComponent<PhotonView>();
}
private void Update()
{
colorReference = colorPickerReference.color;
if (myPhotonView.IsMine)
{
sqaureReference.color = colorPickerReference.color;
myPhotonView.RPC("ColorChangeFunc", RpcTarget.All, colorReference.r, colorReference.g, colorReference.b,
colorReference.a);
}
}
[PunRPC]
void ColorChangeFunc(float r, float g, float b, float a)
{
Color color = new Color(r, g, b, a);
sqaureReference.color = color;
}}
Note: The Photon plugin is working as the connection is being established and the lobby is being joined.
I Thank you in advance, All help is appreciated.