Best way to sync player's health
Options
Hi
what is the best approach for sync the player's health? I tried several ways the last I tried was adding health as a custom property to the photonplayer but when the player is hit it only looses health in the game of the person attacking and after like a second the player regain all the health (it syncs with the player getting hit who is at full health), I thought it may be my "hit" function
what is the best approach for sync the player's health? I tried several ways the last I tried was adding health as a custom property to the photonplayer but when the player is hit it only looses health in the game of the person attacking and after like a second the player regain all the health (it syncs with the player getting hit who is at full health), I thought it may be my "hit" function
[RPC] public void HitFunc(float Damage, int AttackerID) { if (!IsShieldOn){ LastAttackerID = AttackerID; _PhotonPlayer.SetFloatProperty("CurHealth", (float)_PhotonPlayer.customProperties["CurHealth"] - Damage); Renderer[] ChildrenRenderers = gameObject.GetComponentsInChildren<Renderer>(); foreach (Renderer R in ChildrenRenderers) { StartCoroutine(ChangeColor(R)); } } }
0
Comments
-
I'm new to photon but I think you need to use this.
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.isWriting) { //We own this player: send the others our data stream.SendNext((int)controllerScript._characterState); stream.SendNext(transform.position); stream.SendNext(transform.rotation); } else { //Network player, receive data controllerScript._characterState = (CharacterState)(int)stream.ReceiveNext(); correctPlayerPos = (Vector3)stream.ReceiveNext(); correctPlayerRot = (Quaternion)stream.ReceiveNext(); } }
http://doc-api.exitgames.com/en/pun/cur ... neral.html
What it does is sync those variables for the gameobjects on each individual program.0