detect any UI action
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.
Read the docs man! :P
The first hit has an example. O$$anonymous$$, I understand that you may not have found it as the example is under selectable.OnPointerEnter and the EventTrigger.OnPointerEnter is pretty empty!
There is also this, as found from a simple search.
http://answers.unity3d.com/questions/967170/detect-if-pointer-is-over-any-ui-element.html
After reading the material Ive linked, if you have trouble, edit this question and add your code; then you can get some proper help.
Thank you! I'm sorry. I behaved stupidly with my searching. But after some trying I finally figured it out with the help of the second link and a little further research.
"+1" to you friend.
I converted my answer to a comment. Accept your own answer and give a +1 to the answer through the link :)
Answer by JohannChristoph · Apr 04, 2016 at 07:09 PM
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;
}
}