private void OnTriggerEnter2D(Collider2D collision) { if (collision.transform.CompareTag("Player")) { collision.transform.gameObject.GetComponent <PlayerController>().LoseHealth(1, transform); } if (collision.transform.CompareTag("Sword") && !kb.knockedBack) { health--; if (health <= 0) { Instantiate(smokePrefab, transform.position, Quaternion.identity); if (Random.value > 0.5f) { Instantiate(rupeePrefab, transform.position, Quaternion.identity); } Destroy(gameObject); } else { kb.KnockbackFromTransform(collision.transform.parent); } } }
public void LoseHealth(int damage, Transform other) { if (health >= 1 && !kb.knockedBack) { health -= damage; healthText.text = "Health: " + health.ToString(); kb.KnockbackFromTransform(other); } if (health <= 0) { GameManager.instance.GameOver(); } }