Question by 
               Lemaw · Feb 18, 2016 at 04:16 PM · 
                c#uinetworkinguser interfacehealthbar  
              
 
              Need help syncing healthbar
Could anyone tell me what's wrong here? The enemy dies on both side when the health reach 0 but the health bar only move on server side, even when it got shot from client side the healthbar only move on server side.
 using UnityEngine;
 using UnityEngine.Networking;
 using UnityEngine.UI;
 
 public class Enemy : NetworkBehaviour, IDamagable
 {
     private Image healthbar;
 
     private float maxHealth = 50;
     [SyncVar]
     public float currentHealth;
 
     void Start()
     {
         healthbar = GameObject.Find("Canvas").transform.FindChild("Healthbar").transform.Find("Healthbar Foreground").GetComponent<Image>();
         currentHealth = maxHealth;
     }
 
     void Update()
     {
         if (currentHealth <= 0)
             NetworkServer.Destroy(gameObject);
     }
 
     public void Damage(float damage)
     {
         if (!isServer)
             return;
 
         currentHealth -= damage;
         healthbar.fillAmount = currentHealth / maxHealth;
     }
 }
 
               Thanks.
               Comment
              
 
               
              Oh and if i put [syncvar] above
 private Image healthbar;, 
 
                  it just give me an error.
Your answer
 
             Follow this Question
Related Questions
C sharp script, to open a Unity standalone .exe file on a network drive 0 Answers
Method Skipping Inputs 2 Answers
Score UI per player 1 Answer
Dynamic Menu C# 0 Answers
How to place sprite above GameObject? 2 Answers