Dirty Stop Out | Remake: Part 1, Recycling GameObjects


I decided to remake DirtyStopOut now that I had some experience scripting Unity - I felt I could make the game a lot better the second time around.

Re-Using Musical Notes

The first change was , instead of having unlimited amount of musical notes spawn, to have just 4 notes that would be moved from the top of the screen back to the bottom so that they could be re-used. Destroying objects causes them to clog up the memory, and so it's much more optimal to re-use them where possible or hide / show objects rather than destroy them.

KillZone

This KillZone game object contains a Box Collider Trigger component as well as a KillZone script that contains the logic for moving the notes from the top to the bottom of the screen again.

Note Spawn Points

I have a bunch of spawn points (I attached a Pink sphere to them so that they are visible) which each have a NoteSpawnPoint tag applied to them and are staggered to cause the notes to spawn be staggered. 

Re-spawning Notes

The KillZone script automatically finds all of the GameObjects in the scene with the tag NoteSpawnPoint and adds them to a list at Runtime. When musical notes hit the KillZone Trigger, a random number is generated (between 0 and the length of spawn points in the list) and moves the collided object to that position.


Randomising the Note Type

Once the note has been re-spawned, it also has a chance to re-spawn as a different type (heal or damage note). The chance that it can spawn as either can be set by me in the Game manager.


Leave a comment

Log in with itch.io to leave a comment.