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 aliakbo · Dec 29, 2013 at 09:22 PM · mousecursormouse drag

Unbound Mouse Cursor

Hey,

I wanted to implement a unbound mouse cursor which continues on the other side of the screen once it reaches one side. Exactly how Unity GUI enables you to change the value of variables by dragging it, allowing you to drag you mouse to the side endlessly.

I hope that makes sense. Would appreciate any help.

Thanks

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

Answer by robertbu · Dec 29, 2013 at 10:28 PM

You cannot set the position of the cursor within Unity. To make this happen you would need to link in a call specific to the OS of the target platform (which would require Pro). But you can fake this behavior by hiding the cursor and moving your own object. The following script can be attached to a GUITexture. I found I had to futz with the value a bit and they may need a bit more work.

 #pragma strict
 
 var speed = 0.01;
 private var tr : Transform;
 
 function Start() {
     tr = transform;
     Screen.showCursor = false;
 }
 
 function Update() {
     tr.position.x += Input.GetAxis("Mouse X") * speed;
     tr.position.y += Input.GetAxis("Mouse Y") * speed;
     Debug.Log(tr.position);
     if (tr.position.x >= 1.05)
         tr.position.x = 0.00;
     else if (tr.position.x <= -0.05)
         tr.position.x = 1.00;
     else if (tr.position.y >= 1.05)
         tr.position.y = 0.00;
     else if (tr.position.y <= -0.05)
         tr.position.y = 1.00;

}

Note this cursor does not partially wrap, it just disappears form one side and reappears on the other. Also if you will be raycasting or converting the cursor to world coordinates, a GUITexture uses Viewport coordinates. So you will use Camera.ViewportToWorldPoint() or Camera.ViewportToRay() using the position of this game object to make the conversion.

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

Cursor Disappears In Scene View When Play Mode Is On 2 Answers

Game runs on one screen, cursor wanders onto other screens? 0 Answers

error CS8025: Parsing error 1 Answer

How to make something happen when mouse on side of screen? 1 Answer

Bullet mouse control 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