• 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
2
Question by katie88 · Jul 29, 2012 at 08:32 PM · scaleguitexturescreen size

Scale GUI Texture to current screen size?

I'm making a 2D game for Android. Currently the game looks fine when the Game View is set to 800 x 480. But I am trying to get my GUI Textures to scale up or down according to the screen size.

My GUI textures are all 800 x 480 in size.

In the Unity Inspector, the Pixel Insets for my GUI Textures are set to X = -400, Y = -240.

Here's what I have as far as code:

 var player1WinsGUI : GUITexture;
 
 function Update(){
 //Scaling textures
 player1WinsGUI.transform.localScale = Vector3(0, 0, 0);
 }

I am trying to come up with a formula that will scale the texture to the current screen resolution, which I know I can get using Screen.width and Screen.height. My guess was:

 Vector3(Screen.height/800, Screen.width/480, 0);


But that results in positive values, which make the texture way too large.

1) Would this have anything to do with the way I have the Pixel Inset properties set in the inspector?

2) Does anyone know which units the Vector3 parameters are in? Is it pixels, percentage or something else?

3) Any ideas on how to do this the way I've set it up? Or is there a simpler way?

Thank you in advance!

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

Answer by Eric5h5 · Jul 29, 2012 at 08:44 PM

Set all pixel inset values to 0, and just set the scale to x=1, y=1 (and position to .5, .5). Then it will always use the entire screen regardless of resolution. GUIText and GUITextures use viewport space.

Comment
Add comment · Show 9 · 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 katie88 · Jul 29, 2012 at 09:06 PM 0
Share

Aahh thank you so much, Eric5h5, that works perfectly! I'm trying to give you an up vote, but Answers is saying I don't have permission even though I'm logged in. :( I will keep trying.

In case anyone wants to reference what my Inspector now looks like:

Under "Transform": Position: (0.5, 0.5, 0) Rotation: (0, 0, 0) Scale: (1, 1, 1)

Under "GUI Texture": All number values set to 0. (I also had set the "Width" and "Height" under Pixel Inset to 800 x 480, which was adding to the problem)

It works great!! Thank you again!

avatar image Eric5h5 · Jul 29, 2012 at 09:42 PM 2
Share

You need a certain amount of karma before you can upvote, which you should have enough of now.

avatar image ShivaFooL · Sep 22, 2012 at 06:08 PM 0
Share

Thanks. I can't vote yet, but solved one problem.

avatar image ayaz alavi · Jul 27, 2013 at 01:30 AM 0
Share

Cant make it work to auto fit atleast in Editor Player. Will it work on device? When I set scale to 1 for x and y then image became outside the screen.

avatar image Eric5h5 · Jul 27, 2013 at 01:31 AM 0
Share

Please read my entire answer.

Show more comments
avatar image
-1

Answer by ddkclaudio · May 31, 2014 at 10:13 PM

hello this solved almost all my problems, however I have an image with 88x179px, but when I do that and care she is cool but when it fits a screen unless the image is very pixelated.

appreciate the help

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

11 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

Related Questions

[CLOSED] Pixel Inset ---> transform scale convert 0 Answers

World Space UI Scale To Fit Screen At DIfferent Aspect Ratios 1 Answer

Scaling a GUITexture using iTween 1 Answer

Scale menu to fit webplayer with fullscreen on/off 0 Answers

Change UI based off of screen size 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