0
\$\begingroup\$

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. enter image description here

\$\endgroup\$
2
  • 2
    \$\begingroup\$ What have you tried? \$\endgroup\$
    – Engineer
    May 6 '20 at 9:48
  • \$\begingroup\$ I tired doing it with 2d sprites but found a problem when wanting to press and delete multiple sprites. Also tried using squares in a 3d space with a 2d view but keeping track of the different positions of each block and what need to be deleted after a square has been selected just confused me. Now I'm trying to do it with buttons? \$\endgroup\$
    – user139388
    May 6 '20 at 9:55
0
\$\begingroup\$

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 Tilemap component allows you to access individual tiles with tilemap.GetTile and even has a convenient method for setting the color tint of a tile directly with tilemap.SetColor
\$\endgroup\$
1
  • \$\begingroup\$ Thank you so very much I'll be trying that just now. Again really do appreciate it. \$\endgroup\$
    – user139388
    May 6 '20 at 10:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .