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 paulaceccon · Jan 09, 2013 at 06:09 PM · guisizeguitexturetexure

Texture height based on it width.

Hi, I have a GUITexture which content changes time by time. All texture defined have the same width, but the height may change. Until now, I have something like this:

 void Start (){
     messageSize = new Vector2(Screen.width/3, Screen.height/5);        
     messageGO = new GameObject();
     messageGO.transform.position = Vector3.zero;
     messageGO.transform.localScale = Vector3.zero;
     messageGUI = messageGO.AddComponent<GUITexture>();
     messageGUI.name = "Message";
 }


 void Update(){    
     if(displayMessage){
        timer += Time.deltaTime;
         if(timer <= time){
            messageGUI.enabled = true;
            messageGUI.texture = message;
            messageGUI.pixelInset = new Rect(position.x,position.y,messageSize.x,  
                                    messageSize.y);                                                          
         }
         else{
             messageGUI.enabled = false;    
             displayMessage = false;
             timer = 0f;
             currentMessage ++;
         }
     }
 } 

So, I was wondering if there is a way to make this messageSize.y adjusts dynamically. Something like we do in HTML, passing width = messageSize.x and messageSize.y = '*'.

What I have so far are fix messageSize. I would like that the messageSize.y change to have the necessary size, like we can do in HTML with the parameter height = '*'.

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 Wolfram · Jan 10, 2013 at 12:09 PM 0
Share

Either I don't understand your problem, or simply call the two lines you posted every time your texture changes (plus updating messageSize).

And please give more information. For example, who computes/updates messageSize? Are the textures "message" created via script, or referenced, or where do they come from?

avatar image paulaceccon · Jan 10, 2013 at 12:35 PM 0
Share

Edited. (:

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Wolfram · Jan 10, 2013 at 01:41 PM

If you want to keep the width constant, and at the same time preserve the texture's aspect ratio, you can do this:

 float messageNewHeight=messageSize.x*message.height/message.width;
 messageGUI.pixelInset = new Rect(position.x,position.y,messageSize.x,  
                                messageNewHeight);

If you also need to adjust position.y, it gets a bit more complicated. Just tell me if you need that, and if so, how/where do you want to align your texture (bottom/center/top of texture).

Comment
Add comment · Show 8 · 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 paulaceccon · Jan 10, 2013 at 04:15 PM 0
Share

Hey, I don't need to adjust the position. At least not now... (:

Thank you a lot!

avatar image paulaceccon · Jan 10, 2013 at 04:17 PM 0
Share

Oh man, it was not hard! It was just... I don't know how you guys call these in english, but in portuguese is "Regra de Três". Thaaaanks!

avatar image Wolfram · Jan 10, 2013 at 04:20 PM 0
Share

Exactly that: "rule of three", or "Dreisatz" in German.

avatar image paulaceccon · Jan 11, 2013 at 12:00 PM 0
Share

(: Thks!!

avatar image Wolfram · Jan 12, 2013 at 08:25 PM 1
Share

Ah, O$$anonymous$$, then the problem was power of twos. Per default, all imported textures are fitted into a power of two width and height, because the graphics card is optimized for that, and mipmapping won't work in Unity otherwise. Setting it to "GUI" disables this scaling. You can also disable it by using the "Advanced" option, but GUI is fine - since you are using it as such.

Show more comments

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Reduce Draw call for Multiple GUI Textures with same Texture 1 Answer

Move GUI elements. 0 Answers

GUITexture Button? 1 Answer

GUI Transparency Changing automatically 2 Answers

Write a Shader for GUI (GUITexture or scripted GUI) 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