Newer
Older
Dreamsturbia-Project-IADE-Unity3D / Assets / Scripts / UIController.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UIController : MonoBehaviour
{
    public Health health;
    public Mana mana;

    public CameraEffect cameraEffect;
    public float criticalHealth = 50f;

    public Image healthBar;
    public Image manaBar;

    public void OnHealthUpdated(float v)
    {
        float percentage = health.hp / health.totalHealth;
        healthBar.fillAmount = percentage;
        healthBar.color = Color.Lerp(Color.red, Color.white, healthBar.fillAmount);
        if (cameraEffect != null)
        {
            if (health.hp <= criticalHealth)
            {
                cameraEffect.material.SetFloat("_Intensity", 1-(health.hp / criticalHealth));
            } else
            {
                if (cameraEffect.material.GetFloat("_Intensity") != 0)
                {
                    cameraEffect.material.SetFloat("_Intensity", 0);
                }
            }
        }
    }

    public void OnManaUpdated(float v)
    {
        manaBar.fillAmount = mana.mana / mana.maxMana;
    }
}