Hello,
I’m making a multiplayer fighting game with Photon. I have a problem with controlling my variables over Photon Rpcs. For example, when somebody won the round i am sending a RPC to PhotonTargets.AllViaServer and in this function firstly show who won the last round and start a coroutine for countdown to restart round, after it i want to reset all health, position datas to default. But it only reset these datas for winner, not for everyone in the game. What could be wrong, i’m searching for it but didn’t figure out what i’m missing.
void Damage(){
recentHealth -= Damage;
if(recentHealth<=0)
{
RPC.("gg", PhotonTargets.AllViaServer, winnerName);
}
}
[PunRPC]
public void gg(string winnerName)
{
//show winnerName in Canvas.
StartCoroutine(refreshScene(1f));
}
IENumerator refreshScene(float time){
//countdown on canvas.
//when coutndown finishes reset health and positions
}
Thanks.
I did a solution but it feel weird. When i call a reseter function in the same class with rpc, everybody except who calls the rpc’s variables are not reseting. But when i call a reseter function from different class, everybody’s variables reseting right. What am i missing? I would be very grateful if someone clear the things. Thank you again.
PS: Sorry if i couldn’t describe well because of my english level.
I’m sorry, but you might have to re-explain what you do (now). The code and your new solution don’t match and it’s hard to help this way.
You are right, sorry for it. All the code above is in playerHealth class on player’s gameobject. I have a GameManager object and script for instantiating, networking things to handled. When i want to reset healths in RefreshScene function as “currentHealth = fullHealth;” its only resets health of who won the last round. But when i create a function in GameManager to reset their healths and call it in RefreshScene, it resets for both.
What i don’t understand is, why “currentHealth = fullHealth” code inside PunRPC is not calling each for own, just calling for winner.
Hope i did explain it well. Thank you very much.
RPCs are called on some object (the one that the PhotonView is on). This way, the RPC has some context.
It depends on what you do in the RPC method. Maybe it affects only the sender or the player who’s game object was called.
In doubt, you need to log what you’re doing. Add output to all RPCs and check what’s logged on both players.