Newer
Older
Dreamsturbia-Project-IADE-Unity3D / Assets / Scripts / UIController.cs
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class UIController : MonoBehaviour
  6. {
  7. public Health health;
  8. public Mana mana;
  9. public CameraEffect cameraEffect;
  10. public float criticalHealth = 50f;
  11. public Image healthBar;
  12. public Image manaBar;
  13. public void OnHealthUpdated(float v)
  14. {
  15. float percentage = health.hp / health.totalHealth;
  16. healthBar.fillAmount = percentage;
  17. healthBar.color = Color.Lerp(Color.red, Color.white, healthBar.fillAmount);
  18. if (cameraEffect != null)
  19. {
  20. if (health.hp <= criticalHealth)
  21. {
  22. cameraEffect.material.SetFloat("_Intensity", 1-(health.hp / criticalHealth));
  23. } else
  24. {
  25. if (cameraEffect.material.GetFloat("_Intensity") != 0)
  26. {
  27. cameraEffect.material.SetFloat("_Intensity", 0);
  28. }
  29. }
  30. }
  31. }
  32. public void OnManaUpdated(float v)
  33. {
  34. manaBar.fillAmount = mana.mana / mana.maxMana;
  35. }
  36. }