UNITY – JS Script – OnCollision
1. Create a Sphere that falls and bource over a Box (You have to use Physics 3D engine)
2. Attach to the Sphere the script
#pragma strict function Start () { } function OnCollisionEnter(collisionInfo : Collision) { print("Collision Enter"); } function OnCollisionStay(collisionInfo : Collision) { print("Collision Stay"); } function OnCollisionExit(collisionInfo : Collision) { print("Collision Exit"); } function Update () { }
Unity has 3 OnCollision events:
1. OnCollisionEnter
TRUE at first frame of the collision
VERO al primo frame della collisione
2. OnCollisionStay
TRUE for some frames, until the colliders are still in contact
VERO per diversi frames, finchè i colliders sono in contatto
3. OnCollisionExit
TRUE the first frame when the colliders are no longer in contact
VERO al primo frame che perdono il contatto
NOTICE: put – function OnCollision – OUTSIDE Start() or Update()