What I understand is that the gameObject here is the “Shredder”, to which the script is attached. Then how destroying this is removing the instances of projectiles from the scene?
The OnTriggerEnter2D() method, as you can see, is passed a parameter of type Collider2D named col.
col is the other collider from the other game object which has collided with this one.
When you call subsequently call the Destroy() method you aren’t passing it gameObject which would be the current game object which this script is attached you, you are passing it col.gameObject, e.g. the other colliders game object.
Your explaination was better than mine @Rob (as usual )
I was simply putting, The ball hit the wall and the wall destroyed the ball with no harm to itself.
The ball being the projectile and the wall being the shredder.
Rob’s explaination is spot on with how the trigger method works but thought i would add laymans terms
Thanks a lot Rob for your excellent explanation. I actually put Debug.Log(gameObject.name) to see which one was being destroyed. I should have put Debug.Log(col.gameObject.name).
Thank you irresistiblejelly. I really appreciate your reply as well.