Is there a smart way to just detect any action of the new UI? Because I rotate my camera with mouse click and drag (or touch with one finger and drag) to look around. But when I use a UI slider for example I don’t want the camera to rotate. I looked into the EventSystem and Modules, but I just don’t get it how to apply it.
Basically I just need to know if the mouse (or touch) is over an UI-element to set a boolean. Depending on true or false I want to block or allow the camera rotation.
The second link (Detect If Pointer Is Over Any UI Element) is a good hint and a better way to put the question.
The function to use is EventSystems.EventSystem.IsPointerOverGameObject, which returns a boolean. An EventSystem with Input Module(s) needs to be present in the scene.
The Javascript code I use for my scenario is:
static var myPointerIsOverUI : boolean; // my camera checks this before rotating
function Update () {
var ct : UnityEngine.EventSystems.EventSystem;
ct = UnityEngine.EventSystems.EventSystem.current;
if (ct.IsPointerOverGameObject()){
myPointerIsOverUI = true;
} else {
myPointerIsOverUI = false;
}
}