Don’t freeze your game— destroy those objects!

Chelsea Cruise
Apr 28, 2021

--

Here you can see that if we don’t do something with those laser objects after the player fires them, they’re going to keep going on forever and ever and ever and ever and ever…….

…..that is not what we want. If we just leave our unneeded objects in the air without destroying them, that’ll cause for a super slow game.

Here’s how to fix it:

if (transform.position.y > 8f)
{
Destroy(this.gameObject);
}

We have our laser being destroyed once it’s greater than a certain position. Alternatively, we can set this up to destroy after a certain amount of time.

Look at how clean it!

--

--

Chelsea Cruise

Unity Developer, Software Engineer, Game Designer, Graphic Artist