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 MechanicalGaming · Mar 18, 2016 at 10:57 PM · c#cursorlock-cursor

Screen.CursorLock problems

Hey everyone!

I'm having a problem with hiding the cursor and locking it in the middle of the screen. It works at first but when I press esc it comes out of it and won't go back in.

Here's the code I am using to try and make this work :

 void Update()
     {
         //Cursor Lock/Unlock//////////////////////////////////////////////////////////////////////////
         if (Input.GetKeyDown(KeyCode.Escape) && cursorUnlocked == false)
         {
             cursorUnlocked = true;
 
             Screen.showCursor = true;
             Screen.lockCursor = false;
         }
 
         if (Input.GetKeyDown(KeyCode.Escape) && cursorUnlocked == true)
         {
             cursorUnlocked = false;
 
             Screen.showCursor = false;
             Screen.lockCursor = true;
         }
         /////////////////////////////////////////////////////////////////////////////////////////////
     }

Thanks for your help guys!

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 Stabbarey · Mar 19, 2016 at 01:28 AM

Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false;

this is the correct code.

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 MechanicalGaming · Mar 19, 2016 at 10:37 PM 0
Share

Cool! Thanks for the help mate!

avatar image
1

Answer by kevinrocks_786 · Mar 19, 2016 at 12:37 AM

Im pretty sure that Screen.lock or Screen.showCursor has been removed since Unity 5.0. However, What I use is this: http://docs.unity3d.com/ScriptReference/Cursor.html

So if you want to make the cursor visible/invisible, you can simply do:

 Cursor.visible = true; // Or false

And to lock the cursor:

 Cursor.lockState = CursorLockMode.Locked;

And to unlock it:

 Cursor.lockState = CursorLockMode.None;


And take a look at Unity's Screen class. Notice how there are not cursor variables: http://docs.unity3d.com/ScriptReference/Screen.html

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 MechanicalGaming · Mar 19, 2016 at 10:36 PM 0
Share

Both of you were right... Didn't know how to do it so I put a plus on you! Thanks for the help mate!

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

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

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Cursor Lockmode only works once? 1 Answer

Centre cursor - Unity 5 (not locking or making invisible) 1 Answer

Aimable reticle using mouse which has limited degrees 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