Need Help in Syncing Health using Photon

Well I tried 100s of ways but I cant get my AI’s Health Sync across network :confused:
My Script:
public HealthScript hs;
public float Health;

void Update () {
if (!photonView.isMine) {
hs.health = Health;
} else {
Health = hs.health;
}
}
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info){
if (stream.isWriting) {
stream.SendNext(Health);
} else {
Health = (float)stream.ReceiveNext();
hs.health = (float)stream.ReceiveNext();
}
}

Can anyone please help, I want to sync the health float! Will be more than appreciated

FIXED IT :smile:

i face the same problem with you may you tell me how you fix it pls

extremely sorry for not mentioning

here is the code

public class RPCHit : Photon.MonoBehaviour {
    public HealthScript hs;
        public float Health;
    // Use this for initialization
    void Start () {
            //hs = GetComponent<HealthScript> ();
    }
   
    // Update is called once per frame
    void Update () {
            if (!photonView.isMine) {
                hs.health = Health;
            }
                if (photonView.isMine) {
                    Health = hs.health;
                }
        }
    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info){
                if (stream.isWriting) {
                    stream.SendNext (Health);
                } else if (stream.isReading) {
                    Health = (float)stream.ReceiveNext();
                }
            }


}
1 Like