Complete the code to detect a collision with another object.
void [1](Collision2D collision) { Debug.Log("Collision detected with " + collision.gameObject.name); }
The method OnCollisionEnter2D is called when this object collides with another collider and both have Rigidbody2D components.
Complete the code to detect when another object enters a trigger collider.
void [1](Collider2D other) { Debug.Log("Trigger entered by " + other.gameObject.name); }
The method OnTriggerEnter2D is called when another collider enters a trigger collider attached to this object.
Fix the error in the method signature to detect collision correctly.
private void [1](Collision2D collision) { Debug.Log("Hit " + collision.gameObject.name); }
For 2D physics, the method must be OnCollisionEnter2D and use Collision2D as parameter.
Fill both blanks to create a method that logs when an object exits a trigger.
void [1](Collider2D [2]) { Debug.Log("Trigger exited by " + [2].gameObject.name); }
The method OnTriggerExit2D detects when a collider leaves a trigger. The parameter is usually named other to represent the other collider.
Fill all three blanks to create a method that detects collision and logs the tag of the other object if it is 'Enemy'.
void [1](Collision2D [2]) { if ([3].gameObject.tag == "Enemy") { Debug.Log("Collided with Enemy"); } }
The method OnCollisionEnter2D detects collisions. The parameter is often named collision. We check the tag of the colliding object using this parameter.