A slightly more efficient way to test the collision tag

Rather than using other.tag == "Player" it is more efficient to use other.CompareTag("Player") as this avoids the extra memory allocation performed when accessing other.tag, and the subsequent garbage collection cost.

See this tutorial for more details.

But really we should consider using Layers - they can be five times faster!

2 Likes

Good tip. After I completed the challenge I was about to come here to say the same.

And absolutely on the layers! Much better to leverage the engine rather than writing lines of code.

On a side note: I’ve got so layers in my game I’m thinking I need to sit down and think through what I’m gonna need before it gets out of control :wink:

Privacy & Terms