public void takeDamage(float amount) { currentHealth -= amount; if (currentHealth <= 0) { Destroy(transform.gameObject); Instantiate(explosion, transform.position, transform.rotation); AudioSource.PlayClipAtPoint(explosionSound, transform.position); eCounter.decreaseEnemies(); } }
public void takeDamage(float amount) { currentHealth -= amount; enemyai.state = 1; //Adjust the health bar healthBar.fillAmount = currentHealth / startingHealth; if (currentHealth <= 0) { Destroy(transform.gameObject); Instantiate(explosion, transform.position, transform.rotation); AudioSource.PlayClipAtPoint(explosionSound, transform.position); eCounter.decreaseEnemies(); } }
void OnTriggerEnter2D(Collider2D other) { if (other.tag == "tile") { stuck = true; } if (other.tag == "Player") { try { other.GetComponent <Rigidbody2D>().velocity = new Vector2(transform.up.x * 5, transform.up.y * 5); Destroy(gameObject); Instantiate(explosion, transform.position, transform.rotation); AudioSource.PlayClipAtPoint(explosionSound, transform.position); eCounter.decreaseEnemies(); playerHealth player = other.gameObject.GetComponent <playerHealth>(); player.takeDamage(50); } catch { } } }