using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class HealthController : MonoBehaviour { public float health = 100; public Slider HealthUI; // Use this for initialization void Start () { HealthUI = GameObject.Find("HealthBar").GetComponent(); HealthUI.maxValue = health; } // Update is called once per frame void Update () { HealthUI.value = health; if (health < 0) { Destroy(this.gameObject); } } }