OnCollisionEnter multiple objects

Hi, first post here.

I’m having a problem getting OnCollisionEnter to work with another object. Basically in my game I have coins that fall down from the sky. The player is supposed to collide with the coins and the coins should disappear (basic mario stuff). Now these coins have a rigidBody on them because I want to use gravity to make them fall. The issue I run into is once the Coin has reach the ground it enters collision with the ground and The player cannot pick it up. However if the player reaches the coin before it touches the ground it works properly and disappears. I’m not sure what’s going on with OnCollisionEnter and why the player can’t just pick up the coin when it’s on the ground.

Here’s my code for the Coin…

function Start () 
{
	
	Physics.gravity = Vector3(0,gravityValue,0);
}

function OnCollisionEnter(other:Collision)
{
	
		print("COLLiDING");
	if(other.gameObject.tag == "Player")
	{
		print("touching coin");
		Destroy(gameObject);
	}
	
	
}

because when rigidbodies stop moving they go to sleep to improve performance.

http://docs.unity3d.com/Documentation/Components/RigidbodySleeping.html

kinematic rigidbodies will wake up sleeping ones.

but there are other solutions

you can easily simulate gravity

during update simply move down if they aren’t grounded.

if you want to use rigidbodies do a line where you go

if (mathf.approximately(rigidbody.velocity, vector3.zero) //so if your not basically stopped
{
//remove the rigidbody component

}

now it doesn’t have a rigidbody and the gravity is over you don’t need it now you can collide.

Basically, what sparkzbarca said, but personally, I’ve had more luck with keeping all of that code on the player end. That is, have an OnCollisionEnter() function in your player object, and tag the coins. Then, send a message to the coin to destroy it, and add your score/points wherever. So for your player:

function OnCollisionEnter(other:Collision)
{
    if(other.gameObject.tag == "Coin")
    {
       print("touching coin");
       other.SendMessage("PickUpCoin");
       myScore += 1;
    }
}

And then in your coin object:

function PickUpCoin()
    {
        Destroy(gameObject);
    }