- Home /
Problem with RPC life
Hi, I have a function that if I hit a player call an RPC that change the life of the hit player over the network, this is my code:
int damage = Random.Range(5, 15);
Debug.Log("Calling setlife with value: " + (hit.collider.transform.parent.gameObject.GetComponent().life - damage));
hit.collider.transform.parent.gameObject.GetComponent().RPC("SetLife", PhotonTargets.AllBuffered, (hit.collider.transform.parent.gameObject.GetComponent().life - damage), gameObject.transform);
And this is my RPC:
[RPC]
void SetLife(int lifeNew, Transform killer)
{
if (lifeNew > 0)
{
gameObject.GetComponent<PlayerNetwork>().life = lifeNew;
}
else
{
Debug.Log("E' morto!");
gameObject.GetComponent<PlayerNetwork>().life = 0;
gameObject.GetComponent<PhotonView>().RPC("RespawnPlayer", PhotonTargets.AllBuffered, killer);
}
}
If I hit a player in my local player editor I see that the other player's life is changed, but in the other game window (the one where is playing the player who was hit), his life doesn't change.
Why?
Your answer
Follow this Question
Related Questions
Problem with identifying players in network 1 Answer
RPC Call doesnt get called 2 Answers
Displaying players name above in multiplayer 1 Answer
RPC call on other scene,NetworkView RPCs in other scene, 0 Answers
RPC custom server best practice 1 Answer