Is it possible that you have set Time.timescale to 0?
Does it work when you replace the yield with
yield null;
This of course won’t wait 3 seconds, it’s just a test to see if it works.
*** edit ***
Well, the way you call the coroutine is the actual problem. When using UnityScript (Unity’s “Javascript”) you don’t need to call StartCoroutine because the compiler does this automatically for you. The problem is that you use StartCoroutine of this script and not on the one where the coroutine is actually located. So you actually do:
this.StartCoroutine(sceneManager.GetComponent(scriptSceneManager).GameOver());
This will run the coroutine on the current object (the one this script is attached to). This usually isn’t a problem, but since you immediately call
Destroy(gameObject);
after that line, this object is destroyed and all coroutines that run on that object.
In your case you have to use:
var sm = sceneManager.GetComponent(scriptSceneManager);
sm.StartCoroutine(sm.GameOver());
However it’s actually not a good idea to start a coroutine that way. You should make the actual coroutine private and invoke it from a “normal” method. So inside your “scriptSceneManager” class it should look like this:
function GameOver()
{
GameOverCo();
}
private function GameOverCo ()
{
print("GameOver has started");
yield WaitForSeconds(3);
print ("Yield waitforseconds in GameOver has ended");
Application.LoadLevel("screenLose");
}
It looks totally silly and looks like it’s pointless to do that extra step, but the compiler actually creates this code:
function GameOver()
{
this.StartCoroutine(GameOverCo());
}
Now when you call the GameOver method from another object, the coroutine will run here on the “scriptSceneManager” object since we now use StartCoroutine of this object and not the one of the calling object.