Application.LoadLevel issue

Not sure what’s going on here.

This works;

function LoadLevel ()
{
	soundManagerScript.PlaySound (soundManagerScript.button01);

	Application.LoadLevel("Test");
}

This does not work;

function LoadLevel ()
{
	soundManagerScript.PlaySound (soundManagerScript.button01);
	yield WaitForSeconds (.390);
	Application.LoadLevel("Test");
}

it gives me this error;

TitleManager.LoadLevel must have a ‘void’ return type.

Any ideas what I’m missing here?

The problem that you have is this, you’re using yield which will automagically be converted to a return type of IEnumerator instead of void.

put your Level call in another function:

function PrepLoadLevel ()
{
    soundManagerScript.PlaySound (soundManagerScript.button01);
    yield WaitForSeconds (.390);
    ActuallyLoadLevel();
}

function ActuallyLoadLevel()
{
    Application.LoadLevel("Test");
}

Typically you can’t call a coroutine from a NGUI button. Functions on NGUI buttons must have a return type of void. Fix by wrapping the coroutine

// This function cannot be a coroutine as it is attached to a button
function StartLevel ()
{
    LoadLevelCoroutine();
}
 
function LoadLevelCoroutine()
{
    soundManagerScript.PlaySound (soundManagerScript.button01);
    yield WaitForSeconds (.390);
    Application.LoadLevel("Test");
}

I would also suggest you change the name of your function from LoadLevel, as this is inherently confusing to debug. In this case the problem was with TitleManager.LoadLevel, not Application.LoadLevel.