private void OnTriggerEnter2D(Collider2D collision) { if (collision != null && hitActive == true) { if (collision.tag == "enemy") { //Destroy(collision.gameObject) Destroys objects it touches GameObject enemy = collision.gameObject; Enemy_Health healthScript = enemy.GetComponent <Enemy_Health>(); healthScript.reduceHealth(Player_Move_Prot.playerDamage); enemy.GetComponent <Enemy_Move>().knockbackEnemy(); Debug.Log("Enemy hit"); } } }
void OnTriggerEnter2D(Collider2D other) { if (other.tag == "enemy") { GameObject enemy = other.gameObject; Enemy_Health healthScript = enemy.GetComponent <Enemy_Health>(); healthScript.reduceHealth(1); //enemy.GetComponent<Enemy_Move>().knockbackEnemy(); Debug.Log("Enemy hit"); Destroy(gameObject); } else { Destroy(gameObject); } }