hp update problem
ok so ive been trying to get this to work for 5 hours
this is the script that syncs the health, evey player has it attatched to them
and this is the thing that updates the health
what happens is: if i attack the other player with the sword, its health updates on my screen but not on their screen
if i attack myself with the sword, my hp updates on both screens, as it should. whats the problem
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Normal.Realtime;
public class playerHealthSync : RealtimeComponent<playerHealthModel> {
public int health = 20;
public Realtime rt;
public Transform spawn1;
public Transform spawn2;
public GameObject player;
protected override void OnRealtimeModelReplaced(playerHealthModel previousModel, playerHealthModel currentModel) {
if (previousModel != null) {
previousModel.hpDidChange -= HpDidChange;
}
if (currentModel != null) {
if (currentModel.isFreshModel){
currentModel.hp = health;
}
UpdateHp();
currentModel.hpDidChange += HpDidChange;
}
}
private void HpDidChange(playerHealthModel model, int value) {
UpdateHp();
}
private void UpdateHp() {
print("updated hp");
health= model.hp;
}
public void SetHp(int hp) {
print("set hp");
model.hp = hp;
}
}using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Normal.Realtime;
public class playerHealthSync : RealtimeComponent<playerHealthModel> {
public int health = 20;
public Realtime rt;
public Transform spawn1;
public Transform spawn2;
public GameObject player;
protected override void OnRealtimeModelReplaced(playerHealthModel previousModel, playerHealthModel currentModel) {
if (previousModel != null) {
previousModel.hpDidChange -= HpDidChange;
}
if (currentModel != null) {
if (currentModel.isFreshModel){
currentModel.hp = health;
}
UpdateHp();
currentModel.hpDidChange += HpDidChange;
}
}
private void HpDidChange(playerHealthModel model, int value) {
UpdateHp();
}
private void UpdateHp() {
print("updated hp");
health= model.hp;
}
public void SetHp(int hp) {
print("set hp");
model.hp = hp;
}
}this is the script that syncs the health, evey player has it attatched to them
and this is the thing that updates the health
if(canHit && coll.tag=="MPPlayer")
{
coll.gameObject.transform.GetChild(0).GetComponent<RealtimeView>().ClearOwnership();
coll.gameObject.transform.GetChild(0).GetComponent<playerHealthSync>().SetHp(coll.gameObject.transform.GetChild(0).GetComponent<playerHealthSync>().health-damagePlayer);
}if(canHit && coll.tag=="MPPlayer")
{
coll.gameObject.transform.GetChild(0).GetComponent<RealtimeView>().ClearOwnership();
coll.gameObject.transform.GetChild(0).GetComponent<playerHealthSync>().SetHp(coll.gameObject.transform.GetChild(0).GetComponent<playerHealthSync>().health-damagePlayer);
}what happens is: if i attack the other player with the sword, its health updates on my screen but not on their screen
if i attack myself with the sword, my hp updates on both screens, as it should. whats the problem
