Crazy Tractor's Infinite Level System
✨ What You'll Learn:
How to position tiles in world space
How to apply spacing for a clean, aligned grid
🧠 Deeper Dive:
Each tile GameObject in Unity has a transform.position. To place tiles evenly across the screen, we multiply their index in the grid by a constant spacing value like tileSpacing = 50f. This ensures rows and columns are evenly spaced.
This positioning logic applies both when the grid is initialized and when it's shifted to simulate scrolling.
✅ Code Example:
Vector3 tilePosition = new Vector3(xIndex * tileSpacing, yIndex * tileSpacing, 0);
tile.transform.position = tilePosition;
When shifting rows:
float newY = referenceTile.transform.position.y + tileSpacing;
tile.transform.position = new Vector3(tile.transform.position.x, newY, 0);