Computer Language/Unity

[Unity] Trigger and Collision

정우섭 2019. 3. 2. 23:08

Crush


When two objects crush on each other at least one object must have Rigidbody, and both of them must have Collider. And if only one object moves and crush the moving object must have Rigidbody.



Collision


Collision detects crush following physical operation. But you have to make sure that Rigidbody -> Kinematic is off.


OnCollisionEnter(Collision col) - Will happen when the object crush on the other.

OnCollisionStay(Collision col) - Will happen every frame until the object is crushing on the other.

OnCollisionExit(Collision col) - Will happen when the object finishes crushing on the other.


We use these functions like picture.


Trigger


Not like CollisionTrigger detect the crush not counting physical operation. In other words, when two object contacts each other they don't bounce and they just pass.


OnTriggerEnter(Collision col) Will happen when the object crush on the other.

OnTriggerStay(Collision col) Will happen every frame until the object is crushing on the other.

OnTriggerExit(Collision col) Will happen when the object finishes crushing on the other.



The variable of Collision becomes parameter of the function, and by using 'col' you can control the crushed object.