Sunday, October 6, 2013

How To Use On Collision Enter In Unity3D

       
       After Finding it quite complicated to find a simple answer to how to use OnCollisionEnter, OnCollisionStay and OnCollisionExit, I decided I would start posting easy to understand answers to problems that I come across in Unity.

The Example code below can be placed in a script on either the trigger game object or the the object that is doing the triggering.

void OnTriggerEnter (Collider other) {
Debug.Log("Delete this now, We have Entered Zone 1");
}
This function will be called whenever an object with a rigidbody or  collider (including character controller), enter the trigger game object. 
       The Trigger object must have a rigid body attached and a collider with the istrigger set to true(or ticked in properties). 

Extra Notes- OnCollisonEnter detects you as having entered a trigger upon the game starting if you are within the trigger game object.

Happy coding

No comments:

Post a Comment