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 DFLY · Apr 15, 2013 at 12:03 PM · guicursorlimitmouse movement

How do I limit cursor movement?

On a first person controller, how do limit the movement of my cursor to the middle two thirds of my screen. This is so that the cursor can be more useful in selecting game objects quickly. The first person will continue to rotate but the mouse will not pass the 2/3 screen position.

I don't want to lock the cursor completely or hide it. I just want to restrain it to the middle 2/3 of my screen.

Sorry I have no sample script to start with. I couldn't find a starting point for this one.

Thanks for any help.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
3

Answer by Owen-Reynolds · Apr 15, 2013 at 01:40 PM

Turn off the real cursor. Create a GUITexture of crosshairs or something that looks like a cursor. Use mouse motion to place and move that on the screen, but kept it in range. Ex (not real code, do not use):

 float cursorX=0.5f; // middle of screen. Using 0-1

 float xMv = (Input.mousePosition.x - oldMouse.x)/Screen.width;
 // NOTE: translating 10 pixel mouse move into 0.03% screen move

 cursorX += xMv;
 if(cursorX<0.33f) cursorX=0.33f; // middle 2/3s

 ....

 crosshairs.position = new Vector3(cursorX, cursorY, 0);
Comment
Add comment · Show 2 · 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 DFLY · Apr 15, 2013 at 02:50 PM 0
Share

What is "old$$anonymous$$ouse" ? Also will the new cursor retain its ability to click on things (eg "On$$anonymous$$ouseDown")? How does the GUITexture get the cursor properties (eg click)?

avatar image Owen-Reynolds · Apr 15, 2013 at 03:54 PM 0
Share

On$$anonymous$$ouse's are only for the "real" mouse. Would use Input. to check for clicks. Then screen ray casts to check what you were over. Even with a real mouse, you need a screenCast to, say, target a spot on the ground.

old$$anonymous$$ouse is just program$$anonymous$$g. If you can't directly check mouse movement, store the last mouse position yourself and compute the movement.

If this seems tricky, consider not doing it. $$anonymous$$ost people are used to the mouse going anywhere. A restricted mouse might freak people out.

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

12 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

Related Questions

Custom Cursor with Kinect Wrapper 1 Answer

change the cursor texture when clicked oon the gui button!! 1 Answer

Textfield cursor is missing. 1 Answer

Does GUI.BeginScrollView have a max height? 1 Answer

"Click" a GUI Button using only joystick input 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