Changing color of cubes when standing upon them

the game floor is made up of many seperate cubes, and I want it so when the player walks on the cube, just that cube changes color, however if the player moves off that cube, it goes back to its original color…

Ive kinda got there, I’ve assigned the script to the player, but I can only assign one cube to the script, whereas I want it to apply to all cubes without having to manually drag 400 off cubes into the script, Ive tried Find.GameObjectWithTag(“Cubes”) and assigned all the cubes to the cube tag, however that hasnt worked…

Here is what I have so far

using UnityEngine;
using System.Collections;

public class distanceCube : MonoBehaviour
{

    public GameObject Cube;
    public float rangefinditem = 10f;//items will change color if its distance to player is <= 10 
    void Update()
    {
        GameObject.FindGameObjectsWithTag("Cube");

            float distance = Vector3.Distance(transform.position,Cube.transform.position);
            if (distance <= rangefinditem)
                Cube.GetComponent<Renderer>().material.color = Color.green; //new color
            else
                Cube.GetComponent<Renderer>().material.color = Color.red; //original color
    }
}

any ideas?

Use OnCollisionEnter so… add dis script to your script for your box

void OnCollisionEnter2D( Collision col){
  GetComponent<Renderer>().material.color = Color.green;
}
void OnCollisionExit2D( Collision col){
  GetComponent<Renderer>().material.color = Color.Red;
}