how to trigger a function at a certain time?

hello Forum,

i don’t get it to work : (. i have to admit that i am an scripting newbie mainly writing in Static JavaScript.
OK, Before my actual program starts (or the Main Level is loaded) i want to play a little animated Logo (animation done in 3dsmax and the Animation Clip is automatically started). When the animation is over i want to fade in a plane in front of the camera (by Mathf.Lerp of the alpha value of the main color of it’s material) to hide the Logo.
What is the best practice how trigger this FadeOut-function when the animation is over and then trigger the loading of the level when my FadeOut- function is over?

i experimented a lot with Time.realtimeSinceStartup and if-conditions. But the Mathf.Lerp seems to be allergic against everything that has got to do with time (the fade works fine in the update function if i fire it by an if-condition which has nothing got to do with time). But i need to time things anyhow that are happening or triggered in my program.
Is there a common practice how to time things (with functions which have for loops inside)? And how do i make this frame rate independent (i know with time. time and time.deltatime, but i don’t get it right).

Or can anyone recommend a reading in the internet or a good book?

Use yield and coroutines. Update is only appropriate for stuff that happens every frame.

function Start () {
   yield AnimatedLogo();
   yield FadeOut();
   Application.LoadLevel("whatever");
}

function AnimatedLogo() {
   // do animation stuff here
}

// etc.

(The docs say Start can’t be a coroutine, but the docs are wrong.) Time.deltaTime is appropriate for making things framerate-independent.

–Eric

oh thanx a lot!!! u turned a despaired and frustrated man into a happy man : ).

i see myself using the ‘yield WaitForSeconds(x.x);’ a lot in future. Yeah and it works fine in the ‘function Start ()’.
I heard this even uses almost no cpu power while waiting.