Replenish Own Player's Health without affecting other fellow Players
Options
My goal is simple:
When the player picks up a health kit, it replenishes his health back to 100.
I have this code:
That will be called when I encounter a health kit:
However, in doing this, I affect all other player's health as well. I just want my own player to get its health to 100, and then broadcast to everyone that "hey, my health is now full".
When the player picks up a health kit, it replenishes his health back to 100.
I have this code:
[PunRPC]
public void ReplenishHealth(int newHealth)
{
playerHealth = newHealth;
isPlayerAlive = true;
Debug.Log("Called!");
}
That will be called when I encounter a health kit:
PhotonView pViewOwn = transform.GetComponent<PhotonView>();
pViewOwn.RPC("ReplenishHealth", RpcTarget.AllBuffered, 100);
However, in doing this, I affect all other player's health as well. I just want my own player to get its health to 100, and then broadcast to everyone that "hey, my health is now full".
0
Comments
-
I think if(photonView.IsMine) { } can be used to determine the owning player and health value can be synced via if (stream.IsWriting) {} - OnPhotonSerializeView . https://doc.photonengine.com/en-us/pun/v2/demos-and-tutorials/pun-basics-tutorial/player-networking . I think PhotonNetwork.RaiseEvent can be used as well to transfer health data.1