- Home /
Script to dectect collision and say what it collided with every time it collides with it
I have written a script that detects when a bouncing cube collides with the wall or the floor and the Debugs a message. Here is the script
function OnCollisionEnter(theCollision : Collision){
if(theCollision.gameObject.name == "Floor"){
Debug.Log("Hit the floor");
}else if(theCollision.gameObject.name == "Wall"){
Debug.Log("Hit the wall");
}
}
The problem is that when the cube hits something it Debugs the message only once, when the cube hits the thing again it dose not debug the message. I would like the message to debug every time the cube hits something. I new to scripting so if you could please explain what you did and why. Thanks.
Oh Wow. Collapse was lit up. That solved it, thanks. I thought it was a problem with the script.
Answer by Avaista · Jul 16, 2012 at 01:03 AM
Look at your console, is "Collapse" lit up?
Answer by ninjaboynaru · Jul 16, 2012 at 03:57 AM
There is nothing wrong with the script. The problem was that I had collapse turned on in the console. Thanks Avaista.
$$anonymous$$ark the question as answered so it shows up in search as such. Helps those of us on the prowl, lol.