The game is not freezed

‘’’
public class DeathHandler : MonoBehaviour
{
[SerializeField] private Canvas gameOverCanvas;

private void Start()
{
    gameOverCanvas.enabled = false;
}

public void HandleDeath()
{
    gameOverCanvas.enabled = true;
    Time.timeScale = 0;
    Cursor.lockState = CursorLockMode.None;
    Cursor.visible = true;
}

}’’’

‘’'public class SessionLoader : MonoBehaviour
{

private Scene currentScense;


private void Start()
{


    currentScense = SceneManager.GetActiveScene();
    Debug.Log(currentScense.buildIndex);
}



public void ScenseReload()
{
    Time.timeScale = 1;

    SceneManager.LoadScene(currentScense.buildIndex);

    Debug.Log("reload scene");
}

public void QuitGame()
{
    Application.Quit();
    Debug.Log("quit");
}

}’’’

when the time.tiemscale =0 is triggered. the system is freezed. but it i comment the tiem.tiemscale =1 in the scense reload, the player still can move up, move down and turn around. the player still can shoot and destroyt the enemy. but all effect and enemy movement is freezed.
i tried to un-comment the time.timescale =1, i got the same result as commented the time.timescale = 0;
can you give any suggestion?

Hi Zhjp,

First of all, add a few Debug.Logs to your code to see if the HandleDeath method gets called and if Time.timeScale gets set to 0. Also log the value of Time.timeScale into your console to see if it did get indeed set to 0.

Hey, many thanks for your answer. i found the problem when the time.timescale is 0, but the character is still moving. becasue the update method in character controller script is still working. now i add some if statement to pasue the character movement in script. but when the reload scene is triggered, the time.tiemscale is 1, but everything is still paused. the debug.log is output time.timescale is 1.

public class SessionLoader : MonoBehaviour
{

private Scene currentScense;


private void Start()
{


    currentScense = SceneManager.GetActiveScene();
    Debug.Log(currentScense.buildIndex);
}


private void Update()
{
    if (Input.GetKeyDown(KeyCode.P))
    {
        Time.timeScale = 1;
    }
}
public void ScenseReload()
{


    SceneManager.LoadScene(0);

    Time.timeScale = 1;
    Debug.Log("timeScale= " + Time.timeScale);
    Debug.Log("reload scene");
}

public void QuitGame()
{
    Application.Quit();
    Debug.Log("quit");
}

}

sorry i forgot my code. i add the new condition in update method. if i press key p, the system can re-working.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms