Terrain collision and specific collision problems .

Hi All

I am wanting to create a script where if the player runs into the coin then he recieves money and I have the money adding part down but when I add On.Collide then it either collides with the terrain and adds all the coins money or it I make it collide with a specific gameobject then the coins fall through the terrain ? How would I fix this ?

Ps. The terrain has a terrain collider and is no a trigger .

OnCollide is called for all collisions. So simply test that you are actually colliding with your player and you will be fine. Assuming that you tagged your player object as “Player”, you can use:

void OnCollisionEnter(Collision collision) 
{
  if (collision.gameObject.tag == "Player")
  {   
    // collect the coin and get rich
  }
}