Debug.Log not working.Beginner problem .

Simple code but not getting anything.I was trying to make a box fall down to the floor which has two walls.
I have Added the script as the component of box.
Debug.Log is working without this collision function.
Not getting any error thou.Animation is working.But in output not getting anything.

function  onCollisionEnter(theCollision:Collision)
{
    if(theCollision.gameObject.name=="wall1")
    {
	Debug.Log("Hit the wall1");
    }
    if(theCollision.gameObject.name=="wall2")
    {
	Debug.Log("Hit the wall2");
    }
    if(theCollision.gameObject.name=="Floor")
    {
	Debug.Log("Hit the floor");
    }
    
}

Please help .

You’ve named the function wrong. It should be ‘OnCollisionEnter()’ with an upper case ‘O’.

Collision is a funny thing. Both GameObjects don’t get the collision, only the one being collided or something along those lines. I’m not even sure half the time.

This might be your problem, might not though. Something you can try is adding this script to your wall1, wall2, and Floor. See if it activates then.

If it activates after that then it’s due to the “who’s colliding into who” factor.

As for the name of your title, it isn’t that Debug.Log isn’t working because it is (As you pointed out in your description). The reason why you don’t see anything is because the if statements aren’t ever becoming true. So the problem is in your collision.

Verify your game objects are named “wall1, wall2, Floor” exactly.

Something you can do for further debug is add a debug log that tells you the name of what is hit. Perhaps there is more to it then just “wall1/wall2”

function  onCollisionEnter(theCollision:Collision)
{
    if(theCollision.gameObject.name=="wall1")
    {
    Debug.Log("Hit the wall1");
    }
    if(theCollision.gameObject.name=="wall2")
    {
    Debug.Log("Hit the wall2");
    }
    if(theCollision.gameObject.name=="Floor")
    {
    Debug.Log("Hit the floor");
    }
    Debug.Log("We hit: "+theCollision.gameObject.name);
}

Oh yes.It is this mistake only.Thanks,you have solved it :slight_smile: