Need to change the color of a sprite

I know this sounds kinda silly. I just started learning how to use unity and c#. I’m trying to make Conway’s Game of Life to start to learn some stuff. I kinda completed it already but it only works in a 10x10 grid.I want to learn to change the amount of columns and rows so when I run the code everything fits inside the camera. I also don’t know how to change the color of one of the “Squares” in the grid since my code just creates a new object on top of the old one after each generation.

Note: I based my code on this video:

This is my code so far:

void Start()
    {
      
        Vertical=(int)Camera.main.orthographicSize;
        Horizontal=Vertical;
        Grid = new float [c, r];
        for(int i=0; i <c; i++)
        {
            for(int j=0; j<r;j++)
            {
               
                if(Random.Range(0.0f,100.0f)>70.0f)
                {
                    Grid[i,j]=1.0f;
                }
                else
                {
                  Grid[i,j]=0.0f;
                }
                //Grid[i,j]=Random.Range(0.0f,1.0f);
                SpawnTile(i, j, Grid[i,j]);
            }
          
        }

        InvokeRepeating("Movement", 1.0f, time);
      
    }

    private void SpawnTile(int x, int y, float value)
    {
        GameObject g= new GameObject("x:"+x+"y:"+y);

        g.transform.position= new Vector3(x-(Horizontal), y-(Vertical-.5f));

        var s =g.AddComponent<SpriteRenderer>();
        s.sprite= sprite;
        s.color = new Color(value, value, value);

    }

    private void Movement()
    {
        Backup=Grid;
        int vec;

      
        for(int i=0; i <c; i++)
        {
            for(int j=0; j<r;j++)
            {
                vec= Vecinos(i,j);

                if((Backup[i,j]==1.0f) && ( vec>3))
                {
                    Grid[i,j]=0.0f;
                }else if((Backup[i,j]==1) && (vec>=2 && vec<=3))
                {
                    Grid[i,j]=1.0f;
                }else if(Backup[i,j]==0 && vec==3)
                {
                    Grid[i,j]=1.0f;
                }else if(Backup[i,j]==1 && vec<2)
                {
                    Grid[i,j]=0.0f;
                }

                SpawnTile(i, j, Grid[i,j]);
              
            }
          
        }


    }

Create a 2d array of objects and initialize them as having the same size of your grid.

GameObject[,] myObjects;

void Start()
{
    myObjects = new GameObject[c, r];
}

Then, when instantiating your tiles, assign them last to this new array you just created in your SpawnTile method:

myObjects[x, y] = g;

Now to change each sprite you just need to loop them or access them directly, example:

SpriteRenderer s = myObjects[7, 13].GetComponent<SpriteRenderer>();

s.color = new Color(1, 1, 1);

It’s even easier and has a better performance if you make a 2d array of sprite renderers instead, now that you know a little about how to do this you can improve the code.