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 Osca Zimmerman · Mar 31, 2011 at 08:35 PM · guitexturescalebox

GUI box texture resizes itself

I have a menu based game, where each menu screen has a background image. My game uses 640 x 480 resolution and the art is in resource folder in this size. When I load the game, the background art (variable GUI_BG) resizes itself to 473 x 475 and goes into the center in the background! All other UI elements like buttons are placed and sized correctly though. I have added the bg image through the inspector.

This is my first try with Unity and I'm not an experienced programmer so its likely I have misunderstood something :)

var GUI_BG : Texture2D; var newSkin : GUISkin;

function Screen() { //layout start GUI.BeginGroup (new Rect(20, 20, 640, 480));

 //the menu background box with image
 GUI.Box(Rect(0, 0, 640, 480),GUI_BG);
 var script = GetComponent("Screen"); 
 // Back to main menu button
 if(GUI.Button(Rect(35, 40, 180, 30), "Back to Main menu")) {
     var script2 = GetComponent("MainMenu"); 
     script2.enabled = true;
     script.enabled = false;
 }
 GUI.EndGroup(); 

}

Not sure if related to the issue, but I Have an additional UI box called "bottom menu" that takes around 200px of the screen and is partly on top of the main screen. The scaled image does go over this box though as designed. The resizing only effects horizontal size.

function OnGUI () {        
    Screen();
    BottomMenu.bottomMenu(BottomMenu.whichMenu());
}

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

Answer by AngryOldMan · Mar 31, 2011 at 08:57 PM

function Screen() {
    //layout start
    GUI.BeginGroup (new Rect(20, 20, 640, 480));

should be

function Screen() {
    //layout start
    GUI.BeginGroup (new Rect(0, 0, 640, 480));

this is your "drawing" area for your GUI, the four digits after new Rect are, position x position y, size x, size y. This is relative to the top corner. If you're having scaling issues you need something like ScaleMode.StretchToFill which works for GUI.DrawTexture eg

GUI.DrawTexture (Rect (0,0,640,480),GUI_BG, ScaleMode.StretchToFill);
Comment
Add comment · Show 2 · 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 Osca Zimmerman · Mar 31, 2011 at 09:03 PM 0
Share

I tried changing 20->0, all it does is moves the group to the top left corner (I used 20, 20 to have some air there).

After fighting with this a while I went to the DrawTexture solution you proposed, which worked. No idea though why the BG image auto-resizes itself horizontally.

Thx!

avatar image AngryOldMan · Mar 31, 2011 at 09:38 PM 0
Share

you need to make the group smaller if your screen size is 640 by 480 and you have taken 20 pixels off the top and side. So 600 by 440 will give you that 20 pixel boarder

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

Texture Size doesn't match collider size 0 Answers

How to maintain high resolution custom background images for GUI elements on different screen sizes? 0 Answers

proper inventory system issue.. 1 Answer

I have a GUI element that highlights an onscreen object with a circle. This circle needs to scale according to the object's distance from the camera in order to compensate for perspective, but the thickness of the circle needs to stay the same. 0 Answers

Remove GUI Box Drawing? 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