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 Recalc · Feb 24, 2018 at 05:30 AM · colorspriterenderer

Modify Sprite HSV Values

I am trying to modify the HSV values of my ingame sprites via this code:

    float greenLv = 0.1f;    
     
     //Access each childrenderer in the game 
     foreach (Renderer childRend in rend) {
     
             Debug.Log (childRend.name);
     
             currColor = childRend.material.color;
     
             Debug.Log ("currentColor" + currColor);
     
             Color.RGBToHSV (currColor, out h, out s, out v);
     
             Debug.Log (" child HSV values colors " + h + "," + s + ","+ v);
     
             currColor = Color.HSVToRGB(greenLv,greenLv,greenLv);
     
             childRend.material.color = currColor;
     
 }

For some reason, the HSV values I get are always (0,0,1) - which should mean the color black? Even though I know for sure the sprite isn't black. Is it getting the first pixel it encounters? How can I possible edit the overall tint of a sprite?

Thank you in advance!

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

Answer by yummy81 · Feb 24, 2018 at 10:17 AM

Let's take a closer look at your code. Inside foreach loop you assign each individual material's color to the "currColor" variable. Then, you translate it into HSV values. As a result, color is stored in h, s and v variables now. Next, you want to reverse the operation converting HSV values back to RGB values and assign the result to childRend.material.color, but instead of doing this:

 currColor = Color.HSVToRGB(h, s, v);
 
 

you are doing that:

 currColor = Color.HSVToRGB(greenLv,greenLv,greenLv);
 
 

That simply means that you do not assign color stored in h, s, v floats, but hardcoded color (0.1f, 0.1f, 0.1f). That's because greenLv = 0.1f. And, that's why you see black color (of course it's not entirely black (0.0f), but almost black (0.1f)). You also ask whether HSV values (0, 0, 1) means black color - no, it's white, but because you assign greenLv float, you see black color. I'm not sure what your final goal is, but I created a small script which allows to manipulate H, S, V floats and see how colors of each child sprite change. Below, there is how my experimental scene looks like, and the script. Put the script on HonestKun gameobject. Remember that each child sprite has its own individual material: Circle gameobject has CircleMaterial, Square has SquareMaterial, and Triangle has TriangleMaterial.

 using UnityEngine;
 
 public class HonestKun : MonoBehaviour
 {
     [Range(0, 1)] public float h = 0f, s = 0f, v = 1f;
     private Renderer[] rend;
     
     private void Awake()
     {
         rend = GetComponentsInChildren<Renderer>();
     }
     
     private void Update()
     {
         Color color = Color.HSVToRGB(h, s, v);
         foreach (Renderer r in rend)
         {
             r.material.color = color;            
         }
     }
 }
 

alt text


pic.png (96.3 kB)
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

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

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

Related Questions

Finding all sprite renderers in the scene and tell them to change color 1 Answer

Array of colors not working, all sprites turn white. 1 Answer

Eyedropper/colordropper GameObject 0 Answers

renderer.enabled doesn't work but coloring does 1 Answer

How to access SpriteRenderer Color from a shader? 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