Change the color of GameObject when it is in the List

Hi Everybody!

i am new here in unity and i’m working in a chess-like board game. What I want to do is change the color of the board piece when a player piece pass above it.

So, here is what i’ve done so far:

while(new Vector2(i, j) != _coordFinal)
			_piecePath.Add(new Vector2(i,j));
			if(_boardPieces[i,j] != 0)
				CollisionBool = true;
			i += _incX;
			j += _incY;

while checking the path of the player piece, I also add each of the coordinates in the _piecePath List.
Then in the board Tile class:

void Update () {
	positions = new Vector2(this.gameObject.transform.position.x,this.gameObject.transform.position.z);

	if (_GM._piecePath.Contains(positions)) {
			GetComponent<Renderer> ().material.SetColor ("_Color",pathColor);

then I recieved null exception and nothing happens in the board.

So if I’m understanding you correctly, you want the squares below the pieces to change color when the pieces are over it. Right?

If so, then the simple solution is to use raycasts. Point the raycasts down at the board and if the raycast hits a square, change the color of that square.

You can use collisions on top of the squares or you can just use coordinates. It’s all up to you.