- Home /
application loadlevel c# calling coroutine not working?
Hi - I'm struggling to get the Application.LoadLevel working using C# (it seems a lot more confusing than JavaScript)
I don't know whether to post my whole code on it's quite long - but essentially when the screen turns black and the gameOver is true, I want a short delay before a different level loads.
But I'm getting two errors on calling the coroutine - 'Identifier expected' and 'Unexpected symbol `0' in class, struct, or interface member declaration'.
void checkGameOver()
{
if(camA3.gameObject.activeInHierarchy == true)
{
if(A3B3 == true && A3A4 == true)
{
if(A3W.GetComponent<BoxCollider>().isTrigger == false && A3B2W.GetComponent<BoxCollider>().isTrigger == false)
gameOver = true;
}
}
else if(camA4.gameObject.activeInHierarchy == true)
{
if(A4B4 == true && A3A4 == true)
{
if(A4W.GetComponent<BoxCollider>().isTrigger == false && A4B5W.GetComponent<BoxCollider>().isTrigger == false)
gameOver = true;
}
}
else if(camB2.gameObject.activeInHierarchy == true)
{
if(B2B3 == true && B2C2 == true)
{
if(B2C1W.GetComponent<BoxCollider>().isTrigger == false && B2A3W.GetComponent<BoxCollider>().isTrigger == false)
gameOver = true;
}
}
else if(camB3.gameObject.activeInHierarchy == true)
{
if(B3B4 == true && B3C3 == true && A3B3 == true && B2B3 == true)
{
gameOver = true;
}
}
else if(camB4.gameObject.activeInHierarchy == true)
{
if(B4B5 == true && B4C4 == true && A4B4 == true && B3B4 == true)
{
gameOver = true;
}
}
else if(camB5.gameObject.activeInHierarchy == true)
{
if(B5C5 == true && B4B5 == true)
{
if(B5A4W.GetComponent<BoxCollider>().isTrigger == false && B5C6W.GetComponent<BoxCollider>().isTrigger == false)
gameOver = true;
}
}
else if(camC1.gameObject.activeInHierarchy == true)
{
if(C1C2 == true && C1D1 == true)
{
if(C1B2W.GetComponent<BoxCollider>().isTrigger == false && C1W.GetComponent<BoxCollider>().isTrigger == false)
gameOver = true;
}
}
else if(camC2.gameObject.activeInHierarchy == true)
{
if(B2C2 == true && C2D2 == true && C1C2 == true && C2C3 == true)
{
gameOver = true;
}
}
else if(camC3.gameObject.activeInHierarchy == true)
{
if(B3C3 == true && C3D3 == true && C2C3 == true && C3C4 == true)
{
gameOver = true;
}
}
else if(camC4.gameObject.activeInHierarchy == true)
{
if(B4C4 == true && C4D4 == true && C3C4 == true && C4C5 == true)
{
gameOver = true;
}
}
else if(camC5.gameObject.activeInHierarchy == true)
{
if(B5C5 == true && C5D5 == true && C4C5 == true && C5C6 == true)
{
gameOver = true;
}
}
else if(camC6.gameObject.activeInHierarchy == true)
{
if(C6D6 == true && C5C6 == true)
{
if(C6W.GetComponent<BoxCollider>().isTrigger == false && C6B5W.GetComponent<BoxCollider>().isTrigger == false)
gameOver = true;
}
}
else if(camD1.gameObject.activeInHierarchy == true)
{
if(C1D1 == true && D1D2 == true)
{
if(D1W.GetComponent<BoxCollider>().isTrigger == false && D1E2W.GetComponent<BoxCollider>().isTrigger == false)
gameOver = true;
}
}
else if(camD2.gameObject.activeInHierarchy == true)
{
if(C2D2 == true && D2E2 == true && D1D2 == true && D2D3 == true)
{
gameOver = true;
}
}
else if(camD3.gameObject.activeInHierarchy == true)
{
if(C3D3 == true && D3E3 == true && D2D3 == true && D3D4 == true)
{
gameOver = true;
}
}
else if(camD4.gameObject.activeInHierarchy == true)
{
if(C4D4 == true && D4E4 == true && D3D4 == true && D4D5 == true)
{
gameOver = true;
}
}
else if(camD5.gameObject.activeInHierarchy == true)
{
if(C5D5 == true && D5E5 == true && D4D5 == true && D5D6 == true)
{
gameOver = true;
}
}
else if(camD6.gameObject.activeInHierarchy == true)
{
if(C6D6 == true && D5D6 == true)
{
if(D6W.GetComponent<BoxCollider>().isTrigger == false && D6E5W.GetComponent<BoxCollider>().isTrigger == false)
gameOver = true;
}
}
else if(camE2.gameObject.activeInHierarchy == true)
{
if(D2E2 == true && E2E3 == true)
{
if(E2D1W.GetComponent<BoxCollider>().isTrigger == false && E2F3W.GetComponent<BoxCollider>().isTrigger == false)
gameOver = true;
}
}
else if(camE3.gameObject.activeInHierarchy == true)
{
if(D3E3 == true && E3F3 == true && E2E3 == true && E3E4 == true)
{
gameOver = true;
}
}
else if(camE4.gameObject.activeInHierarchy == true)
{
if(D4E4 == true && E4F4 == true && E3E4 == true && E4E5 == true)
{
gameOver = true;
}
}
else if(camE5.gameObject.activeInHierarchy == true)
{
if(D5E5 == true && E4E5 == true)
{
if(E5D6W.GetComponent<BoxCollider>().isTrigger == false && E5F4W.GetComponent<BoxCollider>().isTrigger == false)
gameOver = true;
}
}
else if(camF3.gameObject.activeInHierarchy == true)
{
if(E3F3 == true && F3F4 == true)
{
if(F3W.GetComponent<BoxCollider>().isTrigger == false && F3E2W.GetComponent<BoxCollider>().isTrigger == false)
gameOver = true;
}
}
else if(camF4.gameObject.activeInHierarchy == true)
{
if(E4F4 == true && F3F4 == true)
{
if(F4W.GetComponent<BoxCollider>().isTrigger == false && F4E5W.GetComponent<BoxCollider>().isTrigger == false)
gameOver = true;
}
}
if(gameOver == true) print("You ha
ve been trapped! Game Over"); }
private bool setTimer = false;
void OnGUI()
{
if (gameOver == true)
{
if(setTimer == false)
{
timer = fadeTime;
setTimer = true;
}
color.a = 1 - (timer / fadeTime);
}
else color.a = 0;
GUI.color = color;
GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), blackScreen);
}
IEnumerator MyLoadLevel(float delay, int level)
{
if (gameOver == true)
{
yield return new WaitForSeconds(delay);
Application.LoadLevel(level);
}
}
StartCoroutine(MyLoadLevel(15.0f,0));
}
Sorry, this question seems to come up a lot on the forums - I just haven't worked out what bit I'm doing wrong.
All the best, Laurien
Answer by Uldeim · Nov 06, 2014 at 08:42 PM
It's a little bit hard to tell from your snippet, but it looks like your StartCoroutine is outside all your methods?
Your answer
![](https://koobas.hobune.stream/wayback/20220613170908im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Increment variable over time 4 Answers
Blinking & resource consumption 1 Answer
StartCoroutine gets the arglist type wrong 1 Answer
Invoke isn't working for a function with yield? 2 Answers
Yielding in a loop only as needed? 0 Answers