Need help changing material back when raycast no longer hitting object.

Hi, I have a laser sight on a player which is also using a Raycast to hit an enemy and change its material to a different colour while you have the laser sight pointed at it. The idea being the enemy remains a certain colour while it’s being targeted. But I’m not sure how to get the enemy material to change back to its original state when you move the laser sight off of it.

At the moment I’m using this script below to send a Raycast message to change the material in a script on the enemy.

void Update () {

		laserSight.SetPosition (0, transform.position);
		shootRay.origin = transform.position;
		shootRay.direction = transform.forward;

		if(Physics.Raycast (shootRay, out shootHit, range, shootableMask))
			EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth> ();
			if (enemyHealth != null)

			laserSight.SetPosition (1, shootHit.point);

			laserSight.SetPosition (1, shootRay.origin + shootRay.direction * range);

And then this is the section of script that’s being called on the enemy.

	public void Targeted ()
		Material m = body.material;
		body.material.color =;
		print ("targeted");

I’m not really sure how you change it back, as obviously once the laser sight goes off the enemy then the Targeted section is no longer called so I assume I don’t do it there. I’ve tried using a bool in the enemy update function which is set to true when hit whilst starting a coroutine to reset it after a short time, but the problem is this keeps resetting the material whilst still targeting the so the enemy ends up flashing.

Ok I’ve worked out a way around this for any that are interested, though I’m sure there’s a more efficient way to do this, so please still tell me if you know it.

At the moment the best way I can find to do this is by creating a small sphere set at the player position with the mesh renderer turned off so it’s hidden, and set the collider to a trigger. I’ve then added a script to the sphere with OnTriggerStay to detect my target with a tag, then change the material in that. Then OnTriggerExit I use to set the material back to the original state. It’s then just a case of setting the sphere position to the raycast hit point if the target has my enemyhealth script.