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 Jopan · Sep 21, 2013 at 07:56 AM · androidguibuttonscalingmatrix

Scaling the GUI matrix in mobile causes buttons to be off

Hello, I am making a mobile app using unity's GUI exclusively. I am targeting android. I want the app to work on any size screen, so I am scaling GUI.matrix to make the GUI appear the same on any resolution.

 private float originalWidth = 1024.0f;
 private float originalHeight = 600.0f;
 
 void Start ()
 {
      scale.x = Screen.width / originalWidth;
      scale.y = Screen.height / originalHeight;
      scale.z = 1.0f;
 }
 
 void OnGUI ()
 {
      GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, scale);
 
      // GUI Code
 }

This worked great. Then I noticed that when I tried to touch the buttons that I couldn't. I believe the buttons only work when I push the area that the buttons are before they are scaled into place.

After searching a bit I found a bit of a hack that worked pretty good, but only for mouse clicks.

 void OnGUI ()
 {
      GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, scale);

     // The hack
     if ( Event.current.type == EventType.Layout && Event.current.clickCount == 0 )
     {
          GUI.matrix = Matrix4x4.identity;
     }
   
     // GUI Code
 }

This didn't work for touch, however. I don't really understand how the "hack" worked, but I tried changing it to this.

      if ( Event.current.type == EventType.Layout && Input.touchCount == 0 )
      {
           GUI.matrix = Matrix4x4.identity;
      }

That had no effect, however.

So my question is basically, how can I get the scaling to work properly on android and also be able to properly click/touch the buttons?

I am using GUILayout by the way. Not sure if not using it would solve anything.

Comment
Add comment · Show 1
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 Philomorph · Mar 17, 2015 at 11:30 PM 0
Share

Did you ever find a solution to this? I'm actually seeing this same issue in my project using the new UI elements. $$anonymous$$y proect was started in Unity 4.6 where one specific user was seeing the problem. Now I've moved up to Unity 5 and he's still seeing the issue!

He's on a "Oneplus One" phone. I have another tester on the same phone who doesn't see the problem.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by alexanderlarsen · Aug 06, 2020 at 09:37 AM

@Jopan Hello from 2020! Did you find a solution to this?

Comment
Add comment · 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

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

17 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

Related Questions

GUI Button for Android 1 Answer

Alternative to GetButtonUp for GUI.Button 1 Answer

GUI scaling on mobile 1 Answer

Android Button Screen 1 Answer

Why i cant press(use) joystick and gui button at the same time ???? 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