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 Whiteleaf · May 28, 2015 at 10:15 PM · cursor

Locking the cursor in Unity 5?

All of the answer thread I've seen have not helped, the Unity 5 cursor locking is confusing ; and the old way of doing it doesn't work anymore.

Can someone please explain how this all works? NOTHING, helped. The documentation, other thread, etc.

Comment
Add comment · Show 1
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 Morseliot · Jun 11, 2015 at 09:07 AM 0
Share

Same bug overhere... going back to 4.6

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by tanoshimi · May 28, 2015 at 10:16 PM

What part of the documentation don't you understand? It seems pretty explicit to me: http://docs.unity3d.com/ScriptReference/Cursor-lockState.html

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
1

Answer by erebel55 · May 28, 2015 at 11:04 PM

 Cursor.lockState = CursorLockMode.Locked;

and you probably want to hide the cursor too

 Cursor.visible = false;
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 Whiteleaf · May 29, 2015 at 09:17 AM

I tried yours Erebel, but when I do it locks my cursor in the bottom left of my screen. My monitor resolution is around 1600x1000; I don't know if that's it.

Tano, it just didn't explain it enough for me. There's no "If this happens, then...", and things like that. It literally just told you what the code was and no debugging/issues that might occur.

Comment
Add comment · Show 7 · 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 erebel55 · May 29, 2015 at 11:04 AM 0
Share

Please post your comments with the "add new comment" button ins$$anonymous$$d of as an answer.

Screen resolution should have nothing to do with it.

Where are you calling Cursor.lockState?

Try calling it within Update() like so..

 public class $$anonymous$$ouseLock : $$anonymous$$onoBehaviour
 {
     void Start()
     {
         // hide the cursor
         Cursor.visible = false;
     }
 
     void Update()
     {
         if (Cursor.lockState != CursorLock$$anonymous$$ode.Locked)
         {
             // lock the cursor
             Cursor.lockState = CursorLock$$anonymous$$ode.Locked;
         }
     }
 }
avatar image Whiteleaf · May 29, 2015 at 03:20 PM 0
Share

Oops sorry this is my first answers post, so I didn't know there was a "add comment" button. I'll try your code and hopefully it works. I was putting it in start because later on if say I had an Inventory, wouldn't I not want it to be locked every frame?

avatar image Whiteleaf · May 29, 2015 at 10:34 PM 0
Share

Okay so now when I lock the cursor, it locks it at the top of the screen next top the pause button and even when I tell it to be invisible it is visible. Why is this happening?

EDIT: After a $$anonymous$$ute of letting playmode sit it seemed to disappear but I'm not entirely sure if it was in the middle which kinda bothers me, but nonetheless it's locked.

Hope it doesn't effect it in the standalone, thanks for the help people!

avatar image erebel55 · May 30, 2015 at 05:45 PM 0
Share

Please mark an answer as accepted if it helped you.

avatar image Whiteleaf · May 31, 2015 at 04:26 AM 0
Share

I'm not going to; as it didn't help. I thanks because people actually replied, I already know how to do everything you gave me in that code.

But I also found a new problem, with a $$anonymous$$ouseLook script I followed from a Unity 5 tutorial, the script works fine, but when I press any key the mouse flickers even though I told it to be invisible. It also is locking at random locations and doesn't disappear till I click on the screen.

Would it be that I have a 32-bit operating system? I'm currently running Windows XP Professional; as soon as I get Windows 8 maybe that'll fix it. Also would it maybe be because I can only have DirectX 9 on Windows XP?

EDIT: Okay, so as it turns out it does not have this affect in the standalone, but only in the editor. I'm guessing it's a bug and no one else has experienced it maybe? I'm running the newest version of Unity 5, Personal Edition.

Show more comments

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Mouse cursor doesn't lock Unity 5 0 Answers

Cursor Lockmode only works once? 1 Answer

Cursor bug 0 Answers

Keep Cursor at center and project interactions to cursor position on mobile touch devices (IOS) 0 Answers

Cursor.lockState does not work 2 Answers


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