Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 Dudledok · Jul 20, 2015 at 08:51 AM · c#cursorlock-cursor

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

The legacy way of locking the cursor would set the cursor locked at the centre of the screen:

 Screen.lockCursor = true;

The new way of locking the cursor is fine apart from the cursor is locked in position wherever it was at the start of the game:

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

How do I move the cursor to the centre of the screen so that players can still click on buttons etc?

Comment
Add comment · Show 4
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 Andres-Fernandez · Jul 20, 2015 at 09:35 AM 0
Share

This is probably a duplicate question (from another one I can't find right now).

If you set the cursor to the center of the screen, why do you need the cursor position to do anything? If it's a 3D button just send a raycast through the center of the screen (check example here), if it's 2D then check if your sprite rect contains the center point of the screen.

avatar image Dudledok · Jul 20, 2015 at 09:40 AM 0
Share

Of course I could do a raycast, but Unity 4.6+ with the new GUI system handles hover and click detection with the cursor on buttons for you, so why do the extra work?

avatar image Andres-Fernandez · Jul 20, 2015 at 11:35 AM 0
Share

Found the question (it was a thread in the forum) here.

If it's GUI then I don't know why you would lock the cursor (how would you click on a topright corner button?).

avatar image Dudledok · Jul 20, 2015 at 11:44 AM 0
Share

I have world space GUI, not screen space.

1 Reply

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

Answer by Andres-Fernandez · Jul 21, 2015 at 06:57 AM

The first 3 entries I got by googling "unity set cursor position" where quite useful. Specially this one.

There's also an asset that apparently does what you need (I havent tried it).

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 Dudledok · Jul 21, 2015 at 12:47 PM 0
Share

I contacted the asset creator and it sounds like it's essentially the same technique (import the windows dll). Thanks, it works. Will have to see how it effects builds across platforms.

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

23 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

Related Questions

Screen.CursorLock problems 2 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Cursor Lockmode only works once? 1 Answer

Artifacts on cursor when using CursorMode.Auto 0 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