Destroy Laser Shoot

Maybe it will be a further part of the course, but it’s better to remember to destroy objects :slight_smile:

I noticed the same thing and assuming that we will address in a future lecture but I just couldn’t deal with all the instances of laser filling up my Hierarchy. :slight_smile:

I had to throw a

Destroy(laser, 2f)l

on there just to keep my sanity.

Greg

Another thing you could consider is creating an empty GameObject in the scene and then in your code, when you instantiate your laser GameObject, parent it to the empty. It doesn’t really have any bearing on the game itself, but it will mean that you can collapse that GameObject in the Hierarchy an not see all of the GameObjects which are created at run time.

Also, if you are not specifically testing anything with regards to projectiles/collisions you could just disable the enemy from firing at all :slight_smile:

Privacy & Terms