- Home /
If mouse is hovering over any GUI element
Hi, I am working on a small rpg project to get into unity and scripting.
I am turning my 3rd Person Camera while holding the left MouseButton, the Player by holding the right one and move the Character by holding both of them down.
if (Input.GetMouseButton(1)){
PlayerInput.instance.transform.rotation = Quaternion.Euler(PlayerInput.instance.transform.eulerAngles.x, Camera.main.transform.eulerAngles.y, PlayerInput.instance.transform.eulerAngles.z);}
if (!Input.GetMouseButton(0)){
Camera.instance.RotateWithCharacter();}
if (Input.GetMouseButton(0) && Input.GetMouseButton(1)){
vertical = 1f;}
Now I want this to only work if the mouse is NOT over any GUI element (in my case the inventory, lootwindow, actionbar and so on). I had a rather bad solution for this.
I created an invisible button that covered the whole screen and was behind the other buttons. And if I clicked on the button I was able to rotate character/camera. Using this method I couldnt click on ingame objects, because of the button.
The other solution I found was by using hotControl (http://docs.unity3d.com/ScriptReference/GUIUtility-hotControl.html), but I dont really understand how it works.
Could someone please explain it to me or post another solution which is easier to understand?
I've never used it, but in reading the reference it does not appear to be what you want since the user has to click on a control for it to be hot. If your GUI interface is static, you can just define a screen rect (or rects) that define the valid (non GUI) area(s) of the screen and check clicks against that rect or rects. If your layout varies across resolutions, you can define the rect in viewport coordinates and convert it screen coordinates at runtime.
Thank you. I actually wanted to make the inventory dragable, but considering the resulting difficulties ill make it static. $$anonymous$$aybe if I get more know-how ill add this feature.
you could use bool true or false check inside a collison check for On$$anonymous$$ouseStay or On$$anonymous$$ouseEnter and On$$anonymous$$ouseExit of a script. You will be disabling and enabling code blocks. The exact syntaxt could be looked up in the manual. To me using the checks is a better way, but there is many ways. also the videos on scripting, helped me a lot you should start with some of them, it helps fill in the gaps. hers 2 difrent ones from unity to check out. A: from Tutorials!
b: from online Live Training Archive