我正在尝试创建一个倒计时计时器,以便我的玩家在游戏再次开始玩之前购买第二条生命 3 秒。我不确定我需要在下面修复什么才能使其正常工作。目前,所有用户界面都会在应有的时候弹出,倒数计时器文本也会弹出,但游戏继续进行,计时器停留在 3。
public static bool GameOver = false;
public static bool CountDown = false;
public GameObject deathMenuUI;
public GameObject countDownUI;
public int timeLeft = 3;
public Text countDownText;
public float slowness = 10f;
public void Start()
{
PlayerPrefs.SetInt("Score", 0);
Time.timeScale = 1f;
}
public void EndGame()
{
StartCoroutine(DeathScreen());
}
//on death, slow time for one second and open deathscreen UI
IEnumerator DeathScreen()
{
Time.timeScale = 1f / slowness;
Time.fixedDeltaTime = Time.fixedDeltaTime / slowness;
yield return new WaitForSeconds(1f / slowness);
Time.timeScale = 1f;
Time.fixedDeltaTime = Time.fixedDeltaTime * slowness;
deathMenuUI.SetActive(true);
Time.timeScale = 0f;
GameOver = true;
}
//if game is continued, close deathUI and start timer
public void continueGame()
{
deathMenuUI.SetActive(false);
Time.timeScale = 1f;
GameOver = false;
StartCoroutine(LoseTime());
}
private void Update()
{
countDownText.text = ("" + timeLeft);
if (timeLeft <= 0)
{
StopCoroutine(LoseTime());
}
}
IEnumerator LoseTime()
{
while (true)
{
countDownUI.SetActive(true);
CountDown = true;
yield return new WaitForSeconds(1);
timeLeft--;
}
}
}
aluckdog
相关分类