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 Nourero · Jul 21, 2013 at 03:14 PM · cursormiddle

Mouse cursor not locking in the middle of the screen

Whenever I have my mouse cursor locked it never goes to the middle of the screen. In normal view it's a tiny but over the middle and in Fullscreen view it goes all to the left and down. How can I fix this?

void Start(){ Screen.lockCursor = true;

 }
 
 void Update () {

     if(Input.GetKeyDown(KeyCode.Escape)){
         Screen.showCursor = !Screen.showCursor;
         Screen.lockCursor = !Screen.lockCursor;
     }
 }
Comment
Add comment · Show 7
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 AlucardJay · Jul 21, 2013 at 03:29 PM 0
Share

These commands do strange things in the Editor, and can break. To test them properly, you have to build it and test the build.

avatar image Nourero · Jul 21, 2013 at 03:42 PM 0
Share

You mean I have to make the game and then see if it works? I need this to work good right away is there a possible way to make this happen?

avatar image robertbu · Jul 21, 2013 at 06:36 PM 0
Share

Just do a PC/$$anonymous$$ac build and run it. Or make a web build, upload it, and then run it. Note you can always 'hide' the cursor and then provide your own cursor-like object and control it any way you like.

avatar image Nourero · Jul 21, 2013 at 07:28 PM 0
Share

Will this make the cursor go to the right spot after I tried building it or will it just show when in "built mode"? And how can I use this cursor-like object your talking about? I'm still kinda new in Unity

avatar image robertbu · Jul 21, 2013 at 07:32 PM 0
Share

You don't describe your problem very well, so I'm not sure how to advise. You can make an object follow the mouse position. Lots of posts on this including code for GUI, GUITextures, and 3D objects. The script that follows the mouse, can also 'disable' itself and place the object at the center of the screen. With the mouse not visible, the user does not know that they are not looking at a real cursor. And this should work in the editor.

Show more comments

2 Replies

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

Answer by IgorAherne · Jul 21, 2013 at 10:12 PM

The thing you would ultimately be trying to achieve is to set the position of the cursor according to the Screen.Width.

Unfortunately it can't be done easily:<

There is a thread on this which can get you going http://answers.unity3d.com/questions/9408/set-cursor-position.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 Tap2Continue · Oct 18, 2014 at 08:24 PM

I created this JavaScript a little while ago. It's really simple actually.

 function Start()
 {
     Screen.lockCursor = true;
     
 }
 
 if(Input.GetKeyDown("esc"))
 {
     Screen.lockCursor = 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

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

18 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

Related Questions

Keep cursor in the middle of the screen? 1 Answer

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