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
1
Question by Neas · Mar 02, 2014 at 07:21 PM · guicoloralphagui.label

Alpha set by tag in GUI.Label / GUI text behaves strange way

Hello everyone,

I'm having a strange issue. Let's have this simple script, that creates a string that contains 256 letters "a" with different alphas, which are set by tag <color=rrggbbaa>text</color>. You can see in script below that I convert numbers from 0 to 255 to two-digit hexadecimal that represents alpha of each "a" letter.

You would expect long string like "aaaaaaaaaaaaaa... (and so on)" where each "a" is less transparent than the previous one. But instead of that, I'm getting this:

view on result

while testing, I tried to save this string into a txt file and alphas seem to be okay there. Then I tried to write this on screen:

 <color=#ffffff69>1</color> <color=#ffffff5A>2</color> <color=#ffffff3f>3</color>

you can see alpha for "1" is 69, for "2" it's 5a and for "3" it's 3f. Since 5a is between 3f and 69, you would expect transparency for "2" to be between "1"'s and "3"'s, but "2" has the fewest transparency.

Any ideas what's going on? Because I've spent this whole weekend trying to figure this out and am really desparate now.

(btw - behaviour is the same when using GUI text instead of GUI.Label)

Thank you

Here's my script:

 string a;
 
 void Start ()
 {
     a = "";
     for (int i = 0; i < 256; i++)
         a += "<color=#ffffff" + ToTwoDigitHexa(i) + ">a</color>";
 }
 
 void OnGUI()
 {
     GUI.Label(new Rect(0, 0, 1000, 500), a);
 }
 
 string ToTwoDigitHexa(int i)
 {
     string s = i.ToString ("X");
     if (s.Length == 1)
         s = "0" + s;
     
     return s;
 }

a.png (44.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

1 Reply

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

Answer by Scribe · Mar 02, 2014 at 10:59 PM

It is possible you have found a bug as it appears the color parameter can take rgb as capital letters and still work however the alpha hexadecimal number must be lower case for it to be correctly read.

Fortunately you can fix this very easily by doing:

 return s.ToLower();

on line 21. Or change line 17 to:

 string s = i.ToString ("x");

Scribe,

P.S. rather than your if statement to check the length of s you can actually do:

 string s = i.ToString("x2");

and it will automatically return a 2 digit number.

The changes:

 string ToTwoDigitHexa(int i){
     string s = i.ToString("x2");
     return s;
 }
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 Neas · Mar 03, 2014 at 04:51 PM 0
Share

Works perfectly! Thank you very much, you saved me ^^

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

21 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 avatar image avatar image avatar image avatar image

Related Questions

guiTexture color half alpha White? 1 Answer

Change Alpha of Text via Code? 1 Answer

Fading alpha of specific GUI.Label 0 Answers

Non rectangular GUI Mask / Matte? 2 Answers

problem with gui 2 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