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 UnrealIzzy · Sep 04, 2012 at 05:52 PM · mousescreencenter

How do I keep the mouse in center of screen

Hey guys I have been away for a bit but now I am back and wondering How can I keep the mouse courser in the center of the screen?

I have written a script but can't get it to work?

 function Start(){
 
 var mousePos = Input.mousePosition;
 mousePos.x -= Screen.width/2;
 mousePos.y -= Screen.height/2;
 }

I haven't really made a script like this as never needed to so all the help would be great full :D

Thanks -Izzy

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
2
Best Answer

Answer by Eric5h5 · Sep 04, 2012 at 06:08 PM

 Screen.lockCursor = true;

Other than that you can't programmatically set the mouse position; it's read-only.

Comment
Add comment · Show 6 · 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 Eric5h5 · Sep 04, 2012 at 06:24 PM 0
Share

Just get rid of the mousePos stuff; it's not doing anything. As I said, the mouse position is read-only.

avatar image UnrealIzzy · Sep 04, 2012 at 06:27 PM 0
Share

Thanks mate for all your help :D

function Start(){ Screen.lockCursor = true; }

avatar image Joris Janssen · Oct 11, 2014 at 03:22 PM 0
Share

But how do i keep the mouse in the center, this function just puts in in the place it is

avatar image MrSoad · Oct 11, 2014 at 03:28 PM 0
Share

I thought : Screen.lockCursor = true; Hid the mouse pointer completely(well until you press escape)??? Sure I used something different to leave it showing but locked to the center...

avatar image Noxury MrSoad · Dec 26, 2015 at 01:25 PM 0
Share

escape is for quitting the game view to interact with the other unity main windows in terms if your mouse is locked.

avatar image Lungdrache · May 08, 2018 at 06:34 AM 0
Share

well... you can set the position... BUT that you will need to do it for every single Operation system because it is using a library ("using namespaceOfTheDll;") from windows, there is the link to it:

https://answers.unity.com/questions/9408/set-cursor-position.html

avatar image
1

Answer by Unshackled · Jun 26, 2019 at 08:49 PM

 Cursor.lockState = CursorLockMode.Locked; or Cursor.lockState = CursorLockMode.None;
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 OliverBooth · Jan 30, 2020 at 11:57 PM 0
Share

Don't forget to combine with

 Cursor.visible = true; // or false

if it's what you need

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

13 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

Related Questions

How to always have the mouse curser in the center of your game ? 3 Answers

Mouse.position from center of player 1 Answer

Let mouse continue on other side of the screen 1 Answer

GUI.DrawTexture Center on screen 1 Answer

Detect mouse movement when cursor is on edge of screen? 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