Destroy GameObject

I am trying to make a script in which if my first person controller collides with my cube, that it destroys it. I am trying this code but I get the message “No appropriate version of ‘UnityEngine.Object.Destroy’ for the argument list ‘(System.Type)’ was found”:

function OnCollisionEnter(collision : Collider)
        {
         Destroy(GameObject);
        }
`

`

You’re calling Destroy(GameObject), but GameObject (with uppercase ‘G’) is a type. You need to destroy an instance, so in your case you either have to use Destroy(gameObject) if the script is attached to a cube, or Destroy(collider.gameObject) if the script is attached to a player. I’m assuming that cube should be destroyed.

try this

 function OnCollisionEnter(collision : Collider)  {  GameObject.Destroy(gameObject);  }

as the other unity people have informed you the error was you were using a type name instead of a property name. GameObject is type, while gameObject is a property of Monobehaviour

For the fps controller you must use OnControllerColliderHit().

You first check whether your fps is colliding with cube or not,… and if not then check all the setting for collision are made or not.

Then script you have written is not correct.

if you script is connected with your fps then you should write :

function OnCollisionEnter(collision : Collision)  
{  
     Destroy(collider.gameObject);  
} 

and if script is connected to cube then ,

function OnCollisionEnter(collision : Collision)  
{  
     Destroy(gameObject);  
}

Hope this will help to you… All the best… Gud luck.

Your function will never get called because it takes the wrong parameter type.

You want:

function OnCollisionEnter(collision : Collision)//Collision, not Collider
{
    Destroy(gameObject);//Lowercase g to refer to the game object that this script is attached to.
}