Hi guys! I just want to say that I am a complete beginner and I’m trying to make a simple LAN game using UNet, I have a code for the Player Health with a syncvar health:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
public class PlayerHealth : NetworkBehaviour
{
public Text healthtxt;
[SyncVar]public int health = 100;
private void Update()
{
healthtxt.text = "HEALTH = " + health;
}
private void OnTriggerEnter(Collider other)
{
if(other.CompareTag("Sword"))
{
TakeDamage(other);
}
}
void TakeDamage(Collider cmd_other)
{
health -= cmd_other.gameObject.GetComponent<SwordDamage>().damage;
}
}
the thing is that the host is not updating his health value and neither the text, and I can’t figure out why, some help would be very much appreciated