[Scripting] how to Automatically generate a square board of boxes

I want to generate a square grid of boxes such that I can tell from the inspector how big it will be and such that when I click on a box

all the boxes in the same row change color. I was able to do the first part but I cant get them to change color. If someone would share ideas on how to do both I would appreciate it very much!

I suppose you have everything in a grid like

X X X X
X X X X
X X X X
X X X X

which in code would look like Vector3[4,4]

you could then grab the collider you clicked on’s position and find it in the 2d array,
And then all u need to do is grab the neighbors of the array’s position on that given line.
It’s all in the mind, just think about it. It’s not that hard.

Ok,

first, you need a manager.

namespace UnityCoach.Answers
{
	[AddComponentMenu ("UnityCoach/CkeckerBoard")]
	public class CheckerBoard : MonoBehaviour
	{
		[SerializeField] GameObject cube; // reference to the object to duplicate
		[SerializeField] Color colorOff = Color.gray; // the color when false/off
		[SerializeField] Color colorOn = Color.green; // the color when true/on
		[SerializeField] int width = 8, length = 8; // the width and length of the board
		bool [,] board; // the board states
		GameObject [,] cubes; // the board objects
		Renderer [,] renderers; // the board renderers

		// Singleton (unique instance)
		private static CheckerBoard _instance;
		public static CheckerBoard instance
		{
			get
			{
				if (_instance == null)
					_instance = (CheckerBoard)GameObject.FindObjectOfType(typeof(CheckerBoard));
				
				return _instance;
			}
			private set { _instance = value; }
		}

		void OnDisable()
		{
			instance = null;
		
		}

		void Awake ()
		{
			instance = this;

			// initialising the boards 2-dimensions arrays
			board = new bool[width, length];
			cubes = new GameObject[width, length];
			renderers = new Renderer[width, length];

			// intanciating the objects
			for (int x = 0 ; x < width ; x++)
			{
				for (int y = 0 ; y < length ; y++)
				{
					cubes[x,y] = Instantiate (cube, new Vector3 (x, 0, y), Quaternion.identity);
					renderers[x,y] = cubes[x,y].GetComponent<Renderer>();
					BoardCell cell = cubes[x,y].GetComponent<BoardCell>();
					cell.x = x;
					cell.y = y;
				}
			}
		}

		/// <summary>
		/// Switches the given row.
		/// </summary>
		/// <param name="row">The Row to switch.</param>
		public void SwitchRow (int row)
		{
			for (int x = 0 ; x < width ; x++)
			{
				board[x, row] = !board[x, row];
				renderers[x, row].material.color = board[x, row] ? colorOn : colorOff;
			}
		}
	}
}

Then, you need a simply script on the cell object, to tell the manager when it is clicked.

namespace UnityCoach.Answers
{
	[AddComponentMenu ("UnityCoach/BoardCell")]
	[RequireComponent (typeof (Collider))] // requires a Collider to catch OnMouseUpAsButton message
	public class BoardCell : MonoBehaviour
	{
		[HideInInspector] public int x, y; // where is this on the board

		void OnMouseUpAsButton ()
		{
			CheckerBoard.instance.SwitchRow (y);
		}
	}
}

Thanks for the challenge, quite interesting!
Hope this helps.