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 jmparavicini · Sep 26, 2014 at 08:56 PM · guirotatescale

GUI Scale and Rotate

Hell everyone i Have 2 codes 1 to rotate my guis and the other to scale them. Both work great alone but when i put them together the GUI's just rotate and dont scale here are my Codes

The Scale

 function OnGUI()
 {
         if(GUI.Button(ResizeGUI(Rect(470, 225, 100, 50)), "Settings"))
     {
         
     }
 }
 
 
 function ResizeGUI(_rect : Rect) : Rect
 {
     var FilScreenWidth = _rect.width / 800;
     var rectWidth = FilScreenWidth * Screen.width;
     var FilScreenHeight = _rect.height / 600;
     var rectHeight = FilScreenHeight * Screen.height;
     var rectX = (_rect.x / 800) * Screen.width;
     var rectY = (_rect.y / 600) * Screen.height;
  
     return Rect(rectX,rectY,rectWidth,rectHeight);
 }

The rotation

 private var rotAngle : float = 90;
 private var pivotPoint : Vector2;
 
 pivotPoint = Vector2(Screen.width/2,Screen.height/2);
 GUIUtility.RotateAroundPivot (rotAngle, pivotPoint); 
 if(GUI.Button(ResizeGUI(Rect(470, 225, 100, 50)), "Settings"))
 {
         
 }
 
     
     

If anyone one knows how to make them both work please answer me im so frsutrated D: Thank You

skullbeats1

Comment
Add comment · Show 8
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 jmparavicini · Sep 26, 2014 at 10:09 PM 0
Share

sorry for the codes

avatar image robertbu · Sep 26, 2014 at 10:30 PM 0
Share

Code formatting does not work within or just after a list. I fixed the code formatting for you.

avatar image jmparavicini · Sep 26, 2014 at 10:39 PM 0
Share

im sorry but what did you change??

avatar image jmparavicini · Sep 26, 2014 at 10:40 PM 0
Share

aaah now i got it

avatar image jmparavicini · Sep 26, 2014 at 10:52 PM 0
Share

Pleaseee i need HELP

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by unimechanic · Oct 01, 2014 at 02:27 PM

You can use the GUI.matrix instead to do the scaling and rotation at the same time:

http://docs.unity3d.com/ScriptReference/GUI-matrix.html

You basically assign to it a matrix created with this static method:

http://docs.unity3d.com/ScriptReference/Matrix4x4.TRS.html

Here is an example:

     Matrix4x4 transformation = Matrix4x4.TRS(
         Vector3.zero,
         Quaternion.identity,
         Vector3.one);    
 
     void OnGUI() {
 // We need to assign the GUI matrix before GUI controls are shown.
         GUI.matrix = transformation;
 
         if (GUI.Button(new Rect((Screen.width - 250) / 2, (Screen.height - 100) / 2 - 55, 250, 100), "TRANSFORM GUI")) {
             transformation = Matrix4x4.TRS(
                 new Vector3(-Screen.width * 0.2f, -Screen.height * 0.7f, 0),    // move the GUI a little to fit the transformed controls in the screen
                 Quaternion.Euler(0, 0, 15),    // rotate 15 degrees clockwise around Z, because controls are in XY plane
                 new Vector3(2, 2, 1));    // scale GUI x2 times in X and Y
         }
 
         if (GUI.Button(new Rect((Screen.width - 250) / 2, (Screen.height - 100) / 2 + 55, 250, 100), "NORMALIZE GUI")) {
             transformation = Matrix4x4.TRS(
                 Vector3.zero,
                 Quaternion.identity,
                 Vector3.one);
         }
     }
 
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 jmparavicini · Oct 01, 2014 at 05:45 PM 0
Share

You are th GOD you saved my project and improved it this is so awesome :D

avatar image jmparavicini · Oct 01, 2014 at 08:44 PM 0
Share

1 question do you know how to change this to javascript?

avatar image jmparavicini · Oct 03, 2014 at 01:43 AM 0
Share

Pleasee i need help i used this script and it worked perfectly but the problem is that i used javascript for my whole game and this doesnt work in java i tried everything but it doesnt work please help

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

26 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

GUI Rotate and Scale dont work together 0 Answers

Create 3D GUI Button? 2 Answers

Scaling a GUI element to fit it's contents 0 Answers

Problem With GUI Circle Thickness 1 Answer

Animate GUI Texture 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