- Home /
How Could I sync a value of varibale in both device?
Actually I am working On multiplayer Project cricket game , I have made two boolean value "Cbathitside" for !photonnetwork.ismasterclient and "Sbathitside" for Photonnetwork.ismasterclient. Boolean value is equal to True only in batting side.
Void OnTriggerEnter(Collider other)
{
if(other.Tag("ball"))
{
if (MatchTypeSelection.instance.matchType == MatchType.MultiPlayer)
{
if (MatchTypeSelection.instance.matchType == MatchType.MultiPlayer && (RotateCoin.instance.CbatHitside == true || RotateCoin.instance.SbatHitside == true))
{
randomBowlerPower = Random.Range(0, 3);
}
if (MatchTypeSelection.instance.matchType == MatchType.MultiPlayer && (RotateCoin.instance.CbatHitside == false || RotateCoin.instance.SbatHitside == false))
{
Batsmanhitshottiming(randomBowlerPower);
print("randomBolwerPower" + randomBowlerPower);
}
}
}
}
I have made BatsmanshothitTiming () for syncing that value (randomBolwerpower) in other device but it is not working please Correct me How could i make Random value should be same in both device.
[PunRPC]
public void Batsmanhitshottiming(int randombowlerpower)
{
randomBowlerPower = randombowlerpower;
this.GetComponent<PhotonView>().RPC("Batsmanhitshottiming", PhotonTargets.Others,randomBowlerPower);
}
Any help would be apperciated.
Answer by Captain_Pineapple · Nov 02, 2019 at 02:58 PM
If you want to call a function that is then called for everyone you have to go with:
photonView.RPC("Batsmanhitshottiming", PhotonTargets.All, randomBowlerPower);
this will then call the function for everyone involved. The rpc should then be like this:
[PunRPC]
public void Batsmanhitshottiming(int randombowlerpower)
{
randomBowlerPower = randombowlerpower;
}
Though since you post this question this makes me assume you still did not bother to read the DOCUMENTATION on photon rpcs.
Please do that before you post another question on photon rpcs. This should als kind of exmplain why your rpc does keep repeating in all your other 5 "Onclick function keeps" repeating question where you did not bother to add code. An RPC must not call itself.
Same thing I have written in my code as well u can check But its not working
[PunRPC]
public void Batsmanhitshotti$$anonymous$$g(int randombowlerpower)
{
randomBowlerPower = randombowlerpower;
this.GetComponent<PhotonView>().RPC("Batsmanhitshotti$$anonymous$$g", PhotonTargets.Others,randomBowlerPower);
}
did you even read my post to the end? It says: A RPC $$anonymous$$UST NOT CALL ITSELF
you just reposted your original code where the rpc "Batsmanhitsshotti$$anonymous$$g" calls itself again.
Answer by Gamer98898 · Nov 05, 2019 at 07:13 AM
@Captain_Pineapple Thanks, Yes I already read Documentation regarding Photon as well I have uploaded my code for Onclick Click function. I have noticed one thing that data is getting delayed for few nanoseconds because of this issue Gameplay is not working properly . Actually data values is syncing but after getting passed ball through batsman . Any kind of help would be apperciable
Your answer

Follow this Question
Related Questions
Photon Help~ for Fps Muti 0 Answers
OnConnectedToMaster() vs IsConnectedAndReady? 1 Answer
How To List Rooms (PUN 2) 1 Answer