I face a little problem in my game. Basicly I’m trying to make a collision detection… if the enemy hits the player and they are the same color the enemy gets destroyed. Else the player dies. But it only works if both colors are blue how to fix this?
function OnCollisionEnter2D(coll: Collision2D) {
if (coll.gameObject.tag == "Player" && Player.renderer.material.color == Color.red
&& Enemy.renderer.material.color == Color.red){
Destroy(this.gameObject);
}
if (coll.gameObject.tag == "Player" && Player.renderer.material.color == Color.green
&& Enemy.renderer.material.color == Color.green){
Destroy(this.gameObject);
}
if (coll.gameObject.tag == "Player" && Player.renderer.material.color == Color.blue
&& Enemy.renderer.material.color == Color.blue){
Destroy(this.gameObject);
}
else {
Destroy(Player);
}
}