Simple Boolean Loop for Flashing Lights.

Could someone please point me in the right directions, basically I need to create a flashing light by turning the light on and off, I am not the best scripter in the word any help would be appriciated.

Edit: Managed to do it through Animation. But the script would also me nice to have.

var theLight: Light ;//assign light
var timing:float=1.5; //time for on/off light
private var lOnOff:boolean=true;//for check status




function FixedUpdate () {
if(lOnOff){
LampOff();
}
else{
LampOn();
}
}


function LampOn () {


yield WaitForSeconds(timing);
theLight.enabled=true;
lOnOff=true;
return;


}

function LampOff () {

yield WaitForSeconds(timing);
theLight.enabled=false;
lOnOff=false;
return;


}

this is simply way.Apply thi javascript on the object u want and setting the variable.

I can’t count the number of things wrong with that example… Overly complex, inefficient, and fairly flaky. It’ll start a bunch of coroutines every frame, all running simultaneously.

var myLight : Light;
var duration : float = 1.0;
function Start() {
while (true) {
myLight.enabled = !myLight.enabled;
yield WaitForSeconds(duration);
}
}

Here is a little version i used a few times.
I use an array. :smile:

var lightList : Light[];
var lightPulse = 0.0;
//=======================//
function Update () {
  for(var l in lightList)	
  l.intensity = Mathf.Sin( Time.time*lightPulse );
}

Thanks for the response guys. Much appriciated.