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;
}
}
}
}