Hey guys! I have a sceen with 4 spot lights. at the beginning they should all be turned off. when i press the “L” button on my keyboard, i want them to turn on one by one. The first light in the row, then it should wait for one second, then the second light and so on. i’m really new to unity and my scripting experience is also on a low level but i really hope you can help me with that!
thanks in edvance!
Good day.
You should create a Ienumerator corrutine. Have all light objects in a array, then just
Ienumerator TurnOnLights()
{
foreach (GameObject Onelight in LightsArray)
{
Onelight.GetComponent<Light>().enabled=true;
yield return new WaitForSeconds (1);
}
}
Something like this.
Bye!
Ah ok thanks for your answer! so this means the order of the lights in my array class define the order which light turns on at the beginning? can you please give me an example how to set up an array for let’s say my lightnames are: light1, light2, light3, light4? thanks