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 pigi5 · Jan 22, 2011 at 12:09 AM · guirotatearoundpivot

GUI rotation not working

I am trying to rotate a compass in the top corner of my screen, and I have writen a script for it, however incorrect it maybe. It is drawing eveything correctly and there are no syntax errors, but instead of rotating around the centerpoint of the compass, the compass is just moving up and down (based on my direction, the max down it goes corresponds to when I am turning right and all the way around, and the max up it goes corresponds to when I am turning left and all the way around: the the center y position seems to be right when I start, so 0 degrees). Why is this? Here is my script:

var camera1 : Camera; var camera2 : Camera; var camera3 : Camera; var openButton : Texture2D; var closeButton : Texture2D; var mapMarker : Texture2D; var compass : Texture2D; var mapSkin : GUISkin; var characterTransform : Transform; var screenPos : Vector3; var playerDirection : float; var pivotPoint = Vector2(66.5,386.5);

function Update () { if (camera2.enabled) { screenPos = camera.WorldToScreenPoint (characterTransform.position); } }

function OnGUI() { GUI.skin = mapSkin; if (camera1.enabled) { playerDirection = characterTransform.transform.rotation.y; GUIUtility.RotateAroundPivot(playerDirection,pivotPoint);
GUI.DrawTexture(Rect(1145,3,290,290),compass); GUI.DrawTexture(Rect(1275,133,30,30),mapMarker); if (GUI.Button(new Rect(1115,270,50,50),openButton)) { camera1.enabled = false; camera2.enabled = true; camera3.enabled = false; } } if (camera2.enabled) { GUI.DrawTexture(Rect(screenPos.x - 12,730 - screenPos.y,20,20),mapMarker); if (GUI.Button(new Rect(1250,100,100,100),closeButton)) { camera1.enabled = true; camera2.enabled = false; camera3.enabled = true; } } }

function Start () { camera2.enabled = false; }

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

Answer by yoyo · Jan 22, 2011 at 05:35 AM

Your pivot point is a long way away from the rectangle in which you're drawing the compass. You need to set the pivot to the center of the rectangle, something like (1290, 148).

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 pigi5 · Jan 22, 2011 at 04:46 PM 0
Share

Thanks. Also, it turns out that with a transform variable, transform.rotation uses Quaternion ins$$anonymous$$d of degrees, so I needed to use transform.eulerAngles. but my pivot point was way off too, and yours was perfectly in the center of my graphic. Thanks!

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

No one has followed this question yet.

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Setting Scroll View Width GUILayout 1 Answer

Is it possible to link character skill lists to a GUI, and if so, how? 3 Answers

Windows Application 2 Answers

Better control over the GUI components? 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