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
1
Question by Apples_mmmmmmmm · May 03, 2011 at 11:06 PM · javascriptmouselookpausegame

Way to pause/unpause, or stop/start mouselook script?

I wrote a script to pause the game when the esc key is hit. This includes the Time.timeScale being set to 0 when paused as well as AuidoListener.pause being set true when the key is hit, and the opposite values in order to unpause it. When it is paused however, I also want the character to stop being able to look around (which I figure disabling mouselook would take care of) So that my menu options when paused can be clicked on without the character looking around while the selection is trying to be made.

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
Best Answer

Answer by Apples_mmmmmmmm · May 04, 2011 at 01:59 AM

So after looking around, I was able to find somewhat of a solution. However, even with the following code, the player can still rotate around the x-axis which I've yet to find a solution to.

 if(Input.GetKeyDown(KeyCode.Escape))
GetComponent("MouseLook").enabled = !GetComponent("MouseLook").enabled;

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 GesterX · May 03, 2011 at 11:14 PM

You need to disable the mouselook script with something similar to below (from a similar question):

Static var Dialog : Boolean = false;

Then put this inside your update function:

if(Dialog){ GameObject.Find("First Person Controller").GetComponent("MouseLook").enabled = false; GameObject.Find("Main Camera").GetComponent("MouseLook").enabled = false; }

if(!Dialog){ GameObject.Find("First Person Controller").GetComponent("MouseLook").enabled = true; GameObject.Find("Main Camera").GetComponent("MouseLook").enabled = true;
}

Then just toggle the Dialog variable when the game is paused and unpaused.

Comment
Add comment · Show 3 · 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 Apples_mmmmmmmm · May 03, 2011 at 11:24 PM 0
Share

I tried adding this in and recieved errors because $$anonymous$$ouseLook is not static, how would I go about making this static?

avatar image GesterX · May 03, 2011 at 11:29 PM 0
Share

I edited the answer - it should work now

avatar image Apples_mmmmmmmm · May 03, 2011 at 11:42 PM 0
Share

Hmm, I tried a few variations of your code within my script and couldn't seem to get it to work still. If I have it as is, I get an error to put a ; after the static var line. If I change the line to static var Dialog : boolean = false; then the first error goes away, but I'm left with the errors for trying to access non static member GetComponent. Any more ideas?

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

Mouse look script help 1 Answer

MouseLook.cs:case of JavaScript 1 Answer

Showing and Locking Cursor - JavaScript / JS 1 Answer

Screen go Gray and only Cursor active OnTriggerEnter 1 Answer

Setting Scroll View Width GUILayout 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