Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Arno · May 10, 2010 at 11:57 AM · menumouselookfpc

Disable MouseLook script FPC

I want to make a menu inside the game. So if you pres escape a window appears with buttons. When the window appears the mouselook script from the First Player Controller must be disabled. I found and used this script, what seems to be oke. but I get a error when i press escape

NullReferenceException: Object reference not set to an instance of an object Gui.window.Update () (atAssets\script\Gui_window.js:25)

var SkinWindow: GUIStyle; var SkinTitle : GUIStyle; var SkinButton: GUIStyle; private var doWindow0 : boolean= false; private var gameobj : GameObject; private var mouseL : MouseLook; private var cam : GameObject; private var mouseL2 : MouseLook; private var windowRect0= Rect(50,50,300,300);

 function Awake() 
 { 
    gameobj =GameObject.Find("First Person Controller"); 
    mouseL = gameobj.GetComponent(MouseLook); 
    cam = gameobj.Find("First Person Controller/Main Camera"); 
    mouseL2 = cam.GetComponent(MouseLook); 
 }

 function Update ()
 {
     if(Input.GetKeyDown(KeyCode.Escape))
     {
         doWindow0= !doWindow0;
         mouseL.enabled=!mouseL.enabled;
         mouseL2.enabled=!mouseL2.enabled;
     }
 }

 function OnGUI () 
 {
     if(doWindow0)
     GUI.Window(0,Rect(300,10,500,500),StartWindow0,"CONTROLS",SkinWindow);
 }

 /*GUIWindow content*/
 function StartWindow0 (windowID : int)
 {
     GUI.Label (Rect (50,50,350,100), "OM ROND TE LOPEN, GEBRUIK PIJLTOETSEN",SkinTitle);
     doWindow0=GUI.Toggle(Rect(400,400,76,76),doWindow0,"EXIT",SkinButton);  
     GUI.DragWindow(Rect(0,0,10000,10000));
 }

I got the standard First person controller from the standard assets screencap hierarchy

please help!

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
0

Answer by Devin · Dec 08, 2010 at 09:35 PM

Make a static variable:

Static var isGamePaused : Boolean = false;

Then put this inside your update function:

if(Input.GetKeyDown(KeyCode.Escape)){
      if(!isGamePaused){
            isGamePaused = true;
            GameObject.Find("First Person Controller").GetComponent("MouseLook").enabled = false;
            GameObject.Find("Main Camera").GetComponent("MouseLook").enabled = false;
      }
}

Keep in mind that this will only disable the MouseLook. To re-enable it use the same idea in reverse with a different If statement. I.E.

if(Input.GetKeyDown(KeyCode.Escape)){
      if (isGamePaused){
            isGamePaused = false;
            GameObject.Find("First Person Controller").GetComponent("MouseLook").enabled = true;
            GameObject.Find("Main Camera").GetComponent("MouseLook").enabled = true;
      }
}

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
avatar image
0

Answer by kkdogiedog · Feb 29, 2012 at 03:45 AM

Haha i felt stupid when i figured this out. There's two MouseLook scripts, one for your main camera and one for your character controller (typically). Make a script that has this:

 function Update () {
 if (Input.GetKeyUp(KeyCode.Escape)) {
     var mouseLook = GetComponent.<MouseLook>();
     mouseLook.enabled = !mouseLook.enabled;
 }

}

Then add it to both the main camera and your character controller.

This worked for me, hope it works for you

(i know its 2012, this is for anybody else having this problem)

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

1 Person is following this question.

avatar image

Related Questions

Limit mouselook using first person controller 0 Answers

how to stop FPC to rotate with mouse?? 0 Answers

Pause menu... Isn't pausing everything... 1 Answer

Mass Effect Select Menu 1 Answer

options menu for game 1 Answer


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