Collision Detection

I am trying to create a simple script of collision detection. I am a beginner at javascript and I can’t seem to get this collision script to work…

function OnControllerColliderHit (hit : ControllerColliderHit) 
{
	if (hit.gameObject.name == "WinLevelOne")
	{
		print("It Worked!!!");
	}
}

I’d recommend using a trigger.

function OnTriggerEnter (other : Collider) {
    if (other.gameObject.CompareTag ("WinLevelOne")) {
        print("it worked!");
    }
}

Are your objects actually character controllers?

you need rigidbody components on the mesh/objects.

OK I feel this is harder than it should be… All I want is a message to print to the debug panel when a box, falling from the sky, touches a platform. Could someone please tell me what the script would be for this simple collision?

–Thanks!! :wink:

As I posted above, there you go!

I must be doing something wrong because it doesn’t seem to work for me… I have a tag called “WinLevelOne” applied to the platform the box falls on, and the script applied to the box falling. Is this correct?

Ok I got it working.

Thanks for the help guys! :sunglasses: