So I need to create a square grid like the one below. And be able to click on a square, the square you chose then is filled with a different color as well as all the squares right and below the square you have chose. My question is what will be the most efficient way to create this grid either in 3D or 2D in Unity.
The component you seem to be looking for is the TileMap.
A complete tutorial would be a bit too broad, and also redundant because there are many good tutorials for it available through your preferred search engine. So here just an overview:
- A tilemap is empty at first. You need to paint tiles on it, either by hand or programmatically.
- In order to do that, you need a tile image first. If you want a grid like this, you should create a sprite which is just a black rectangle with white fill.
- Clicks on tiles can be detected by adding colliders to all tiles or using the technique described here.
- When scripting, the
Tilemapcomponent allows you to access individual tiles with
tilemap.GetTileand even has a convenient method for setting the color tint of a tile directly with