Question by
danny1111 · Feb 21, 2016 at 10:41 PM ·
c#yieldwaitforseconds
WaitForSeconds in c# not working
Hi, my code stops when the 3 shows up. I think there's something wrong with the yield line. Please help.
using UnityEngine;
using System.Collections;
public class PauseScript : MonoBehaviour {
public GameObject pauseBackground;
public GameObject pauseButton;
public GameObject playButton;
public GameObject coinText;
public GameObject scoreText;
public GameObject unpauseCountdown;
public static int number=3;
public void Pause(){
pauseBackground.SetActive(true);
playButton.SetActive(true);
pauseButton.SetActive(false);
coinText.SetActive(false);
scoreText.SetActive(false);
for(int i=0;i<ClickController.cubes.Length;i++){
ClickController.cubes[i].SetActive(false);
}
Time.timeScale=0;
ClickController.onPause=true;
}
public void Unpause(){
pauseBackground.SetActive(false);
playButton.SetActive(false);
pauseButton.SetActive(true);
coinText.SetActive(true);
scoreText.SetActive(true);
for(int i=0;i<ClickController.cubes.Length;i++){
ClickController.cubes[i].SetActive(true);
}
StartCoroutine ("countdown");
}
public IEnumerator countdown(){
Debug.Log (2);
unpauseCountdown.SetActive(true);
unpauseCountdown.GetComponent<TextMesh>().text=number.ToString();
number--;
yield return new WaitForSeconds(1);
StartCoroutine ("countdown1");
}
public IEnumerator countdown1(){
Debug.Log (2);
unpauseCountdown.SetActive(true);
unpauseCountdown.GetComponent<TextMesh>().text=number.ToString();
number--;
yield return new WaitForSeconds(1);
StartCoroutine ("countdown2");
}
public IEnumerator countdown2(){
Debug.Log (2);
unpauseCountdown.SetActive(true);
unpauseCountdown.GetComponent<TextMesh>().text=number.ToString();
number--;
yield return new WaitForSeconds (1);
StartCoroutine ("countdown3");
}
public IEnumerator countdown3(){
yield return new WaitForSeconds (1);
Debug.Log (3);
Time.timeScale = 1;
unpauseCountdown.SetActive(false);
ClickController.onPause = false;
number = 3;
}
}
Comment