- Home /
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!
Answer by Mike 3 · Jul 04, 2010 at 10:46 AM
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) )
Thanks. I was using variables as I wanted to use 1 script for all cubes. As I have 3 colors of cube.
Hmmm, weird. im getting "$$anonymous$$ identifier : collision" ?