Hi All,
At first this seem like a simple idea, but I can’t seem to figure out how to do it.
I have a raycast, and when it hits an object with tag “key”, it sets a boolean in script on that object to TRUE. Easy.
What I’d like is for when the the raycast stops hitting that same object, the boolean reverts to FALSE.
Here’s what I got so far, amongst many other bizarre attempts.
private bool Key;
public Camera camera;
void Start() {
camera = GetComponent<Camera>();
}
void Update() {
Ray ray = GetComponent<Camera>().ViewportPointToRay(new Vector3(0.5F, 0.5F, 0));
RaycastHit hit;
{
if ((Physics.Raycast(ray, out hit, 100)) && (hit.collider.tag == "Key"))
{
Key = hit.collider.gameObject.GetComponent<Activated>().active;
Key = true;
}
else if (Key != null)
{
Key = false;
}
}
}
}