void OnTriggerEnter2D(Collider2D col) { if (col.gameObject.tag.Equals("Player") && !isByPlayerCreated) { Debug.Log("Collison with Player"); Player player = col.gameObject.GetComponent <Player>(); PlayerRecord.health -= damage; //Debug.Log("Life of player: " + PlayerRecord.health); } else if (isByPlayerCreated) { if (col.gameObject.tag.Equals("Enemy1")) { Debug.Log("Collison with Enemy1"); Enemy1 enemy1 = col.gameObject.GetComponent <Enemy1>(); enemy1.setHealth(enemy1.getHealth() - damage); //Debug.Log("Life of Enemy1: " + enemy1.getHealth()); } else if (col.gameObject.tag.Equals("Enemy2")) { Debug.Log("Collison with Enemy2"); Enemy2 enemy2 = col.gameObject.GetComponent <Enemy2>(); enemy2.setHealth(enemy2.getHealth() - damage); //Debug.Log("Life of Enemy2: " + enemy2.getHealth()); } else if (col.gameObject.tag.Equals("Enemy3")) { Debug.Log("Collison with Enemy3"); Enemy3 enemy3 = col.gameObject.GetComponent <Enemy3>(); enemy3.setHealth(enemy3.getHealth() - damage); //Debug.Log("Life of Enemy3: " + enemy3.getHealth()); } else if (col.gameObject.tag.Equals("Enemy4")) { Debug.Log("Collison with Enemy4"); Enemy4 enemy4 = col.gameObject.GetComponent <Enemy4>(); enemy4.setHealth(enemy4.getHealth() - damage); //Debug.Log("Life of Enemy4: " + enemy4.getHealth()); } } else if (col.gameObject.tag.Equals("FireBall")) { bool isByPlayerCreatedColFireBall = col.gameObject.GetComponent <FireBall>().getIsByPlayerCreated(); if (isByPlayerCreated ^ isByPlayerCreatedColFireBall) { //Debug.Log("Fireball is destroyed"); Destroy(col.gameObject); Destroy(gameObject); } } }