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 ccwiegreff · Apr 11, 2014 at 05:48 PM · javascriptmouselookbooleans

Main Camera = false problems

For my pause script i wanted the camera to freeze, unlock, and then freeze again when paused. It starts out okay but it never changes to true.

 private var lock_X : boolean = true;
 private var lock_Y : boolean = true;
 
 function Start() {
 
 lock_X = GameObject.Find("First Person Controller").GetCompenent(MouseLook).enabled = false;
 
 lock_Y = GameObject.Find("Main Camera").GetCompenent(MouseLook).enabled = false;
 }
 
 function Update(){
 lock_X = lock_X
 lock_Y = lock_Y
 }
 
 function PauseGame(){
 
 lock_X = !lock_X;
 lock_Y = !lock_Y;
 }
 
 function UnPauseGame(){
 
 lock_X = !lock_X;
 lock_Y = !lock_Y;
 }
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

1 Reply

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

Answer by perchik · Apr 11, 2014 at 06:02 PM

Well here's a few thoughts

It's probably a bad idea to toggle the locks, when you know what you want them to be. When you unpause you want to set lock_X = false, so do that. Toggling it could lead to incorrect behavior.

Second, lock_X = lock_X does nothing.

Next, this line lock_X = GameObject.Find("First Person Controller").GetCompenent(MouseLook).enabled = false; probably doesn't do what you expect. It sets lock_x and the enabled member of the mouse look component to false. My guess is that you want to save the current value of enabled and then toggle it later.

Then, you're not actually changing .enabled after Start because Lock_X copies the value of enabled, but doesn't actually point to enabled. So changing Lock_X doesn't changed the enabled property

With all that said, Here's some untested code that I think may work:

 private var lock_X : boolean = false;
 private var lock_Y : boolean = false;
 private var fpsMouse : MouseLook;
 private var camMouse :MouseLook;
 
 function Start()
 {
     fpsMouse = GameObject.Find("First Person Controller").GetCompenent(MouseLook);
     camMouse = GameObject.Find("Main Camera").GetCompenent(MouseLook);
     
     fpsMouse.enabled = false;
     camMouse.enabled = false;
 }
  
 function Update()
 {
     if(fpsMouse.enabled != lock_X)
     {
         fpsMouse.enabled = lock_X;
     }
     if(camMouse.enabled != lock_Y)
     {
         camMouse.enabled = lock_Y;
     }
 }
  
 function PauseGame()
 {
     lock_X = false;
     lock_Y = false;
 }
  
 function UnPauseGame()
 {
     lock_X = true;
     lock_Y = true;
 }

Still, with all that said, you never call PauseGame() or UnpauseGame() in this code, so I don't know if it ever gets called.

EDIT Updated the code to include lock_Y.

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

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

OnTriggerStay Not Working, JavaScript Help Needed 1 Answer

Animation Script not working. 1 Answer

fps MouseLook with animation applied to camera. 1 Answer

Mouse look script help 1 Answer

Showing and Locking Cursor - JavaScript / JS 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