- Home /
Question by
AnishIsBosss · Aug 09, 2021 at 04:50 PM ·
2d gamepause menupause game
When I pause during the countdown the game does not freeze PLS SOMEONE HELP.
When I press the pause button during the countdown to start the game, the game goes to the pause menu but does not freeze the game.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//This is the countdown script
public class DelayedStartScript : MonoBehaviour
{
public GameObject countDown;
// Start is called before the first frame update
void Start()
{
StartCoroutine("StartDelay");
}
// Update is called once per frame
void Update()
{
}
IEnumerator StartDelay ()
{
Time.timeScale = 0;
float pauseTime = Time.realtimeSinceStartup + 4f;
while (Time.realtimeSinceStartup < pauseTime)
yield return 0;
countDown.gameObject.SetActive(false);
Time.timeScale = 1;
}
}
Comment
Answer by StringAtlas · Aug 15, 2021 at 03:28 AM
Time.realtimeSinceStartup takes the time even when pausing. Instead, you can use Time.time
Answer by EnergyTeamDummies · Aug 15, 2021 at 07:21 AM
[Time.timescale] stop the fixedupdate but update and coroutines still running, you need create a variable and use it as a traffic light.