How to create an array of cubes such that when you click on one of them all the cubes in that row change color

Hello, I’m new to unity and I would like to know to create a two dimensional array of cubes in a game such that when you click on anyone of them, the color of all in the same row change. I would like to learn how to make it so that by changing one parameter you get a diferent grid size. I would appreciate it very much if someone could help me!

Thank you but I mean how do I process all the cubes such thag when I click on one all in the same row change not just the one I clicked

@Isas29
Create & Add CubeHandler.cs in Main Camera , create & add CubeMonoBehaviour.cs in the cube prefab. Ganbatte!

CubeHandler.cs

using UnityEngine;
using System.Collections;

public class CubeHandler : MonoBehaviour {

    int rows, columns;
    public MyCube[,] cubeGrid;
    [SerializeField]
    GameObject cubePrefab;
    static CubeHandler instance;
    public static CubeHandler Instance { get { return instance; } }

    void Awake()
    {
        if (instance) Destroy(this);
        else instance = this;
    }

	// Use this for initialization
	void Start () {
        rows = 4;
        columns = 4;
        cubeGrid = new MyCube[rows, columns];
        FillCubeGrid();
	}
	
	void FillCubeGrid () {
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < columns; j++) {
                MakeCube(i, j);
            }
        }
	}

    void MakeCube(int i, int j){
        cubeGrid[i, j] = new MyCube { cube = Instantiate(cubePrefab, new Vector3(i, j, 0), Quaternion.identity) as GameObject };
        cubeGrid[i, j].cube.transform.localScale = Vector3.one * 0.5f;
        //cubeGrid[i, j].cube.AddComponent<CubeMonoBehaviour>();
    }
}



public class MyCube  {
    public GameObject cube;
}

CubeMonoBehaviour.cs

using UnityEngine;

public class CubeMonoBehaviour : MonoBehaviour
{

    void OnMouseDown()
    {
        //change column color
        for (int i = 0; i < 4; i++)
        {
            for (int j = 0; j < 4; j++)
            {
                if (transform.position.y == (float)j)
                {
                    CubeHandler.Instance.cubeGrid[i, j].cube.GetComponent<MeshRenderer>().material.color = Color.red;
                }
            }
        }
    }
}