diff --git a/Assets/Scripts/EnemyAI.cs b/Assets/Scripts/EnemyAI.cs index 223c488..ba9853d 100644 --- a/Assets/Scripts/EnemyAI.cs +++ b/Assets/Scripts/EnemyAI.cs @@ -33,6 +33,18 @@ void Update () { // { // rigidBody.AddForce(new Vector3(10f,0f,0f)); // } + if (!isDead) + { + + foreach (Material mat in m_Material) + { + //mat.SetColor("_EmissionColor", Color.yellow* Mathf.LinearToGammaSpace(5)); + mat.SetColor("_EmissionColor", Color.red*5*currentHealth/maxHealth); + //Debug.Log("Current health" + currentHealth); + //Debug.Log("Max Health" + maxHealth); + //Debug.Log(currentHealth/maxHealth); + } + } } void ApplyRandomForce() diff --git a/Assets/Scripts/HealthManager.cs b/Assets/Scripts/HealthManager.cs index b3680a8..2a2e3d6 100644 --- a/Assets/Scripts/HealthManager.cs +++ b/Assets/Scripts/HealthManager.cs @@ -4,27 +4,34 @@ public class HealthManager : MonoBehaviour { - public float health = 100f; + public bool isDead = false; + public float maxHealth = 100f; + protected float currentHealth; + + void Awake() { + currentHealth = maxHealth; + } // Use this for initialization - void Start () { - - } + // void Start () { + // currentHealth = maxHealth; + // } // Update is called once per frame - void Update () { + // void Update () { - } + // } public void TakeDamage(float amount) { - health -= amount; - if (health <= 0f) + currentHealth -= amount; + if (currentHealth <= 0f || !isDead) Die(); } virtual protected void Die() { + isDead = true; Destroy(this.gameObject,1f); } }