Hi there, I’m experienced with Unity as a game engine but a beginner with c# and javascript. I’am writing a script in which an objects colour will change after a random number of seconds. It must be 1 of 6 colours i have already chosen, it cant just be random. I’ve got the timer working and i can change the colour to red for instances, but how do I get the colour to change to any one of the random colours I’ve chosen.
So lets say after a random number of seconds between 10 and 50 the colour of this object will change to either, red, blue, pink, green or yellow?
my code so far:
using UnityEngine;
using System.Collections;
public class MasterCube : MonoBehaviour {
//public float targetTime = 60.0f;
public float colorChange;
IEnumerator Start()
{
yield return StartCoroutine(MyDelayMethod(Random.Range( 5,15 )));
//3.1415 seconds later
}
IEnumerator MyDelayMethod(float delay)
{
yield return new WaitForSeconds (delay);
Debug.Log ("time");
this.gameObject.renderer.material.color = new Color (255, 0, 0, 255);
}
}