How to make light fade in 3 seconds after scene begins?

Hi, i’m trying to have a light fade in after 3 seconds have passed since my scene starts. Actually there are a few things i’d like to fade in (including the emission intensity of a material).

So my scene ideally would go like this:

  • Scene begins
  • 3 seconds pass in darkness
  • lights fade in (lets say it takes them 1.5 seconds to do so, so that they are fully lit by the 4.5 second mark), at the same time material emission intensity fades in too.

I know this is some basic C# stuff but I just don’t have the experience. I also tried searching for an answer but couldn’t find anything suitable. Thanks for the help!

P.S. one of my lights has a pulsating script, so ideally that light would fade in then begin pulsing afterward.

Here’s the pulsing script:

public float duration = 1.0F;
public Light lt;
void Start() {
	lt = GetComponent<Light>();
}
void Update() {
	float phi = Time.time / duration * 2 * Mathf.PI;
	float amplitude = Mathf.Cos(phi) * 1F + 1F;
	lt.intensity = amplitude;
}

could use coroutines, but will be hard for you right now

so,

void Update() {
     float brightness = Mathf.Clamp01(Time.time / duration);
     lt.intensity = brightness ;
 }

Check out this lesson, somewhere from 1h 48 minutes:

Hi @wpaunity try using invoke and coroutines! They work perfectly for this stuff!

 public Light lt;
 void Start() {
	float timeUntilInvoked = 3.0f;//Seconds to pass before invoke
	Invoke("TriggerFunction", timeUntilInvoked);//Invoke certain function after 3.0f seconds
 }

void TriggerFunction() {
	StartCoroutine("FadeIn");//Start a coroutine to run independent from the update function
}

IEnumerator FadeIn() {
	float duration = 5.0f;//time you want it to run
	float interval = 0.1f;//interval time between iterations of while loop
    lt.intensity = 0.0f;
	while (duration >= 0.0f) {

        lt.intensity += 0.02;
           
		duration -= interval;
		yield return new WaitForSeconds(interval);//the coroutine will wait for 0.1 secs
	}
}

This will make the while statement run for 5 seconds with 10 intervals per second.
So if you want a variable to go from 0 to 100 smoothly in 5 seconds you can just add to a variable +2 inside the while loop.

Edit: Edited the code so that if you plug the code in and give a light component to the corresponding variable " lt " it will turn the light off and after 5 secs it will go to the max intensity. I hope it will give you a better understanding.