Health Sync Issue over Network

Hello everyone, I just wanted to sync the health of networked players with below code. It manages the decal instantiation and health update as well.

Player prefab is synced with photonview. Somehow, I cannot serialize the shipHealth variable across the network. I shoot cannonballs with an RPC function and projectiles hitting the player modifies health as -1 for each hit.

For each client, player's own health is updated regarding the hits. However, opposing players health stays unmodified eventhough it got hit. The other player also sees his own player's health modified, but the opposing player's health is not modified again.

To sum up, only local players own avatar can see its health updated for each client. (When I remove photonView.IsMine from below code, every instance evaluates decals and hits locally which might result in inconsistent hit registirations)

I am also using serilaized transforms for the same player.

Any ideas what might be the issue here?

    void OnCollisionEnter(Collision collision)
            ContactPoint contact = collision.contacts[0];
            Vector3 temas = contact.point;
            Vector3 local = contact.normal;
            Decal.ProjectAt(DecalPrefab, Target, temas, -local);
            GameObject impactCopy = Instantiate(impact, temas, Quaternion.LookRotation(local, Vector3.up)) as GameObject;

            if (GetComponent<PhotonView>().IsMine)
                shipHealth -= 1;

    void IPunObservable.OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
            if (stream.IsWriting)
                // We own this player: send the others our data
                // Network player, receive data
                this.shipHealth = (float)stream.ReceiveNext();


Sign In or Register to comment.