Making Sprite Disappear on Trigger

Hey guys so i have a sprite of a Cabin and I added a 2D box collider component to it with Is Triggered. I wrote a very small script (with no errors) that will destroy the GameObject when collided with. I also added a tag called “Cabin” which is referenced in the attached script. I have no idea why it doesnt work :frowning: I messed around with the code a lot, switching Trigger with Collider, adding rigidbody to it and everything in between. This is like my sixth attempt at this and its really slowing me down. With Is Trigger on, he just walks right through it, with it off, he walks into it like a wall. Does anyone see what I did wrong, a setting I may have incorrect, or something in my little bit of code? Even if you have your own way of doing it in C# and would like to share, I would really appreciate it. Here is my code:

using System.Collections.Generic;
  using UnityEngine;
  using UnityEngine.UI;


 
 public class Cabin : MonoBehaviour {
     public void OnTriggerEnter(Collider node)
     {
         if (node.gameObject.tag == "Cabin")
         {
             Destroy(node.gameObject);
         }
     }
 }

and here is my Cabin in Inspector:

If you need to see anything else, I will be happy to upload it! Thanks so much!

I saw the capture you uploaded, and it seems that the problem is that the script is attached to the cabin. The OnTriggerEnter doesn’t work because a trigger can’t detect when something has entered it, you need to check from the object that enters the trigger. So to fix it just attach the script to the player.

OnTriggerEnter is for 3D collisions/triggers. You’ll need to use OnTriggerEnter2D when using 2D colliders,

public class Cabin : MonoBehaviour {
      public void OnTriggerEnter2D(Collider2D node)
      {
          if (node.gameObject.tag == "Cabin")
          {
              Destroy(node.gameObject);
          }
      }
  }