this code is not working and color remain in blue
using UnityEngine;
using System.Collections;
public class ColorSwitch : MonoBehaviour {
Material Text;
// Use this for initialization
void Start ()
{
Text = gameObject.renderer.material;
}
// Update is called once per frame
void Update ()
{
Text.color = Color.Lerp(Color.blue, Color.red, 3);
Debug.Log("color is red");
if (Text.color == Color.red)
{
Text.color = Color.Lerp(Color.red, Color.blue, 3f);
Debug.Log("color is blue");
}
}
}
um you do know how Lerp works right?
for some reason you use a constant 3 instead of a variable. what will happen since you set it to more than 100 percent each frame, your eyes wont even pick up a color change, though it is change, this will slow it done for you.
public class ColorSwitch : MonoBehaviour {
Material Text;
float Timer = 0f;
// Use this for initialization
void Start ()
{
Text = gameObject.renderer.material;
}
// Update is called once per frame
void Update ()
{
Text.color = Color.Lerp(Color.blue, Color.red, Timer);
Debug.Log("color is red");
if (Text.color == Color.red)
{
Text.color = Color.Lerp(Color.red, Color.blue, Timer);
Debug.Log("color is blue");
}
Timer += Time.deltaTime * 0.02f;
if(Timer >= 1f) {
Timer = 0f;
}
}
}
now it should fade to blue and to red over and over;