Hey so what I’m trying to do is, look at an object, it turns yellow. If I’m not looking at the object, it turns back to red. I get it to yellow fine, but going back to red has me stumped. The ‘else’ statement below does nothing, doesn’t even register a Debug.Log. Not sure what to do. Any ideas would be great, thanks!
.
public float rayLength;
public GameObject player;
void Update()
{
RaycastHit hit;
Ray ray = new Ray (transform.position, transform.forward);
Debug.DrawRay (transform.position, transform.forward * rayLength);
if (Physics.Raycast (ray, out hit, rayLength))
{
PlatformDummyScript platforms = hit.transform.GetComponent<PlatformDummyScript> ();
if (platforms != null)
{
if (platforms)
{
platforms.GetComponent<MeshRenderer> ().material.color = Color.yellow;
if (Input.GetKeyDown (KeyCode.G))
{
Vector3 offset = new Vector3 (0, 1, 0);
player.transform.position = platforms.transform.position + offset;
}
}
else
{
platforms.GetComponent<MeshRenderer> ().material.color = Color.red;
}
}
}
}