Hi! 
How Can I do to create a sequence of light?
There are 4 Point Light, and I would like to that one at a time turning on…(every 3 seconds about) like a cycle…
And when finished the cycle, starts again…
I hope I explained well, sorry for my bad english… 
Thank you
1 Answer
1
there are a couple of ways to achieve this. Either way, you need to write a new script like the one below:
using UnityEngine;
using System.Collections;
[System.Serializable]
public class LightAnimator : MonoBehaviour {
// number of seconds between changing light
public float lightTime = 1;
// the current light that is lit.
int currentLight = 0;
public Light[] lights;
void Start()
{
StartCoroutine("ChangeLight");
}
IEnumerator ChangeLight()
{
yield return new WaitForSeconds(lightTime);
Debug.Log("Changing light to number "+currentLight);
// disable the current light
lights[currentLight].enabled = false;
// change the index to the next light
currentLight++;
// if the index is 4 or more, go back to the first light
if (currentLight >= 4)
currentLight = 0;
// the current light is now the next light, so enable it.
lights[currentLight].enabled = true;
// call this method again to create an infinite loop.
StartCoroutine("ChangeLight");
}
}
Once you have created this script, create an EMPTY game object in your scene, and attach this script to it. You can call this object “LightAnimationController”, or something similar. In the inspector, you should have a variable within the attached script on the right called “Lights” - you should be able to drag your lights (from your scene) into this array. When expanded out, you should see your 4 lights you have added.
Thank you so much, is perfect! :) The last question, to add a Input? Because at the start the light should be off, and If I press a Key, they light up..
– PaxStyleObviously I removed start method, and I added the void Update so: void Update() { if (Input.GetKeyDown(KeyCode.C)) { StartCoroutine("ChangeLight"); } else if (Input.GetKeyDown(KeyCode.C)) { StopCoroutine("ChangeLight"); } } Departure is correct, but when I press "C" to stop, not stop lights, but increases the speed of those.. O.O I've already voted your answer.. ;)
– PaxStyle