- Home /
Question by
KaidaStudios · Sep 11, 2017 at 10:47 PM ·
unity 5networkingdamage
UNET sending/recieving damage
I have a trigger that is spawned when someone does a melee attack and want it to apply damage when a different client runs into it, not the local. So it works except it only will attack the local, ive tried using isLocalPlayer with no help, both "isLocalPlayer" & "!isLocalPlayer" bring the same results.. any help would be greatly appreciated!
My code on the spawned melee attack trigger:
private void OnTriggerEnter(Collider col)
{
if (col.gameObject.tag == "enemy" || col.gameObject.tag == "Player" && isTrigger)
{
print("HIT NON-LOCAL PLAYER");
col.SendMessage("hit", dmg);
Destroy(gameObject);
}
}
and this is the hit code on the player(Again all works but it only affects local)
[SyncVar(hook = "changehp")]
public float curhp = 1;
void hit(float damage)
{
print("message got here");
if (!isLocalPlayer)
{
print("you got HIT");
Cmdattack(damage);
}
}
[Command]
void Cmdattack(float damage)
{
curhp -= damage;
}
public void changehp (float newcurhp)
{
hpbar.fillAmount = newcurhp;
}
Comment
Your answer