Coroutine - events not working

I have spent endless nights, pulling my hair out a burning out my brain, why? Because I cannot seem to wrap my head round why my code will not work.

I am using a coroutine to enable an event to work.

I want a loading screen (a scene) to wait 5 seconds when it starts and to wait for the space bar to be pressed to actually load the next level… Please help me, I cannot stand my pain.

function start() 
{

yield WaitForSeconds (5);
gameObject.Find("Continue").renderer.enabled = true;
gameObject.Find("Continue").renderer.material.color = Color.gray;
StartCoroutine("Do");


function Do(){
if

 	 (Input.GetKeyDown(KeyCode.Space))
 	 {
 	 
Application.LoadLevel("OpeningTutorialScene");


}
}

This is what you need:

function Start()
{
    yield WaitForSeconds (5);
    var renderer = gameObject.Find("Continue").renderer;
    renderer.enabled = true;
    renderer.material.color = Color.gray;
    while(true)
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            Application.LoadLevel("OpeningTutorialScene");
        }
        yield;
    }
}

btw: note that “Start” starts with a capital “S” or it won’t work. “start” and “Start” is not the same thing.

Coroutines are tricky business sometimes. Try this method instead.

private var startTime : int = 0;
public var waitForSecondsTime : int = 0;

        function Awake() 
        {
            startTime = Time.time;
            gameObject.Find("Continue").renderer.enabled = true;
            gameObject.Find("Continue").renderer.material.color = Color.gray;
        }
         
        function Update ()
        {
          if (Time.time > startTime + waitForSecondsTime)
          {
             Do();
          }
        }

 
        function Do()
        {
           if (Input.GetKeyDown(KeyCode.Space))
           {
              Application.LoadLevel("OpeningTutorialScene");
           }
        }