//here we manage health of the enemy when a bullet hits it. if its health is 0 it will spawn the death animation, possibly spawn a heart, then destroy itself. void takeDamage(int damage) { if (!isDead) { //GetComponent<AudioSource>().PlayOneShot(hurtSound); //FLINCHER if (isFlinchable) { if (EnemyType == "shooter") { ShooterScript.Flinch(damage); } } health -= damage; if (health <= 0) { isDead = true; GameObject DeathAnimation = Instantiate(deathAnim, transform.position, Quaternion.Euler(0, 180, 0)) as GameObject; DeathAnimationScript = DeathAnimation.GetComponent <deathAnimation>(); // rend.enabled = false; Transform[] children = gameObject.GetComponentsInChildren <Transform> (); for (int i = 0; i < children.Length; ++i) { if (children [i].gameObject.GetComponent <SpriteRenderer> () != null) { children [i].gameObject.GetComponent <SpriteRenderer> ().enabled = false; } } GameObject[] enemies = GameObject.FindGameObjectsWithTag("enemy"); foreach (GameObject en in enemies) { if (en.GetComponent <Collider> () != GetComponent <Collider> ()) { Physics.IgnoreCollision(GetComponent <Collider> (), en.GetComponent <Collider> ()); } } /* Drops item (heart) if randNum = 2 * int randNum = Random.Range(1,4); * if(randNum == 2){ * Instantiate(heartDrop, transform.position, Quaternion.Euler(0,180,0)); * } */ //Destroy(gameObject); } else { StartCoroutine(resetColor()); StartCoroutine(Blinking()); } } }
void DamageTimeControl(List <int> list) { if (ControllerScript.getTimeControl() == false) { list.Add(health); } else if (ControllerScript.getTimeControl() == true) { // checkHealth(); int PreviousHealth = health; if (list.Count > 0) { health = list [list.Count - 1]; if (PreviousHealth <= 0 && health > 0) { GameObject DeathAnimation = Instantiate(deathAnim, transform.position, Quaternion.Euler(0, 180, 0)) as GameObject; DeathAnimationScript = DeathAnimation.GetComponent <deathAnimation>(); //DeathAnimationScript.setBackwards(true); StartCoroutine(spawnBack()); } //updateHearts(); list.RemoveAt(list.Count - 1); } } }