Question About Collisions

I am modifying the Delivery Driver project and want to create multiple collision responses based on the objects which are colliding. Currently I have 3 object types: Wall, Crate and Man. Each pairing should log a different message to the console. Here is my current wall collision script:

public class WallCollision : MonoBehaviour
{
   void OnCollisionEnter2D(Collision2D other)
    {
        Debug.Log("Ouch!");
    } 
}

I attempted to use Tags to achieve this but intellisense is telling me that “Collision2D does not contain a definition for tag”
How can I improve this to send the message “Thud” when a Crate collides with the wall?

You can use tags. You just need to use the correct object

void OnCollisionEnter2D(Collision2D other)
{
    if (other.gameObject.CompareTag("Crate"))
    {
        Debug.Log("Thud!");
    }
} 

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms