Hi I have a script to change the colour of a light every few seconds but I am having a few issues with it and I am wondering what the errors are and how to fix them.
Here is my script
using UnityEngine;
using System.Collections;
public class lightController : MonoBehaviour
{
Color[] colours = new Color[5];
public float time;
public float repeatRate;
void Start()
{
colours[0] = Color.blue;
colours[1] = Color.cyan;
colours[2] = Color.green;
colours[4] = Color.magenta;
colours[5] = Color.red;
colours[6] = Color.yellow;
}
void Update()
{
InvokeRepeating("ChangeColour", time, repeatRate);
}
void ChangeColour()
{
light.color = colours[Random.Range(0, colours.Length -1)];
}
}
The error is
“IndexOutOfRangeException: Array index is out of range.
lightController.Start () (at Assets/lightController.cs:16)”
and the problem is that the lights seem to flash very quickly not depending on how much the Time and Repeat Rate is. This is rather urgent because if I do not fix this error. I may induce a seizure.
Please help.