• 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 sadowlight123 · May 17, 2017 at 10:08 PM · colorcolor changecolor32

Not exact color

Hello Everyone ,

I am trying to get a color into unity but it gives me a different color.

The color needed : RGBA : (53,140,233,255) Hex : #358CE9 The color given by Unity : RGBA : (34,90,152,255) Hex : #225A98

The code I used :

 Color Blue = new Color32(53,140,233,255);
  fill.color = Blue;


Can anyone please help ? Thank you in advance.

Comment
Add comment · Show 1
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 · May 19, 2017 at 12:02 AM 0
Share

You need to give more information. What is "fill"? Where and when is that code executed? Where do you "check" the color? What's your target platform?

I just tried your code with an UI.Image component. I checked the color in the inspector and also created a screenshot and checked the color in $$anonymous$$S Paint. In each case i get exact the same color that i specified "(53, 140, 233)".

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Shrikky23 · May 17, 2017 at 11:12 PM

You used Color instead of Color32. Either use the Color32 at both the places or use Color

  1. Color = Each color component is a floating point value with a range from 0 to 1

  2. Color32 = Each color component is a byte value with a range from 0 to 255.

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 sadowlight123 · May 18, 2017 at 10:19 AM 0
Share

Thanks for your answer , you are right about needing Color32 on both sides. However , I tried with Color32 on both sides , I still get the same results.

 Color32 Blue = new Color32(53,140,233,255);
 fill.color = Blue;

avatar image Shrikky23 sadowlight123 · May 18, 2017 at 09:28 PM 0
Share

I tested it and it works perfectly for me. I believe two possible issues you might be facing.

  1. fill.color might accept only Color and not Color32 Solution : Color32 blue = new Color32(53, 140, 233, 255); fill.color = (Color)blue;

  2. fill.color is accessed by some other code, find all references in code and make sure nothing else modifies it.

Other solutions: 1. Try this in an empty project and see if you still face that problem. 2. If you do, send me a link to that empty project,

avatar image sadowlight123 Shrikky23 · May 19, 2017 at 01:18 PM 0
Share

Thank you much for your help . I really appreciated it . I found the problem behind this issue . The color of the sprite which I was changing the color was not initially of white color it was of a greyish color . That's why changing it's color gave a different outcome.

avatar image Bunny83 · May 18, 2017 at 11:54 PM 1
Share

That's irrelevant, Color and Color32 have implicit casting operators and convert automatically between each other.

 public static implicit operator Color32(Color c)
 {
     return new Color32((byte)($$anonymous$$athf.Clamp01(c.r) * 255f), (byte)($$anonymous$$athf.Clamp01(c.g) * 255f), (byte)($$anonymous$$athf.Clamp01(c.b) * 255f), (byte)($$anonymous$$athf.Clamp01(c.a) * 255f));
 }
 public static implicit operator Color(Color32 c)
 {
     return new Color((float)c.r / 255f, (float)c.g / 255f, (float)c.b / 255f, (float)c.a / 255f);
 }

So it doesn't matter which struct you use. We don't know what "fill" actually is, but most built-in components will use "Color". So when you specify the color as Color32 it always need to be converted. Though as i said that happens automatically.

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

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

Related Questions

Problem with RGB color on 3D 1 Answer

how to change color in unity scripting overtime?,how to change color gradually with C# 2 Answers

Material doesn't have a color property '_Color' 4 Answers

How can I make objects change color, then fade/return to its original color? 1 Answer

Bugs in built versions 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