Complete the code to detect when an object enters a trigger collider.
void OnTriggerEnter(Collider [1]) { Debug.Log("Object entered trigger"); }
collision instead of other in OnTriggerEnter.The method OnTriggerEnter receives a Collider parameter commonly named other to represent the object entering the trigger.
Complete the code to detect when two colliders collide (not triggers).
void OnCollisionEnter(Collision [1]) { Debug.Log("Collision detected"); }
other instead of collision in OnCollisionEnter.The OnCollisionEnter method receives a Collision parameter often named collision to represent the collision details.
Fix the error in the method name to detect trigger exit events.
void On[1]Exit(Collider other) { Debug.Log("Object exited trigger"); }
OnCollisionExit for trigger events.The correct method name for detecting when an object exits a trigger is OnTriggerExit.
Fill both blanks to correctly check if the collider is a trigger and log a message.
void OnCollisionEnter(Collision [1]) { if ([2].collider.isTrigger) { Debug.Log("Triggered by a trigger collider"); } }
other as parameter name but collision inside the method.isTrigger on the wrong object.In OnCollisionEnter, the parameter is usually named collision. To check if the collider is a trigger, use collision.collider.isTrigger.
Fill all three blanks to create a method that detects trigger stay events and logs the name of the other object.
void On[1]Stay(Collider [2]) { Debug.Log($"Object [3] is staying in trigger"); }
OnCollisionStay instead of OnTriggerStay.The method name is OnTriggerStay. The parameter is other. To log the object's name, use {other.name} inside the string.