public void InflictDamage(Globals.EnemyCollision coll, Vector2 bulletForce, int damage) { _health -= damage; //HealthBar.fillAmount = _health / 100; coll.lastHit = Time.time; if (_health <= 0) { _isDead = true; Shooting.enabled = false; _movement.enabled = false; _rb.AddForce(bulletForce * 100); _deathTime = Time.time; _anim.SetTrigger("death"); if (GameEndDialog != null) { GameEndDialog.SetActive(true); } Destroy(Shooting.gameObject); } }
void OnTriggerExit2D(Collider2D other) { if (other.gameObject.layer == 8) { Globals.EnemyCollision coll = enemyCollisions.FirstOrDefault(colission => colission.obj.GetInstanceID() == other.gameObject.GetInstanceID()); if (coll != null) { enemyCollisions.Remove(coll); } } }
void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.layer == 8) { Globals.EnemyCollision coll = new Globals.EnemyCollision(); coll.obj = other.gameObject; enemyCollisions.Add(coll); _health.InflictDamage(coll, Vector2.zero, Globals.Constants.ZOMBIE_DAMAGE); } }