Hey I have a problem I need to show some text whenever a raycast hits a building. That's no problem, but if I etc. look up in the sky after looking at a building the text will still be visible.
Here's the code:
void Update () {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 25)) {
if(hit.collider.gameObject.layer == 8 && hit.collider != null) {
actionMenu = true;
return;
}
actionMenu = false;
}
}
So my question is... How do I check if my raycast is still hitting a gameobject and if not it should return false.
↧