how detect "OnRaycastOut"

When my characterMesh turns towards a cube, it turns gray.
When I move my characterMesh the other way (he now faces a different cube), the new cube should turn gray. I have come that far. I would like the old cube to turn to it’s original color. Any ideas?

using UnityEngine;
using System.Collections;

public class DmgCube_scr : MonoBehaviour {
	
	Color originalColor;
	GameObject target;
	GameController_scr gc_scr;
	
	
	void Start () {
		originalColor = gameObject.renderer.material.color;
		gc_scr = GameObject.Find ("GameController").GetComponent<GameController_scr>();
	}
	

	void Update () {

		// ::::::::::::::::::::::::::::::::::::::::::::::: TARGETING :::::::::::::::::::::::::::::::::::::::::::
		Ray targetingRay = new Ray(transform.position, transform.TransformDirection (Vector3.forward));
		RaycastHit targetHit;
		
		if(Physics.Raycast (targetingRay, out targetHit, 1f))
		{
			if(targetHit.transform.gameObject.tag == "cube")
			{
				target = targetHit.transform.gameObject;
				target.renderer.material.color = Color.gray;
			}
		}
	}
}

you can keep your last target and change it`s color if the new target is not the same

if(targetHit.transform.gameObject.tag == "cube")
                 {
                     target = targetHit.transform.gameObject;
                     if(target!=lastTraget)
                            lastTraget.renderer.material.color = originalColor;
                     lastTarget=target;
                     target.renderer.material.color = Color.gray;
                 }
            else //when player looks at something else other than cubes
                 {
                   
                            lastTraget.renderer.material.color = originalColor;
                     
                 }