using UnityEngine;
using System.Collections;

public class ColourChange : MonoBehaviour {

	public float count = 0f;
	bool colourChange = true;
	bool colourChange2 = false;
	bool colourChange3 = false;
	Color32 newCol = new Color32 (0, 0, 255, 255);

	// Update is called once per frame
	void Update () {
		if (colourChange) 
		{
			newCol = Color32.Lerp (new Color32(0,0,255,255),new Color32(0,255,255,255),count);
		}
		if (colourChange2) 
		{
			newCol = Color32.Lerp (new Color32(0,255,0,255),new Color32(255,0,0,255),count);
		}
		if (colourChange3) 
		{
			newCol = Color32.Lerp (new Color32(255,0,0,255),new Color32(0,0,255,255),count);
		}

		if (count >= 1f) 
		{
			if(colourChange)
			{
				colourChange = false;
				colourChange2 = true;
				count = 0f;
			}
			else if(colourChange2)
			{
				colourChange2 = false;
				colourChange3 = true;
				count = 0f;
			}
			else if(colourChange3)
			{
				colourChange3 = false;
				colourChange = true;
				count = 0f;
			}
		}
		renderer.material.color = newCol;
		count += 0.01f;
	}
}
