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 /
avatar image
0
Question by RenatoB · Jun 10, 2011 at 01:17 PM · decimalrgb

Convert RGB to decimal

I need to know the values of the RGB color in decimal mode. Anyone knows the equation?(no script) Thanks.

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 RenatoB · Jun 10, 2011 at 01:27 PM 0
Share

Thanks for the answer, macfanpro. I´m using setcolor to change a button color, using decimal values. I need to restore the original color of this button when the mouse exit, but I´ve only the rgb value and I need to put this values in decimal too.

avatar image RenatoB · Jun 10, 2011 at 01:46 PM 0
Share

Thank you guys.

5 Replies

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

Answer by equalsequals · Jun 10, 2011 at 01:27 PM

If by decimal mode you mean a 4 dimensional float ranging between 0 and 1 for R, G, B and A values then:

RGB(A) is a 256-bit color, so by that logic then any channel can be 0 to 255. Knowing this, we can say a color is 255(r),127(g),25(b),255(a) you can do this:

 Color color = new Color(r/255.0F,g/255.0F,b/255.0F,a/255.0F);

The equation is very basic math. 0 is 0 and 255 is 1, you simply take the number of bits in that channel and divide it by the maximum (255) to find it's normalized (decimal) value.

EDIT - Note: As Mike mentioned, don't divide by an int and expect to get a float. Always divide by a float to get decimal values.

Hope that helps

==

Comment
Add comment · Show 4 · 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 Mike 3 · Jun 10, 2011 at 01:28 PM 1
Share

Just a small point - you want to divide by 255.0, not 255, otherwise you'll end up with all zeroes

avatar image equalsequals · Jun 10, 2011 at 01:38 PM 0
Share

Right - I obviously have not had my coffee yet. Had I ran it I would have noticed the implicit float-to-int problem. Thanks!

avatar image flaviusxvii · Jun 10, 2011 at 05:10 PM 1
Share

I would never have guess this is what RenatoB was asking. You're like some kind of noob-whisperer!

avatar image equalsequals · Jun 10, 2011 at 05:22 PM 0
Share

I work with a lot of UI designers, 3D artists and programmers. One thing you learn in a diplomatic role like Tech Artist is that there is a different name for everything across all trades, and your job is to understand them all. Typically UI designers know RGB as 255, and programmers know it as normalized data, so knowing this it was the logical assumption.

avatar image
6

Answer by diOriginal · Aug 07, 2012 at 05:16 PM

You can use the following function.

http://docs.unity3d.com/Documentation/ScriptReference/Color32-operator_Color.html

exampel for red: private Color32 ColorRed = new Color32(255, 0, 0, 255);

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 Jeremy Hindle · Feb 10, 2013 at 04:19 PM 0
Share

What I was looking for, Thank you.

avatar image
2

Answer by Sylker · Dec 07, 2013 at 06:03 AM

Or you can use this:

http://www.corecoding.com/utilities/rgb-or-hex-to-float.php

and totally skip equations and scripts.

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

Answer by ckfinite · Jun 10, 2011 at 01:20 PM

Well, there is really no way to do what you say without script. What is decimal mode exactly? Do you want to get one of the r g or b values?

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

Answer by lst · Feb 26, 2016 at 08:19 PM

Also there is a web converter http://www.corecoding.com/utilities/rgb-or-hex-to-float.php

after can use directly

Color color = new Color(0,5f,0.5f,0.5f, 1f); // values from that converter enter here.

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 Bunny83 · Feb 29, 2016 at 03:43 AM 0
Share

http://answers.unity3d.com/questions/128407/convert-rgb-to-decimal.html#answer-591472

Looks familiar doesn't it?

You posted the same link as Sylker posted over two years ago. So your answer didn't add anything.

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

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

High precision numbers 2 Answers

C# public decimal variable not showing up in inspector 2 Answers

Convert RGB heightmap to greyscale 2 Answers

Round to decimals 2 Answers

Change InputField decimal mark 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