This Prefab which we call a LevelBlock represents the core functionality for the infinite part of our game.
Of course when making a game like this memory management and making sure that the environment truly never ends is a very important. factor. if for any reason your game stops instantiating new territory or does it to late the game comes off as broken or you let the player peak beyond anyveil of belivability your game has and if the game flat out crashes well ... that's never a good situation..
So the concept behind these are very simple , when our player character collides with the green object( rendered invisible in-game due to a culling mask on the camera) we instantiate the next level block exactly 100 units ( the width of this block) away from the x position of our current block. once our player character collides with the red object we call a function that destroys our current block in roughly ten seconds.
we also took care to make sure each block is sort of it own environment with its own rice ball spawners, enemies, and backgrounds that are children of our parent block object. that way when we destroy the level block we also destroy all of its children as well . So far I have never seen more than 7 level blocks in existence at once and by constantly destroying old level blocks we manage to balance our memory usage very well!