OnTriggerEnter2D with if/else

if (col.gameObject)

Can you explain what this is supposed to be doing? It’ll always have a valid GameObject so this will always be true and always result in you enabling the renderer.

You need to explain and maybe show what colliders are where and where this script is. Too many posts show a bit of script and a rough description. The main thing is provide the context.

Use OnTriggerEnter2D for when you enter a trigger and OnTriggerExit2D for when you exit a trigger. If you don’t know this then I would highly suggest following a basic 2D physics tutorial before you try to use it otherwise you’re going to be guessing each step.

This just looks like a continuation of this thread TBH: How do I make a key appear?

Also, please don’t add random tags to posts. This is not related to 9-slice, performance, spriute-mask, tilemap etc.

Thanks.

1 Like