Collision2D on gameObject tag doesn't work SOLVED!

  1. Basically, my hero will do some stuffs like slashing the melon, but the collision doesn’t work. It just passed through the melon (image below):

  2. I configured the components needed.
    Tag = watermelonTag
    Is Trigger = checked

  3. I place this code in my Hero game object.

void OnCollisionEnter2D (Collision2D collision){
      
        switch (collision.gameObject.tag){

        case "watermelonTag":
            srSlash.sprite = slashingSprite;
            audio.PlayOneShot(swordSound);
            audio.PlayOneShot(fruitSmashing);
            Destroy(collider.gameObject);
            break;
        case "pineappleTag":
            srSlash.sprite = slashingSprite;
            audio.PlayOneShot(swordSound);
            audio.PlayOneShot(fruitSmashing);
            Destroy(collider.gameObject);
            break;

Thanks :))

Wouldnt it be “OnTriggerEnter2D” …since u set it to “Is Trigger”?

1 Like

wOw thanks alot! you’re my hero of the day!
I’m just kinda learning unity3d XD

1 Like

I just started with unity a week ago :slight_smile:
Had a lot of fun since then.
I highly recommend to check the Live Tutorial Sessions each Monday…they r awesome and helped me a lot!

OK! awesome thanks!