Posted October 06, 2022 by Mike Guthrie-Plouffe
The game is comprised of a single scene, which generates “chunks” as the player progresses. These chunks hold the level geometry such as pits and platforms, as well as any spawn points for randomized items, such as pickups. At any one time, there are six chunks active in the scene at one time; a chunk is disabled once it goes offscreen and is sent back into the pool queue.
Each chunk is assigned a difficulty, represented as an integer value. A “difficulty reader” takes a sample from an animation curve based on the player’s position in the world and spits out a value which represents the current difficulty; using a gradual incline, the game steadily grows in difficulty. Chunks are spawned based on the current in-game difficulty, with a degree of variance that can be set in-editor.
Every object in the game is pooled and initialized OnEnable; this includes level chunks, coins, pickups, interactibles, audio, and visual effects (i.e. particles).
The game takes place in a museum, and so there are lots of varying objects that populate display cases. Each case is assigned a size and can be populated with a combination of objects that fit that specific case layout. Another way to do this would be to assign a size to the objects as well, and to fit a randomized collection of objects into that space, but the method I used proved to be more suitable for our asset workflow, as not every asset that was created fit into a certain size
As for some other objects:
Audio is pooled in a different way; it has a special Audio Factory class that generates audio. There is only one type of game object associated with audio FX, which has an Audio Source attached to it. This is a very simple game, and there are no SFX that have special settings for the Audio Source, so these pooled objects get re-used for each sound. If a sound is played, the object calling “playSound” calls on “AudioFactory” . “Play”, which takes an audio clip and an audio mixer group – this way the correct clip is played, and all sounds are mixed correctly.