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;
}
}
}