Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

detect trigger in unity

// Trigger must be checked on one of the Colliders
private void OnTriggerEnter(Collider hit) {    
  Debug.Log(gameObject.name + " just hit " + hit.name); 
}
private void OnTriggerStay(Collider hit) { 
  Debug.Log(gameObject.name + " is hitting " + hit.name); 
}
private void OnTriggerExit(Collider hit) { 
  Debug.Log(gameObject.name + " stopped hitting " + hit.name); 
}
// For 2D 
private void OnTriggerEnter2D(Collider2D hit) { }
private void OnTriggerStay2D(Collider2D hit) { }
private void OnTriggerExit2D(Collider2D hit) { }
 
PREVIOUS NEXT
Tagged: #detect #trigger #unity
ADD COMMENT
Topic
Name
6+2 =