- Home /
How can I call Application.LoadLevel in a Coroutine?
Hello, I am currently trying to fix my death screen. Right now, when the player dies, some death text will come up on my game. But because the game is quite frantic and how I have set the death screen up, the user misses vital information due to tapping on the phone screen and essentially skipping it.
Here is my code.
public class Game_Controller : MonoBehaviour {
private GameObject player;
public GameObject onDeathInterface;
public GameObject onAliveInterface;
public GUIText retryText;
void Start()
{
player = GameObject.FindWithTag("Player");
if(player == null)
{
StartCoroutine( PlayerRetry(4.0f));
}
}
void Update()
{
if(player == null)
{
onDeathInterface.SetActive(true);
onAliveInterface.SetActive(false);
}
}
IEnumerator PlayerRetry(float waitTime)
{
yield return new WaitForSeconds(waitTime);
{
retryText.text = "Tap To Retry!";
if(Input.touchCount == 1)
{
Application.LoadLevel("Level 1");
}
}
}
}
As you can see, I want the coroutine to start 4 seconds after the player has died. The text displays fine in for seconds but I cannot reload the level. Could anyone help?
Thank you in advance!
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Adding Android Mobile Controller to Unity Project 0 Answers
Why doesn't my game update on Android Tablet unless I'm clicking the screen? 1 Answer
Gamplay Android 0 Answers
How to integrate Android Widgets? 0 Answers