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 Juhsi · Dec 21, 2013 at 03:21 PM · mousecursor-customization

Rotate GUI custom mouse cursor?

This is my Script:

 var yourCursor : Texture2D;  // Your cursor texture
 var cursorSizeX : int = 16;  // Your cursor size x
 var cursorSizeY : int = 16;  // Your cursor size y
  
 function Start()
 {
     Screen.showCursor = false;
 }
  
 function OnGUI()
 {
     GUI.DrawTexture (Rect(Event.current.mousePosition.x-cursorSizeX/3, Event.current.mousePosition.y-cursorSizeY/3.5, cursorSizeX, cursorSizeY), yourCursor);
 }

alt text

I want mouse cursor rotate itself always when I Play the game. Could anyone help me :(

Thanks for your kind!

mousecursor_all2.png (2.7 kB)
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
0

Answer by robertbu · Dec 21, 2013 at 05:34 PM

GUI elements can be rotated using GUIUtility.RotateAroundPivot(). Here is some example code. Note I've used a more traditional calculation for x and y. I'm assuming your calculations were so that the cursor position was offset from the middle of the texture. You'll have to adapt the 'pivot' calculation for whatever cursor calculation you use.

 var yourCursor : Texture2D;  // Your cursor texture
 var cursorSizeX : int = 16;  // Your cursor size x
 var cursorSizeY : int = 16;  // Your cursor size y
 
 var speed = 90.0;
 private var angle = 0.0;
  
 function Start()
 {
     Screen.showCursor = false;
 }
 
 function Update() {
     angle += Time.deltaTime * speed;
     angle = angle % 360.0;
 }
  
 function OnGUI()
 {
     var matx = GUI.matrix;
     var x = Event.current.mousePosition.x-cursorSizeX/2.0;
     var y = Event.current.mousePosition.y-cursorSizeY/2.0;
     var pivot = Vector2(x + cursorSizeX / 2.0,y + cursorSizeY / 2.0);
     GUIUtility.RotateAroundPivot(angle, pivot);
     GUI.DrawTexture (Rect(x, y, cursorSizeX, cursorSizeY), yourCursor);
     GUI.matrix = matx;
 }


Comment
Add comment · Show 4 · 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 Juhsi · Dec 21, 2013 at 06:12 PM 0
Share

alt text

Hi, thanks!!! Your script is working!!!

But how can I change the rotate pivot to ↑ picture's rotate direction (X,Z)? Could you $$anonymous$$ch me (:

5.png (3.5 kB)
avatar image robertbu · Dec 21, 2013 at 06:18 PM 0
Share

Your picture did not post. I need to see what you are talking about. Posting the cursor itself would also be helpful.

avatar image Juhsi · Dec 21, 2013 at 06:45 PM 0
Share

https://www.dropbox.com/s/0vojog2fx6s85iz/5.png

sorry.

This is my picture ><

avatar image robertbu · Dec 21, 2013 at 06:45 PM 0
Share

Ahhhh. I've never seen code for this kind of problem. You might be able to directly manipulate the GUI.matrix to solve this problem, but a more typical solution would be to create a series of images and cycle through the images...like GIFs use to create animations. Here is a bit of starter code to demonstrate:

 #pragma strict
 
 var images : Texture[];
 var fps = 10.0;              // Frames per second
 var cursorSizeX : int = 16;  // Your cursor size x
 var cursorSizeY : int = 16;  // Your cursor size y
 private var index = 0;
 
 function Update () {
     index = (Time.time * fps) % images.Length;
 }
 
 function OnGUI() {
     GUI.DrawTexture (Rect(Event.current.mousePosition.x-cursorSizeX/3, Event.current.mousePosition.y-cursorSizeY/3.5, cursorSizeX, cursorSizeY), images[index]);
 }

You need to set the size of 'images' in the inspector and then drag and drop your frames into the slots.

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

change mouse cursor on mouseover 3 Answers

HIdden cursor slider issue 1 Answer

Offseting position of guiText in relation to mouse 0 Answers

smoothing again 4 Answers

Rotating object with GUI Elements present 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