Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by TurtleWolf · Jan 28, 2011 at 04:34 PM · mousedisablelook

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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;
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TurtleWolf · Feb 01, 2011 at 10:01 AM 0
Share

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?

avatar image DaveA · Feb 02, 2011 at 12:03 AM 0
Share

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

avatar image
1
Best Answer

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

No one has followed this question yet.

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges