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 8r3nd4n · Apr 01, 2013 at 11:28 AM · materialcolorlerpfadetransition

Lerping/Fading between multiple colours

Hi

I have been searching and going through the docs for how to successfully fade from one colour to another but after a few hours of trial and error, have come up still unsure how to achieve this. I thought lerping between colours would be simple enough =(

I have some colliders in the scene and when the player object hits them, it should change the colour of a skysphere I have. At the moment, it changes straight away but I'm after a fade/transition effect so its not so jarring.

I tried the fade script from Unify Wiki: http://wiki.unity3d.com/index.php?title=Fade but could not get this working either. I have been looking at coroutines but am a bit lost with them.

Anyone have some ideas as to how to get this going? The material colour is passed in from another script.

Thanks

 using UnityEngine;
 using System.Collections;
 
 public class ChangeSkysphereColour : MonoBehaviour {
     
     public static string materialColour;
     public Color blue = new Color (129.0F,155.0f, 255.0f);
     public Color green = new Color (160.0F,255.0f, 170.0f);
     public Color pink = new Color (253.0F,100.0f, 253.0f);
     public Color yellow = new Color (255.0F,148.0f, 179.0f);
     public Color white = new Color (228.0F,228.0f, 228.0f);
     private Color currentColour;
     
     // Use this for initialization
     void Start () {
         currentColour = yellow;
     }
     
     // Update is called once per frame
     void Update () {
         
         //renderer.material.color = currentColour;
         if(materialColour == "Blue")
         {
         renderer.material.color = Color.Lerp(currentColour,blue, 0.1f);
         currentColour = blue;
         }
         
         if(materialColour == "Green")
         {
         renderer.material.color = Color.Lerp(currentColour,green, 0.1f);
         currentColour = green;
         }
         
         if(materialColour == "Yellow")
         {
         renderer.material.color = Color.Lerp(currentColour,yellow, 0.1f);
         currentColour = yellow;
         }
         
         if(materialColour == "Pink")
         {
         renderer.material.color = Color.Lerp(currentColour,pink, 0.1f);
         currentColour = pink;
         }
         
         if(materialColour == "White")
         {
         renderer.material.color = Color.Lerp(currentColour,white, 0.1f);
         currentColour= white;
         }
         
     }
     
 }
 


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 whydoidoit · Apr 01, 2013 at 12:16 PM

Lerp's last parameter is a number between 0 and 1 representing the current level between the two.

  string lastMaterialColour;
  float t;
 // Update is called once per frame
 void Update () {
    if(lastMaterialColour != materialColour)
    {
       t= 0; 
       lastMaterialColour = materialColour;
    }
    t += Time.deltaTime;
    //renderer.material.color = currentColour;
    if(materialColour == "Blue")
    {
    renderer.material.color = Color.Lerp(currentColour,blue, t);
    currentColour = blue;
    }
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 whydoidoit · Apr 01, 2013 at 12:16 PM 0
Share

This code resets the time when the colour changes

avatar image 8r3nd4n · Apr 01, 2013 at 01:33 PM 0
Share

Thanks for that. I should have realised that the value in the Lerp was just sitting there without any change in value.

However, after putting the new code in, it still just jumps between colours rather than fade between them. $$anonymous$$aybe the colour values need to be modified individually? Or would this work better on materials rather than direct colours?

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

11 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

Related Questions

Changing two different objects renderer colour 1 Answer

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

How to fade an image 1 Answer

Color lerp once? 2 Answers

How can I blend between 5 different materials? 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