I have a game where if you hit a box, you lose a life, and if you hit a coin, you get point. I had this game working, but as the game sped up, hitting a coin would throw you to the side. So I wanted to change the code to OnTriggerEnter
from OnColliderEnter
. But now the collision isn’t working. The player, box, and coin all have Rigidbodys, and the coin and box both have colliders with Is Trigger enabled. The player has a normal collider.
private void onTriggerEnter(Collision other)
{
Debug.Log("collision detected");
if (other.gameObject.tag == "crate")
{
loseLife();
}
else if (other.gameObject.tag == "coin")
{
getPoint();
Destroy(other.gameObject);
}
}
private void getPoint()
{
score +=1;
}
private void loseLife()
{
lives -=1;
}
}