Road TO Dev — That’s a lot of lasers…

Rob Smith
2 min readMar 31, 2021

Well we did it! We made our character fire those lasers but now if you notice something in the inspector… they live FOREVER!

That just won’t do we need to make sure the lasers go away when they are either off screen or when they hit something. We will cover collisions soon so for now let’s just focus on when the laser leaves the screen. This is easy to do. Just decide where on your screen in the Y axis you want to be considered “off screen”. You can do this by just dragging a laser into the hierarchy and dragging it to the top edge. Then look at it’s Y coordinate and bingo you have your number.

Now that we have that number let’s just create a check in the laser script to Destroy itself when it reaches this value.

Now you can see in the hierarchy that once the lasers reach their limit they are properly disposed of. This is a must have as you don’t want your game getting bogged down.

--

--

Rob Smith

Hi there! I am currently on the path to learn how to become a unity developer and will be documenting my journey as best as I can here. Thanks for looking!