Question by
bathorsthroat · Feb 05, 2016 at 01:42 PM ·
error messageapplication.loadlevelgameover
How to change level after my game over screen appears? C#
Hello, I am creating game with use of a master script. Inside my Game Over Script I would like for the first level to be loaded Blank number of seconds after the Game Over Panel is set to true. When I try this my "void TurnOnGameOverPanel()" gives and error "cannot be an iterator block because `void' is not an iterator interface type". Can anyone help me out on this one? Thanks
P.S. I know my script is correct but it's my best shot at it and I'd stuck. It's in C# by the way. :)
public class GameManager_Frank_GameOver : MonoBehaviour
{
private GameManager_Frank_Master gameManagerMaster;
private Player_Master playerMaster;
public GameObject panelGameOver;
void OnEnable()
{
SetInitalReferecnes();
{
gameManagerMaster.GameOverEvent += TurnOnGameOverPanel;
}
}
void OnDisable()
{
gameManagerMaster.GameOverEvent -= TurnOnGameOverPanel;
}
void SetInitalReferecnes()
{
gameManagerMaster = GetComponent<GameManager_Frank_Master>();
}
void TurnOnGameOverPanel()
{
if (panelGameOver != null)
{
panelGameOver.SetActive(true);
yield return new WaitForSeconds(6);
Application.LoadLevel(1);
}
}
}
}
Comment
Best Answer
Answer by maxartz15 · Feb 16, 2016 at 06:09 PM
you have to use a IEnumerator for waitforseconds:
IEnumerator TurnOnGameOverPanel()
{
if (panelGameOver != null)
{
panelGameOver.SetActive(true);
yield return new WaitForSeconds(6);
Application.LoadLevel(1);
}
}
And you have to start it:
StartCoroutine(TurnOnGameOverPanel());
Link info: http://docs.unity3d.com/ScriptReference/Coroutine.html http://docs.unity3d.com/Manual/30_search.html?q=IEnumerator