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 davidflynn2 · Oct 05, 2013 at 06:41 PM · c#colorchange

Blend into next color instead of jumping to next color

I have the following script segment in my day and night cycle I have been working on but instead it just jumping form SunRiseColor to normalColor I want it to blend to that color as it goes or change shades till it gets there. The _timeOfDay is my day code that its basing when do do each at. Right now I am doing sunRiseColor and sunRise2Color because I could not get a blend.

 private void AdjustColor()
     {
         for(int cnt = 0; cnt < _sunScript.Length; cnt++)
             {
             
         
         if(_timeOfDay >20 && _timeOfDay < 38)
             {
                 _sunScript[cnt].GetComponent<Light>().color = sunRiseColor;
                 _sunScript[cnt].GetComponent<LensFlare>().color = sunRiseColor;
             }
         if(_timeOfDay >38 && _timeOfDay < 40)
             {
                 _sunScript[cnt].GetComponent<Light>().color = sunRise2Color;
                 _sunScript[cnt].GetComponent<LensFlare>().color = sunRise2Color;
                 
             }
         if(_timeOfDay > 75 && _timeOfDay < 85)
             {
                 _sunScript[cnt].GetComponent<Light>().color = sunSetColor;
                 _sunScript[cnt].GetComponent<LensFlare>().color = sunSetColor;
             }
         if(_timeOfDay > 85 && _timeOfDay < 100)
             {
                 _sunScript[cnt].GetComponent<Light>().color = sunSet2Color;
                 _sunScript[cnt].GetComponent<LensFlare>().color = sunSet2Color;
             }
             
         if(_timeOfDay > 40 && _timeOfDay < 75)
             {
                 _sunScript[cnt].GetComponent<Light>().color = normalColor;
                 _sunScript[cnt].GetComponent<LensFlare>().color = normalColor;
             }
             
         }
     }
Comment
Add comment · Show 2
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 davidflynn2 · Oct 05, 2013 at 08:26 PM 0
Share

Any one please help me with this I Like how its come out but I cant figure out how to blend to the next color.

avatar image Mamul · Oct 05, 2013 at 08:39 PM 0
Share

I would recomend to use iTween , although it depends what exactly you are doind.Anyway check this link ,there are samples that could help you. http://pixelplacement.com/itweenARCHIVE/

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by TrickyHandz · Oct 05, 2013 at 08:59 PM

Color.Lerp would do this for you beautifully. Here is an example of one case:

 Light targetLight = sunScript[cnt].GetComponent<Light>();
 LensFlare targetLensFlare = _sunScript[cnt].GetComponent<LensFlare>();
 
 targetLight.color = Color.Lerp(targetLight.color, sunRiseColor, 
                                 Time.deltaTime * 0.5f);
 targetLensFlare.color = Color.Lerp(targetLensFlare.color, sunRiseColor,
                                    Time.deltaTime * 0.5f);

Let me know how that works out for you.

EDIT: Here is a link to the docs page for this - Color.Lerp

Comment
Add comment · Show 5 · 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 davidflynn2 · Oct 05, 2013 at 09:08 PM 0
Share

Ya, that has the effect I want, I was actually just playing with that myself the only problem I am hitting is its not changing fast enough.

avatar image g0tNoodles · Oct 05, 2013 at 09:12 PM 0
Share

Then change the time component of it.

avatar image TrickyHandz · Oct 05, 2013 at 09:15 PM 1
Share

You can change the dampening multiplier at the end to make it go faster. Just change work your way towards the speed you want:

 targetLight.color = Color.Lerp(targetLight.color, sunRiseColor
                                Time.deltaTime * 5.0f);

That would make it go 10 times faster than my initial example.

avatar image davidflynn2 · Oct 05, 2013 at 09:16 PM 0
Share

Ok I see what I was doing wrong I was going down to try to go faster its up to go faster down to go slower. Ops lol thanks so much.

avatar image TrickyHandz · Oct 05, 2013 at 09:28 PM 1
Share

Not a problem. When you have a chance, just mark the question as answered so other people that are trying to do this can easily find a solution. Happy coding!

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

18 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

Related Questions

Multiple Cars not working 1 Answer

Problem with color c# 1 Answer

Referencing color change when object is 'deselected' 2 Answers

Distribute terrain in zones 3 Answers

Multiple Button Modifications 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