Hi I’m basically trying to get it so that a light that starts disabled, is set to use a flicker script once a global variable is enabled, but at the moment it is not working. Any ideas?
var minFlickerSpeed : float = 0.01;
var maxFlickerSpeed : float = 0.05;
var minLightIntensity : float = 1;
var maxLightIntensity : float = 2;
while(ClickableItemPowerHouse.isPowerActivated == true)
{
light.enabled = true;
light.intensity = Random.Range(minLightIntensity, maxLightIntensity);
yield WaitForSeconds (Random.Range(minFlickerSpeed, maxFlickerSpeed ));
light.enabled = false;
yield WaitForSeconds (Random.Range(minFlickerSpeed, maxFlickerSpeed ));
}
Heh I solved my own problem after many combinations of things very similar to the code that finally worked:
var minFlickerSpeed : float = 0.01;
var maxFlickerSpeed : float = 0.05;
var minLightIntensity : float = 1;
var maxLightIntensity : float = 2;
function Update ()
{
if(ClickableItemPowerHouse.isPowerActivated == true)
{
FlickerLight();
}
}
function FlickerLight()
{
while(true)
{
light.enabled = true;
light.intensity = Random.Range(minLightIntensity, maxLightIntensity);
yield WaitForSeconds (Random.Range(minFlickerSpeed, maxFlickerSpeed ));
light.enabled = false;
yield WaitForSeconds (Random.Range(minFlickerSpeed, maxFlickerSpeed ));
}
}
That would work. But I think, that FlickerLight() gets run multiple times, started each Frame the Power is Activated. Functions called can run through multiple frames…
You should only start the FlickerLight() Function if the Status turned from false to true and inside that Function check if it still is Activated and then Quit the while-loop. Because of the while(true) the Function will run forever, and started each frame again… It will probably slow down your game after a while…