Issue with Pause Script

I successfully wrote a script that pauses the game by essentially setting the Time.timeScale to 0. However, with this script, I also enable a pause menu UI. I want to animate the UI to move slightly to the right when I hover, but since the Time.timeScale is 0, is this even possible to do while paused?

Script below:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Pause : MonoBehaviour {
    bool pauseState = false;
    public GameObject pauseMenu;

    void Update()
    {
        if (pauseMenu.activeSelf)
        {
            pauseState = true;
            //Debug.Log("UpdateActive");
        }
        else
        {
            pauseState = false;
            //Debug.Log("UpdateFalse");
        }

        if (Input.GetKeyDown("escape") && pauseState == false)
        {
            Time.timeScale = 0;
            pauseMenu.SetActive(true);
            //Debug.Log("pauseState = true");

        }
        else if (Input.GetKeyDown("escape") && pauseState == true)
        {
            Time.timeScale = 1;
            pauseMenu.SetActive(false);
            //Debug.Log("pauseState = false");
 
        }
    }

    public void ResumeGame()
    {
        Time.timeScale = 1;
        pauseMenu.SetActive(false);
        //Debug.Log("pauseState = false");

    }

    public void QuitGame()
    {
        Application.Quit();
        Debug.Log("Game Quit Successful!");

    }


}

Note: Wasn’t sure if Scripting or UI was the best place to post this, but since this involves a pause script I thought this forum would be the safer option.

There is Time.unscaledDeltaTime and specifically for an Animator you can set its updateMode to AnimatorUpdateMode.UnscaledTime .

I’m sorry, but I’m a bit new at UI scripting/animation. How would I implement this? Would I just basically swap out Time.timescale in my script with AnimatorUpdateMode.UnscaledTime, or is there further configuration that I would have to do?

I figure out how to do it more easy, without scripting, just go where you have the animator component and at Update Mode, change to Unscaled Time.

That was Pengocat ideea but he don’t explain to you how to do it.
P.S: I didn’t try it, so i don’t know if is working like you want.

If you are using an Animator component you can set it in the inspector like @ARares mentions above. You can set it in code like the following:

    public Animator anim;

    // Start is called just before any of the Update methods is called the first time
    void Start()
    {
        anim.updateMode = AnimatorUpdateMode.UnscaledTime;
    }
1 Like