Destroy Object problem

I;m trying to destroy an object with a mouse click, it kinda works but i get this error when testing it:

Can’t remove component.
Can’t remove Transform because MeshFilter, BoxCollider, MeshRenderer depends on it

This is my script:

var Cube : Transform ;
function Update () {

if (Input.GetMouseButtonDown(0)) {

Destroy(Cube);

       }

}

Anyone got any idea how to fix this?

use cube.gameObject instead

Tried that now this error appears:

Assets/scripts/DestroyObject.js(6,14): BCE0019: ‘GameObject’ is not a member of ‘UnityEngine.Transform’.

(Current script)

var cube : Transform ;
function Update () {

if (Input.GetMouseButtonDown(0)) {

Destroy(cube.GameObject);

       }

}

use gameObject, not GameObject

okay that worked, i only forgot one thing to implement, and that is that i have to be able to click the object itself and not anywhere in the scene xD just found that out :stuck_out_tongue:

Why not just declare your variable as a game object instead of a transform – var cube : GameObject; – and save yourself from drilling through the hierarchy? Not a big deal, just a little less code. You could then just use the script you wrote in the first post above. Destroy (cube);