Quantcast
Viewing latest article 4
Browse Latest Browse All 10

How do I check if raycast is hitting a gameobject?

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.

Viewing latest article 4
Browse Latest Browse All 10

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>