Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 fitzy.89 · Sep 30, 2011 at 07:46 AM · rotationguinot working

GUIUtility.RotateAroundPivot isn't working

I'm having trouble trying to get my GUI object to rotate around its central point.

its meant to be an arrow that circles around a mini-map pointing towards the objective.

I'm using Unity 3.4.0f5

The arrow shows and is positioned correctly but it just wont rotate.

"rotAngle = GameObject.Find("ObjectiveWatch").GetComponent(WatchObjective).direction;" is fed by a Euler Angle.


 var minimapArrow : Texture2D;
 
 private var rotAngle : float = 0;
 
 private var pivotPoint : Vector2;
 
 function OnGUI() {
 
     GUI.depth=149;
 
     GUI.Label (Rect ((Screen.width) - 226, (Screen.height * 0.20) + 7, 202, 202), minimapArrow);
 
     
 
     rotAngle = GameObject.Find("ObjectiveWatch").GetComponent(WatchObjective).direction;
 
     //Debug.Log("direction = " + rotAngle);
 
     pivotPoint = Vector2((Screen.width) - 327, (Screen.height * 0.20) + 108);
 
     GUIUtility.RotateAroundPivot (rotAngle, pivotPoint);
 
 }
Comment
Add comment · Show 5
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 LeeGibson · Sep 30, 2011 at 08:12 AM 0
Share

i tried that a few days ago, but it didn't work for me either, no matter what code i tried. the way i see it .rota$$anonymous$$roundpivot is for a singular, not a constant rotation.

one way around that is to put the texture you want to rotate on a mesh and rotate that.

avatar image fitzy.89 · Sep 30, 2011 at 08:17 AM 0
Share

but it's not really like some sort of flowing rotation.. it's one adjustment each frame.. the unity scripts reference does the same thing. in fact this was almost a copy from there :\

avatar image fitzy.89 · Sep 30, 2011 at 09:35 AM 0
Share

fixed it!!


var $$anonymous$$imapArrow : Texture2D;

private var rotAngle : float;

private var pivotPoint : Vector2;

function OnGUI() {

 var matrixBackup:$$anonymous$$atrix4x4  = GUI.matrix;

 rotAngle = GameObject.Find("ObjectiveWatch").GetComponent(WatchObjective).direction;

 pivotPoint = Vector2((Screen.width) - 125, (Screen.height * 0.20) + 100);

 GUIUtility.RotateAroundPivot (rotAngle, pivotPoint);

 GUI.depth=149;

 var myRect:Rect = Rect((Screen.width) - 223, (Screen.height * 0.20) + 4, 202, 202);

 GUI.DrawTexture (myRect, $$anonymous$$imapArrow);

 GUI.matrix = matrixBackup;

}

avatar image LeeGibson · Sep 30, 2011 at 09:54 AM 0
Share

congratulations!

avatar image fitzy.89 · Sep 30, 2011 at 09:56 AM 0
Share

thanks to you and your link lee

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Tommynator · Sep 30, 2011 at 09:39 AM

A classic mistake, you have to draw you arrow image AFTER changing the rotation matrix of the GUI. Make sure to set the matrix to identity after the operation.

//do the rotation
GUIUtility.RotateAroundPivot(rotAngle, pivotPoint);
//draw image
GUI.DrawLabel(Rect(Screen.width - 226, (Screen.height * 0.20) + 7, 202, 202), minimapArrow);
//reset
GUI.matrix = Matrix4x4.identity;

Consider using DrawTexture() instead of Label() as it's a bit more efficient if you just want to draw a Texture2D. (You have to set the dimensions manually though as it's not keeping the aspect ratio automatically)

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 fitzy.89 · Sep 30, 2011 at 09:55 AM 0
Share

thank you, yeah i found the solution from Lee Gibsons response, and realised that drawing before rotating was my mistake, but it is all fixed now =D

again, thank you

avatar image
1

Answer by LeeGibson · Sep 30, 2011 at 08:27 AM

i find it also hard to believe that it's not possible to rotate a gui texture.

maybe this might help: http://forum.unity3d.com/threads/36951-Rotate-A-GUI-SPrite-element-texture

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 Bunny83 · Sep 30, 2011 at 11:49 AM 0
Share

I've converted your comment into an answer ;)

avatar image LeeGibson · Sep 30, 2011 at 12:02 PM 0
Share

thank you :)

avatar image
0

Answer by fitzy.89 · Sep 30, 2011 at 11:41 AM

Thank you Lee Gibson!!

thanks to you i managed to get a script that worked for rotating the minimaps arrow with ease!!

the most fiddly part is positioning the pivot point.


 var minimapArrow : Texture2D;
 
 private var rotAngle : float;
 
 private var pivotPoint : Vector2;
 
 
 
 function OnGUI() {
 
     var matrixBackup:Matrix4x4  = GUI.matrix;
 
     rotAngle = GameObject.Find("ObjectiveWatch").GetComponent(WatchObjective).direction;
 
     pivotPoint = Vector2((Screen.width) - 125, (Screen.height * 0.20) + 100);
 
     GUIUtility.RotateAroundPivot (rotAngle, pivotPoint);
 
     GUI.depth=149;
 
     var myRect:Rect = Rect((Screen.width) - 223, (Screen.height * 0.20) + 4, 202, 202);
 
     GUI.DrawTexture (myRect, minimapArrow);
 
     GUI.matrix = matrixBackup;
 
 }
Comment
Add comment · Show 3 · 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 LeeGibson · Sep 30, 2011 at 12:01 PM 0
Share

very glad i could help! ^_^

avatar image fitzy.89 · Sep 30, 2011 at 12:05 PM 0
Share

lol its funny because i posted up this answer before any of the other things were up but it has only shown up now =D

avatar image Bunny83 · Sep 30, 2011 at 12:42 PM 0
Share

@fitzy.89: That's because you have not enough karma. Afaik you need at least 15 karma to directly post questions / answers. It has been implemented to prevent spammers from registering fake accounts. All things posted from people below 15 karma will end up in the moderation queue. Every user with 1000+ karma can allow those posts but we have to find the time ;)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Limiting object rotation using GUI.Buttons? 1 Answer

GUI Button not working...but the the script is correct... 2 Answers

Bind horizontal scrollbar to camera control 1 Answer

how can i flip my scoredisplay var guitext so that it appears upside down? 0 Answers

Why isn't my Gui showing up at all? 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