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 MithosAnnar · Apr 02, 2012 at 04:20 PM · materialobjectcolorpercentage

How do I Adjust The Colour Of My Object By Percentages?

Hello, and how are you?

I'm trying (and very, very hard at that!) to change the colour of an object by picking up other objects, what are a certain colour.

For example:

If I was to pick up two red objects and a blue object I would want my object to be 2 parts red and 1 part blue.

Here is the script i'm using.

 var red : float; 
 var green : float; 
 var blue : float; 
 var purple : float;
 var orange : float;
 
 var playerColor : Material;
 
 function Start () {
 
    playerColor = renderer.material;
 
 }
 
 function Update () {
 
    red = red + purple / 2 + orange /3;

    green = green + orange /3;

    blue = blue + purple / 2 + orange /3;
             
    playerColor.SetColor("_Tint", Color(red, green, blue));
 
 }
 
 function OnCollisionEnter (other : Collision) {
 
 if (other.transform.tag == "Particle") {
 
    other.gameObject.SendMessage("SendParticle");
    
    Destroy (other.gameObject);
 
 }
 
 }
 
 function AddBlue () {
 
    blue ++;
 
 }
 
 function AddRed () {
 
    red ++;
 
 }
 
 function AddOrange () {
 
    orange ++;
 
 }
 
 function AddPurple () {
 
    purple ++;
 
 }
 
 function AddGreen () {
 
    green ++;
 
 }

So yeah... It doesn't work. Maybe a tip or two (something...anything..) on how colour works?

Thanks!

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

Answer by Berenger · Apr 02, 2012 at 04:32 PM

The Color object in Unity has 4 components r, g, b and a, all of them between 0 and 1, (1,1,1,1) being white. If you keep adding to your colors, it will inevitably end up white.

What you want is a mix between color. You should look at Color.Lerp. However, an interpolation done that way can give you black or dark color inbetween, and you probably don't want that. You should take a look at HSV colors (hue saturation value), that use a Lerp probably more relevant to your needs.

Comment
Add comment · Show 2 · 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 MithosAnnar · Apr 02, 2012 at 05:44 PM 0
Share

@Bérenger $$anonymous$$antoue: Thanks for your reply. I am figuring it out this way as of current!

avatar image MithosAnnar · Apr 03, 2012 at 03:57 PM 0
Share

It worked!

Thanks again!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

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

Changing two different objects renderer colour 1 Answer

I want to have multiple colors of car with best performance solution. 1 Answer

Changing a second objects material on trigger 0 Answers

Cannot Assign Material To Object 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