Crazy Tractor's Infinite Level System
✨ What You'll Learn:
How to simulate infinite scrolling by reusing tiles
How to move and reorder rows or columns
🧠 Deeper Dive:
Instead of creating and destroying tiles as the player moves, we simply reposition them and reorder the grid list. For example, to scroll upward:
Take the last row of tiles
Move it to the top of the screen
Insert it at the start of the
TileGrid
list
This gives the illusion of continuous movement.
✅ Code Example:
public void ScrollUp()
{
TileRow bottomRow = TileGrid[TileGrid.Count - 1];
foreach (GameObject tile in bottomRow.Tiles)
{
float newY = TileGrid[0].Tiles[0].transform.position.y + tileSpacing;
tile.transform.position = new Vector3(tile.transform.position.x, newY, 0);
}
TileGrid.Insert(0, bottomRow);
TileGrid.RemoveAt(TileGrid.Count - 1);
UpdateTileEdges();
}
The same principle applies to ScrollDown, ScrollLeft, and ScrollRight with relevant adjustments.