I am new to unity and coding and game design in general, but I am trying to create a light that fades its intensity up from 0 at the beginning of the game. I’d like to to be delayed a certain amount of time before starting to fade. I literally have nothing down for this one and am not sure where to go. Any help is greatly appreciated!
EDIT
I know the title says “Flickering Light Controls”…my bad, that was for a different post…
Hey, we meet again in a short span of a few minutes. You can probably try doing a coroutine and use WaitForSeconds to do the delay.
http://docs.unity3d.com/Documentation/ScriptReference/WaitForSeconds.WaitForSeconds.html
If you don’t want to take the plunge and use WaitForSeconds for the delay (I don’t really like coroutines), you can create a float value which adds Time.deltaTime until it hits a certain value.
if(waitTime < 3f) // If counting to 3 seconds
{
waitTime += Time.deltaTime;
}
else
{
// End of delay
}
As for the flicker effect, you can change the value of the light’s intensity over time (using Time.deltaTime).
Thanks wolf hunter!
Not to keep hounding you (get it, canine joke…) but I am like brand, brand new to this and trying to meet deadlines. What variables/functions would be used to control the intensity?
I don’t know what to put after “else”
Sorry and thanks again for all your help!
No worries. You can use Light.intensity to adjust the brightness.
var duration = 8;
var myLight : Light;
function Update()
{
if(duration > 0)
{
duration -= Time.deltaTime * 5f;
myLight.intensity = duration;
}
}
Please amend the code to your requirements.
Take a look at Mathf.PingPong for fading the light intensity in and out.