Skip to content

Commit

Permalink
Enemies now dim as they lose health
Browse files Browse the repository at this point in the history
  • Loading branch information
Legorobotdude committed Apr 4, 2018
1 parent 0158342 commit ce4eac4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
12 changes: 12 additions & 0 deletions Assets/Scripts/EnemyAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
23 changes: 15 additions & 8 deletions Assets/Scripts/HealthManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit ce4eac4

Please sign in to comment.