Collision delete

Ok so iv been trying to make a script and keep failing. I want it so that when an object touches another object, a event happens (Such as it prints on the screen "You won!")

  • My box is called "bluecube"
  • My collider that if bluecube collides with it i want something to happen is called "bottom-collider"

so i tried this script - (this failed)

var bluecube : Transform;

function OnControllerColliderHit(collision:Collision)

{
if(collision.gameObject == "bluecube")
{
    Destroy(bluecube);

}
}

what i wanted it to do is that when the bluecube comes into contact with the object that has this script attached it will destroy the bluecube.

Thanks in advance!

1 Answer

1

You just need to change this little piece of code:

if(collision.gameObject.name == "bluecube")
{
    Destroy(collision.gameObject);
}

Since you're doing it by name, you don't need to have a variable to your blueCube object (though you could also use it for checking if you prefer, e.g. if (collision.transform == bluecube) )

Yup yup, sounds better in that case