Colliders properties

Triggers

This class works for all Colliders, its functions give possibilities like destroy gameObjects when its produce a contact, like coins in Mario, or simply send messages to the console.

Lets see the messages

  • OnTriggerEnter
  • OnTriggerExit
  • OnTriggerStay
public class Coins : MonoBehaviour {
    void OnTriggerEnter (Colliger other) {
    
        if (other.getComponent<player1>() != null)
        {
            Debug.Log(other.name);
        }
    }
}
  • Use OnTriggerEnter to detect a contact between colliders.
  • OnTriggerExit to know when the gameObjects gets outside of the collider.
  • and onTriggerStay to start a count of frames when the gameObjects its remaining tapping the collider.