0

When I drive over the trigger, I get no response in the console. On the Package I have Rigidbody2D, Collision Script, Collider 2D and it is marked as trigger. On the car I have a Collider 2D, Rigidbody 2D adn my movement script. I am very new to coding so my baby eyes cant tell whats wrong :(

void OnCollisionEnter2D(Collision2D other)
{
    Debug.Log("Oof!");   
}
    void OnTriggerEnter2D(Collider2D other)
{
    if (other.gameObject.CompareTag("Package"))
    {
        Debug.Log("Package picked up");
    }       
}   
Sathish Guru V
  • 1,417
  • 2
  • 15
  • 39
Nienna
  • 3
  • 3

1 Answers1

0

This collision script is comparing the object it collides with has the tag "Package".

if (other.gameObject.CompareTag("Package"))

From what you told me, this script is currently on the package object. So it's a package checking if its colliding with another "Package"...

Solution is to move the script to the car, since is the car that will be colliding with the package.

PS.: It should only log the "Package picked up" message if it meets the "if" condition. Is the package tag "Package"?

Milena
  • 97
  • 2
  • 10
  • This worked, thank you so much!!! The small q's count, I'll know all this stuff like the back of my hand soon and it's because of Heros like you!!! – Nienna Apr 11 '23 at 02:29
  • Glad it worked for you. Just vote this answear up and select it as the best one, so it has a green checkmark on your topic and it'll be tagged as solved. – Milena Apr 11 '23 at 08:06