I have this script that detects when a raycast hits an object and runs a function from that gameObject.
How can I detect when the raycast leaves the object so I can run a different function to that gameObject?
using UnityEngine;
using System.Collections;
public class CastRays : MonoBehaviour {
SetRenderQueue srq;
void FixedUpdate()
{
RaycastHit hit;
Vector3 forward = transform.TransformDirection (Vector3.forward) * 7;
if (Physics.Raycast (transform.position, forward, out hit) && hit.transform.tag == "Block") {
print ("There is something in front of the object!");
srq = hit.transform.gameObject.GetComponent<SetRenderQueue> ();
srq.MakeTransparent (); //Run Function
}
Debug.DrawRay(transform.position, forward, Color.green);
}
}