I don’t know what I did different, because i’ve used this exact code before, but my object destroy code doesn’t seem to be working?
the code is
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("Circle"))
{
Destroy(other.gameObject);
}
}
pretty simple. I dont know what I’m doing wrong
BTStone
2
Did you check the first/obvious things:
- your code is part of a MonoBehaviour class, right? Is this MonoBehaviour attached to a GameObject?
- Does this GameObject have a Collider2D and a Rigidbody2D attached? Is it setup to actually trigger?
- Can the GameObject with the Collider actually collide with the other GameObject, did you check the physics collision matrix?
- Does the other collider gameobject actually have the tag “Circle”?
Also sidenote: you dont need to write other.gameObject.CompareTag, other.CompareTag is sufficient enough
Hi there!
I’m not exactly sure what i did, but I got it to work. I made a script specifically for this code and that seemed to fix it
Probably had to do with the placement of the code in your script.