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 tamsii · Jul 22, 2014 at 09:44 AM · c#gui

Scaled GUI

I have a GUI Texture, when I click on it a GUI Button should appear. It all worked well until I put the "scaled code". I found the scaling part on some other question.

How can I make it work? Here's my code.

 private bool displayMusic = false;
 public GUITexture myTexture;
 private Vector3 scale;
 int originalWidth = 640;
 int originalHeight = 400;


 void OnGUI() 
 {
     scale.x = Screen.width/originalWidth; // calculate hor scale
     scale.y = Screen.height/originalHeight; // calculate vert scale
     scale.z = 1;
     Matrix4x4 svMat = GUI.matrix;
     GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, scale);

     if (Input.GetMouseButton (0) && myTexture.HitTest (Input.mousePosition)) 
     {
         displayMusic=true;                    
     }

     if (displayMusic) 
     { 
         if (AudioListener.volume != 0 && GUI.Button (new Rect(1005,130,135,30), "Sound effects: ON"))
         {
             AudioListener.volume = 0;
             displayMusic=false;
         }
         else 

         if (AudioListener.volume == 0  && GUI.Button (new Rect(1005,130,135,30), "Sound effects: OFF"))
         {
             AudioListener.volume = 100;
             displayMusic=false;
         }

     }
     GUI.matrix = svMat; 
 
 }

}

Comment
Add comment · Show 2
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 VioKyma · Jul 22, 2014 at 10:32 AM 0
Share

When you say it doesn't work, I'm not quite sure what you mean. Does it generate an error? Does it not display at all? Or does it display strangely?

avatar image tamsii · Jul 22, 2014 at 10:37 AM 0
Share

When I click on the GUI Texture it doesn't happen anything, but it should show the GUI Button.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Graham-Dunnett · Jul 22, 2014 at 02:07 PM

Matrix4x4.TRS() changes the way that rendering happens. It does not change the way that input touch and mouse position get computed. Don't use this approach to resize your GUI elements.

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 tamsii · Jul 23, 2014 at 06:53 AM 0
Share

Well.. Then, how can I make my GUI elements don't change position on different resolutions?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

How can I have a 1st person and 3rd person camera movement option for the player? 1 Answer

Drawing several BeginArea inside a BeginScrollview (GUILayout) produces an unexpected behaviour 1 Answer

How to get correct zooming in GUI.DrawTexture? 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