How to sync RPC function Photon Network?
I am trying to make the host call one single function for all clients in the game. If the random integer value = 1 on the host's scene, the random value should be 1 for every single other client in the scene.
Here is the loop in Update():
randomTimer -= Time.deltaTime;
if (PhotonNetwork.IsMasterClient)//The host sends this function to the whole session
{
if(randomTimer <= 0)
{
GetComponent<PhotonView>().RPC("RandomNumberPick", RpcTarget.AllBuffered);
randomTimer = 3f;
}
}
Here is the RPC function:
[PunRPC]
void RandomNumberPick()
{
randomScore = Random.Range(0, 30);
randomScoreText.text = randomScore.ToString("0");
}
Currently, all that's happening is the function is being called at the same time for all clients. What I want to happen is for the randomScore value to be the same for all clients.
I was trying to sync a variable across all clients in the game. Not just call an RPC function across all clients.
Answer by KloverGames · Nov 18, 2021 at 05:08 PM
Nvm guys I watched a YouTube tutorial and he explained exactly what I was trying to do.
Here is the link if you are having the same problem: https://youtu.be/EwI8WG5MpYw
Your answer
Follow this Question
Related Questions
Photon RPC Only Working Halfway 1 Answer
Photon Sync Var 1 Answer
Photon RPC 2 Answers
UNET - syncvars 2 Answers
Unity Photon doesn't Spawn Player 0 Answers