public GameObject cube;
public Color[] colors;
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
StartCoroutine(ChangeCube(cube));
}
}
IEnumerator ChangeCube(GameObject cube)
{
WaitForSeconds wait = new WaitForSeconds(1f);
for (int i = 0; i <= colors.Length; i++)
{
cube.GetComponent<Renderer>().material.color = ChooseColor(colors[i]);
Debug.Log("Current color: " + colors[i]);
yield return wait;
}
}
private Color ChooseColor(Color chosenColor)
{
return chosenColor;
}