Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class LifeBar : MonoBehaviour {
  6.  
  7.     public IHealth health;
  8.  
  9.     public GameObject[] healthImages;
  10.    
  11.     public GameObject healthContainer;
  12.  
  13.    
  14.     void Start () {
  15.         health = FindObjectOfType<PlayerController>().GetComponent<IHealth>();
  16.         health.OnHealthChanged += HealthUpdated;      
  17.     }
  18.    
  19.     // Update is called once per frame
  20.     void Update () {
  21.        
  22.     }
  23.  
  24.     private void HealthUpdated(float currentHealth)
  25.     {
  26.         for (int i = 0; i < healthImages.Length; i++)
  27.         {
  28.             if (i < currentHealth)
  29.             {
  30.                 healthImages[i].SetActive(true);              
  31.             }
  32.             else
  33.             {
  34.                 healthImages[i].SetActive(false);
  35.                 healthImages[i].GetComponent<Animator>().SetTrigger("PlayDecreaseHealth");
  36.             }
  37.         }
  38.     }
  39. }