Unity 5 UI not blocking Raycast Collider ( Physics Raycast )
In my project I'm using the Unity UI to make the inventory of the character. at the scene, there are objects with raycast that when they are clicked, activate a UI with information about them. if i'm in front of these same objects, and Enabled the IU Inventory, and click on the objects with Raycast, the UI with information about it appears, and hinders the process of inventory. I tried a few methods to make the UI block Raycast Collider (Physics Raycast). The only one that worked was this:
At the top: using UnityEngine.EventSystems;
In Void Update: if (EventSystem.current.IsPointerOverGameObject ()) {
In the editor of Unity, everything works perfectly. But the problem is in the build, which does not work. I use:
void Start () {
Screen.lockCursor = true;
Cursor.visible = false;
To lock the mouse pointer in the center of the screen, and i see if disable this function, the script with Collider Raycast (Physics Raycast) works perfectly in the build.
So I was wondering if someone can help me, can be a method to make the UI block Raycast Collider (Physics Raycast), or some other method to lock and hide the mouse pointer, or something similar.
in short: I need a method, to make the UI block Physics Raycast (Raycast Collider).
Note: sorry for bad English, I used a translator.
Answer by Clonus · Feb 11, 2016 at 06:41 PM
I am experiencing the same issue. I have been using this to hepl me understand what is going on. So far no luck with various blogs or posts.
void OnMouseDown()
{
Debug.Log("MouseDown");
Debug.Log(string.Format("IsPointerOverGameObject() : {0}",EventSystem.current.IsPointerOverGameObject()));
}
void OnMouseUp()
{
Debug.Log("MouseUp");
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
Physics.Raycast(ray, out hit);
Debug.Log(string.Format("HitPoint : {0}", hit.point));
}