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 /
  • Help Room /
avatar image
0
Question by ActivePrime · Feb 08, 2016 at 05:20 PM · uibuttonresolution

Problem scalling UI Buttons Generated on Runtime

Attached is the screenshot from mobile, Setting screenshot from Unity and the code snippet to generate the UI button.

My problem is of scaling the UI generated buttons according to the resolution of different devices, I am breaking my head with every wall since 7 hours but no good, i found different tutorials but couldn't solve my specific problem.

It is shown in the screenshot of unity the size showing on 16:10 ratio is quite large that is going out off screen but i am unable to get why why why it is showing so small on the device.

Please note that my app is live and i am looking for an urgent response.

alt text

 using UnityEngine;
 using System.Collections;
 
 public class SkinImplementer : MonoBehaviour {
 
     public GUISkin MainSkin = null;
     public string buttonTitle = string.Empty;
 
     public Texture2D playButtonImage = null;
     public Texture2D LeaderboardButtonImage = null;
     public Texture2D AchievementButtonImage = null;
     public Texture2D CreditsButtonImage = null;
     public Texture2D PlayAgainButtonImage = null;
 
 
     void OnGUI(){
         GUI.skin = MainSkin;
 
         if (Application.loadedLevelName == "TapBallStart") {
             if (GUI.Button (new Rect (Screen.width / 2 - 150, Screen.height / 2 - 60, 300, 120), playButtonImage)) {
                 Application.LoadLevel ("TapBall");
 
             }
         }    else if (Application.loadedLevelName == "TapBallGameOver") {
             if (GUI.Button (new Rect (Screen.width / 2 - 150, Screen.height / 2 - 60, 300, 120), PlayAgainButtonImage)) {
                 Application.LoadLevel ("TapBall");
             }
             
         }
         if (GUI.Button(new Rect (Screen.width/2, Screen.height/2+60, 225, 225), LeaderboardButtonImage)) {
             //show leaderboard script
             Social.ShowLeaderboardUI();
         }
 
         if (GUI.Button(new Rect (Screen.width/2-225, Screen.height/2+60, 225, 225), AchievementButtonImage)) {
             //show achievement script
             Social.ShowAchievementsUI();
         }
 
         if (GUI.Button (new Rect (Screen.width / 2 -105, Screen.height / 2 + 285, 210, 120), CreditsButtonImage)) {
             Application.LoadLevel ("Credit");
         }
     }
 }
 
unity-setting.jpg (102.9 kB)
screenshot-2016-02-05-22-12-33.png (408.0 kB)
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by hexagonius · Feb 08, 2016 at 09:31 PM

The scale mode on your canvas scaler is wrong. use scale with screen size, set your reference pixel width and height (size you designed the sprites for) and the slider to how the UI should react on different aspects.

http://docs.unity3d.com/Manual/script-CanvasScaler.html

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 ActivePrime · Feb 09, 2016 at 06:28 PM 0
Share

Thanks for your reply, I looked at the documentation sent that i read already and applied different option before putting up the question for support. i have changed it to "Scale with Screen Size" as guided all is going well "On SCREEN in UNITY" but the problem still persist for the menu in question that was generated by the c# code shared already.

Adjacent is the screenshot from mobile and guess what, c# generated menu is in place and nothing changed to it but other things like game/company and social logos are disappeared those were available in game view of unity on all aspect ratios including the one used by my mobile.

alt text

untitled-1.jpg (432.2 kB)
avatar image
0

Answer by ActivePrime · Feb 12, 2016 at 11:40 AM

@hexagonius any luck?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Get value in button OnClick() 1 Answer

Possible to long/short press a UI button - Phone device 0 Answers

How do I control my car with UI buttons? 0 Answers

UI Buttons Will Not Work After Building,UI Buttons do not work 0 Answers

UI Resizing out of screen 0 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