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 bekiryanik · Sep 22, 2014 at 02:10 PM · gameobjectcolorhsbcolor

How to Use HSBColor script?

Hello,

I am trying to change the color of the object(it is a child object) via this script in this link: HSBColor Wiki but i couldn't call what i need to call to change color of my object in that script. I've just did that in my own script:

 public HSBColor hsbcolor;

 void Example()
      {
       this.transform.FindChild ("Graphics").GetComponent<SpriteRenderer> ().color = new HSBColor(new Color(1f, 2f, 3f, 1f);
      }

Something is wrong in this code, i couldn't find what it is. I get error when i use this.

How can i call HSBColor function from script in link? Or what should i add after equal sign?

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

Answer by robertbu · Sep 22, 2014 at 02:16 PM

You have a few issues here. I'm guessing that you want to specify an HSBColor and assign the result to color the sprite. So you first have to produce an HSBColor struct with the right values, then you have to convert the result to a Color to be able to assign it. Untested:

   transform.FindChild ("Graphics").GetComponent<SpriteRenderer> ().color = HSBColor.ToColor(new HSBColor(0.333,0.0f,0.5f,0.5f,1.0f));
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 bekiryanik · Sep 22, 2014 at 02:36 PM 0
Share

Thank you so much! That is exactly what i need!

avatar image bekiryanik · Sep 22, 2014 at 04:46 PM 0
Share

roberthu, like you said, i need to produce a HSBColor struct with the right values but how? If you know how to do that, can you tell me, please?

Right now, i can't get the the color from hsb cause of the reason that you said i guess.

avatar image robertbu · Sep 22, 2014 at 05:02 PM 0
Share

This:

 new HSBColor(0.5,0.5f,0.5f,1.0f)

...produces the HSBColor struct. But I was wrong about the first value being 0 to 360. It is 0 to 1 like all the others. A quick mapping:

  • 0 - red

  • 0.333 - green

  • 0.666 - blue

avatar image bekiryanik · Sep 22, 2014 at 05:25 PM 0
Share

One more question. I tried to set colors with HSBColor but it was like setting color with this code:

 transform.FindChild ("Graphics").GetComponent<SpriteRenderer> ().color = new Color(0.4f,0.1f,0,0.7f);



No differences. Is this HSBColor not working?

avatar image robertbu · Sep 22, 2014 at 07:35 PM 0
Share

So the HSB settings for bright red would be (0,1,1,1). The RGB settings for bright red would be (1,0,0,1). If you are getting the same values, there is something wrong. I just ran a quick test of the HSBColor class, and everything worked correctly. In order to debug your problem, I need to see your exact code and have a description of 1) what you are trying to do, 2) your expectation, and 3) what is happening.

Show more comments
avatar image
0

Answer by Julian_Nementic · Sep 22, 2014 at 03:31 PM

When you dont need HSB, than try this:

         transform.FindChild ("Graphics").GetComponent<SpriteRenderer> ().color = new Color32(40,10,30,100);
         
         //or this
         
         transform.FindChild ("Graphics").GetComponent<SpriteRenderer> ().color = new Color(0.4f,0.1f,0,0.7f);

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 bekiryanik · Sep 22, 2014 at 04:44 PM 0
Share

Thanks! :)

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to fill the inside volume of a 3D mesh with color? 0 Answers

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

How do I mix multiple colors into one color? 1 Answer

changing color on collision -1 Answers

Why doesnt unity find Hsb color? 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