Destroy cube when player touches it

Hello.My tags are Player=3rd person controller and Cube=Cube… Ok so I have a script written but there is a problem. The script is for my Player and when he runs into a Cube, The Cube should die(dissappear. But when I run into the Cube my player dies instead of the cube…How can I reverse it so the cube dies when the player runs into it? here is script. (the script is applied to my 3rd person char)

var other : GameObject;

function OnControllerColliderHit (hit : ControllerColliderHit){

if(hit.gameObject.tag == “Cube”) {

Destroy (gameObject);

print("Hey you destroyed me ");

}

}

:wink: It’s quite obvious. You destroy gameObject which returns the gameobject to which this script is attached to. In your case the player. You want to destroy the other object that collided with the player. In other words: hit.gameObject. You just checked the tag name of this object a line above :wink:

I think it has to be

Destroy (hit.gameObject);

Good to see you put in some effort on your own :slight_smile:
Be it that you’ve written it yourself or that you searched it…

Edit: Aw, Bunny was faster…

Wow…that easy…i feel dumb…THANKS both of you so much!