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 KitsuneWarriorr · Dec 03, 2014 at 09:29 AM · c#color changecolor.lerp

How can I loop through all colours in code?

Right I need to make a certain part of a material change colour the part in question is called "indicator color" and it needs to loop through the whole colour spectrum so from R-RB-B-BG-G-GR-R-RB etc. I'm very bad with this sort of coding however and I have no idea where to start. I know it requires a lerp but it also needs to loop, any help will be very much appreciated

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
1

Answer by HarshadK · Dec 03, 2014 at 09:53 AM

I'm not quite sure if this is what you are asking for but below is an example to loop through the color spectrum.

 Color currentColor;
 
 for(int b = 0; b <= 255; b++)
 {
     for(int g = 0; g <= 255; g++)
     {
         for(int r = 0; r <= 255; r++)
         {
             currentColor = new Color(r/255, g/255, b/255);
         }
     }
 }

This will loop through all the available colors in an 8 bit color palette. Starting from all red shades then moving towards green to blue in the end. Also the shades will start from darker to lighter as it will start from black and end with white.

If you need specific range then you can actually set values for variables r, g, and b in the loop for specific value range you need.

Comment
Add comment · Show 10 · 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 KitsuneWarriorr · Dec 03, 2014 at 10:02 AM 0
Share

Okay thanks, but how can I make effect only th indicator color shader? the rest of the material needs to remain unchanged

avatar image HarshadK · Dec 03, 2014 at 10:06 AM 0
Share

So you want to apply this effect to a part of the material?

avatar image KitsuneWarriorr · Dec 03, 2014 at 10:09 AM 0
Share

yes, the indiactor shader

 Shader "Custom Ambient" {
 
     Properties {
 
         _Color ("$$anonymous$$ain Color", Color) = (1,1,1,1)
 
         _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
 
         _Shininess ("Shininess", Range (0.01, 1)) = 0.078125
 
         _$$anonymous$$ainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
 
         _AmbTex ("Ambient", 2D) = "black" {}
 
         _Bump$$anonymous$$ap ("Bump (RGB)", 2D) = "bump" {}
 
         _IndicatorTex ("Indicator Lights (RGB)", 2D) = "black" {}
 
         _Indicator ("Indicator Color", Color) = (1,1,1,1)
 
         _Glow ("Glow Color", Color) = (0,0,0,1)
 
         _Silhouette ("Silhouette Color", Color) = (0.5, 0.5, 0.5, 1)
 
     }


The Indicator is what I want to edit

avatar image Lunatix · Dec 03, 2014 at 10:12 AM 1
Share

Just wanted to point out, that this will not work in C# since you use integers in your example - use "(float)r / 255.0f" ins$$anonymous$$d.

avatar image HarshadK · Dec 03, 2014 at 10:21 AM 1
Share

@Lunatix +1 for pointing out.

@$$anonymous$$itsuneWarriorr he is right. He is just pointing out the fact that you need to append an 'f' in front of float value and since variables r, g, and b are int they need to be typecasted to float.

I just gave the logic and it was not an actually intended code to be copy and pasted to use as is. $$anonymous$$y apologies.

Show more comments

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

25 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

Related Questions

Change slider color to green when value is 50 2 Answers

Distribute terrain in zones 3 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Multiple Cars not working 1 Answer

Flat Low Poly Terrain / Script a terrain 2 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