- Home /
Suspend Mouse Look
How would I suspend the mouse look script? I want to be able to click on my GUI in first person with out turning my head/(camera) to select a GUI.button. Can't I add a command to the mouse look script to suspend it when I hold down shift or alt?
Answer by DaveA · Jan 28, 2011 at 04:49 PM
You check the current mouse position against the window containing your GUI element(s) and set a global (I use a Plugin, you could also use a common script object). Then in MouseLook, return early from Update if that's set. Also, clear that global boolean in a LateUpdate function.
I made this my 'global' variable manager:
using UnityEngine;
public class GUIManager : MonoBehaviour { public static bool GUI_is_showing = false;
public static void SetGUIShowing (bool val)
{
GUI_is_showing = val;
}
public static bool isGUIshowing()
{
return GUI_is_showing;
}
void LateUpdate()
{
GUIManager.GUI_is_showing = false;
}
}
Then in my OnGUI() functions:
windowRect = GUILayout.Window (1, windowRect, EditView, "My View");
var mouseOverMe : boolean = windowRect.Contains(Event.current.mousePosition);
if (mouseOverMe)
GUIManager.SetGUIShowing (true);
Then in MouseLook:
void Update ()
{
if (GUIManager.isGUIshowing())
return;
Thank you... I really appreciate your help, DaveA! I am new to scripting and just haven't got my head around all the nuances. Even more than just having a code that works, I am really trying to crasp what's going on here, it's seems like your solution is more complicated than it would need to be, which is why I haven't responded sooner. I have been trying to absorb your answer until I understood it, and having the working code should augment that understanding. All of the scripts seem to have a check box to enable them. Is it not a good idea to script a keyboard key to un-check this?
Yeah, actually, I coded this when I was a noob too. The other post is much cleaner, using 'active' is a much better way to go, generally. I think $$anonymous$$e grew out of a need to turn off one axis but leave the other on, or something strange. I voted up the other answer. That said, if you have other UI items which may need to set/check such state, a GUI manager may still come in handy...
Answer by TurtleWolf · Feb 01, 2011 at 10:26 AM
Sorry I didn't see this in my original search, but this thread actually covers what I was talking about, How do I disable mouse look when a button is pressed? Maybe my mis-phrasing will help some other hillbilly find his answer too...
Your answer
Follow this Question
Related Questions
How to disable click to move on interface elements ? 0 Answers
How can I let my Sprite look towards the mouse in Unity 4.3 2D? 1 Answer
How to control a weapon through a single mouse movement? 2 Answers
draw line between mouse and gameobject on flat plane 0 Answers
How can I save MouseLook position in this script ? 0 Answers