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 hannm · Jan 22, 2014 at 08:01 AM · mousedisablelockmouselock

disable script when i press escape??

hey, i have this java script that locks the mouse for my FPS

 function Update () {
 Screen.showCursor = false;
 Screen.lockCursor = true;
 Screen.lockCursor = false;
 }
 
 if(Input.GetKeyDown("escape")
   {
    paused  = !paused ;
  
     if(paused) //Do Stuff When Paused
      {
      Screen.showCursor = true; 
         }
          else // Do stuff when unpaused
            {
               Screen.showCursor = false; 
                }
  
                }
                  }
 

it shows error saying, Assets/_Scripts/MouseLOCK.js(10,3): BCE0044: expecting ), found '{'.

i need it so when i press escape it turns off the lock script so that way i can navagate the menu and when i press escape again it turns lock back on.

thanks guys

Comment
Add comment · Show 3
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 ahaykal · Jan 22, 2014 at 09:18 AM 0
Share

First please format your code - Check out the unity tutorial.

 var paused : boolean = false;
 function Update () 
 { 
 if(Input.Get$$anonymous$$eyDown("escape")
   {
    paused  = !paused ;
 
   if(paused) //Do Stuff When Paused
    {
    Screen.showCursor = true; 
    }
   else // Do stuff when unpaused
    {
    Screen.showCursor = false; 
    }
 
   }
 }
avatar image hannm · Jan 23, 2014 at 08:35 AM 0
Share
 function Update () {
 Screen.showCursor = false;
 Screen.lockCursor = true;
 Screen.lockCursor = false;
 }
 var paused : boolean = false;
 function Update () 
 { 
 if(Input.Get$$anonymous$$eyDown("escape")
   {
     paused  = !paused ;
     
     if(paused) //Do Stuff When Paused
       {
       Screen.showCursor = true; 
          }
            else // Do stuff when unpaused
              {
               Screen.showCursor = false; 
                }
                
                 }
                  }


i tried this but it gives me errors... the script locks the mouse but need it to unlock the mouse when i press escape then re lock it once i press it again...:(

avatar image fafase · Jan 23, 2014 at 09:09 AM 0
Share

You have two Update methods.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Ryanvanpolen · Jan 22, 2014 at 10:50 AM

you use no boolean... (R6)

 if(input.GetKeyDown("escape")) {
 //you say paused = !paused
 paused = true; //if you tap escape, than is pause true
 if(paused) {
 //do some stuff...
 }
 //you don't need an else, but you can do it if you like to
 }

Maybe this works better...

succes

Comment
Add comment · Show 1 · 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 fafase · Jan 23, 2014 at 09:07 AM 0
Share

no this won't since pause is always true. He wants to press escape to set on and off.

avatar image
0

Answer by hannm · Jan 23, 2014 at 10:44 PM

i changed it to

 function Update () {
 Screen.showCursor = false;
 Screen.lockCursor = true;
 Screen.lockCursor = false;
 }
 
 if(Input.GetKeyDown("escape")
   {
    paused  = !paused ;
  
     if(paused) //Do Stuff When Paused
      {
      Screen.showCursor = true; 
         }
          else // Do stuff when unpaused
            {
               Screen.showCursor = false; 
                }
  
                }
                  }


but it gave me error saying, Assets/_Scripts/MouseLOCK.js(10,3): BCE0044: expecting ), found '{'.

can anyone re write it for me?? i thought i fixed it but nope :(

thanks

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

20 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

Related Questions

Cant unlock cursor with FPS prefab 2 Answers

Cursor lock not working after alt tab 2 Answers

Lock mouse position with a Rect, possible? 1 Answer

turn off script with a key.. 1 Answer

How to lock mouse cursor but still move camera 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