x


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?

more ▼

asked Jan 28 '11 at 04:34 PM

TurtleWolf gravatar image

TurtleWolf
14 2 4 6

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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...

more ▼

answered Feb 01 '11 at 10:26 AM

TurtleWolf gravatar image

TurtleWolf
14 2 4 6

(comments are locked)
10|3000 characters needed characters left

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;
more ▼

answered Jan 28 '11 at 04:49 PM

DaveA gravatar image

DaveA
26.8k 153 171 257

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?

Feb 01 '11 at 10:01 AM TurtleWolf

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 mine 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...

Feb 02 '11 at 12:03 AM DaveA
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1002
x222
x89

asked: Jan 28 '11 at 04:34 PM

Seen: 1234 times

Last Updated: Jan 28 '11 at 04:34 PM