What is the meaning of the beam in this code? If it is to determine with which object the interaction takes place with it, then:
Ray _ray = MyCamera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(_ray, out hit)) { if (hit.gameObject.tag == "something") { if (UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject()) Debug.Log("Complete!"); } }
Not very cool, but was that the meaning of the beam?
UPD: Then you can leave it through the beam like this:
Ray _ray = MyCamera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(_ray, out hit) && hit.gameObject.tag == "something") { //if (UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject()) более не требуется. Debug.Log("Complete!"); }
But in my opinion it is better to avoid using the beam even with simple events, or EventTrigger, as suggested in the comments, or somehow.
EventTriggerfor the elements, which theUIbutton has by default, and just add the rest? and no beam is needed - Alexey ShimanskyOnMouseOver/OnMouseEnter/OnMouseDownetc. events should work. docs.unity3d.com/ScriptReference/MonoBehaviour.html - Alexey Shimansky