I’m brand new to Unity and working on my first project.
I am using an empty GameObject to destroy other game objects that pass through the screen and get destroyed on the other side as they are no longer needed. And I have the Object already tagged as “Obstacle” but yet it still seems to do nothing at all when I test it. The “Obstacle” objects still keep going, seeming to ignore the “Destroy” … is there something I’m missing or doing wrong? The empty GameObject has a box collider and Rigidbody and all that, so I’ve already double checked those things as well. I’ve tried Google and found some similar problems, just not specifically what my issue is… so posting here is the last thing I can think of to solve the issue. Any help would be greatly appreciated.
Well, yes. If there weren’t, it would work. So that means, somewhere your understanding is incomplete; some assumption you’re making is incorrect. Debugging is nothing more or less than tracking down where that incorrect assumption is.
Right now, you think Destroy isn’t doing anything. You’re assuming that the Destroy line is actually being executed. I think that’s probably incorrect, but it’s certainly the first thing you should check. Insert a Debug.Log line right before or after the Destroy, and watch the console — do you see the message appearing when you expect it to?
My guess is “no.” So now you know there’s nothing wrong with Destroy; the problem is that that code is never running. Back up a step. Is OnCollisionEnter itself ever getting called? Insert another Debug.Log at the top of that and see.
Continue in this way, falling back and checking your assumptions, until you find the key bit that you are missing. Then you’ll probably know how to fix it (but if not, of course, post again here and we’ll try to help!).
First of all, thank you for the replies. I appreciate it!
So apparently the OnCollisionEnter never is getting called, it seems to be getting ignored completely so then the question is why?
One thing I eventually found through Googling was that there seems to be an issue if you add Rigidbody to both Colliders in 2D? It said something about them being static and not supposed to move.
However, that may have been an old post and completely irrelevant to my issue right now.