0
\$\begingroup\$

I'm relatively new to Unity, and I've been having a very difficult time getting the legacy animations to run in unscaled time. I need to pause my game, and as soon as it pauses, I need to have my boxes for the pause screen come in from the side. This sort of works if I use an IEnumerator, but I have to hard-code exactly how long it will take for the animation to come in (.333f seconds) and the game will not pause until the animation fully shifts in.

The major problem with this is that I need to use more moving animations while the game is paused that will be called using the onClick() methods in the pause game's buttons. Think of my pause menu as somewhat like an old-school RPG's menu like Final Fantasy but with moving GUI animations. Now, I know that unscaled time is the key to solving this issue, but every explanation I've found online seems to involve the Animator which refuses to work with the legacy? animations. Either that, or the code they're using makes little sense to me because it may be above my level of comprehension. Here is what I have as it stands (*note that I have some deltaTime and _lastframetime code but I have no idea how to make use of it):

// Update is called once per frame
void Update () {
    deltaTime = Time.realtimeSinceStartup - _lastframetime;
    _lastframetime = Time.realtimeSinceStartup;

    //Press T or Tab to pause the game
    if (Input.GetKeyDown(KeyCode.T) || Input.GetKeyDown(KeyCode.Tab)) {
        //If not currently paused, then stop time and show the GUI
        if (!pauseGame) {
            Debug.Log("Tab/T properly pressed to pause game.");
            pauseGame = true;
            showGUI = true;
            StartCoroutine(Wait(.333f)); //IEnumerator Wait, then stops
        }else if (pauseGame){
            Debug.Log("Tab/T properly pressed to UNpause game.");
            Time.timeScale = 1;
            pauseGame = false;
            showGUI = false;
        }

        //If we are to show the GUI, play the start animation; otherwise, the exit one
        if (showGUI == true) {
            //startMenuCanvas.animation.
            startMenuCanvas.animation.Play ("pause_menu_anim1");
        } else {
            startMenuCanvas.animation.Play ("pause_menu_anim1_exit");
        }
    }
}

IEnumerator Wait(float seconds){
    Debug.Log ("Waited for " + seconds + " seconds.");
    yield return new WaitForSeconds(seconds);
    Time.timeScale = 0;
}

Ideally, I want to remove the IEnumerator and be able to call the Play animations using unscaled time. Is there any simple way to do this that I am missing?

\$\endgroup\$
2
\$\begingroup\$

enter image description here

I've faced similar issue, and after digging around I found this. Hopefully, its useful for you

ref: http://answers.unity3d.com/questions/217351/animations-ignore-timescale.html

\$\endgroup\$
  • \$\begingroup\$ This is NOT legacy system \$\endgroup\$ – tc07 Sep 25 '16 at 10:06
0
\$\begingroup\$

Use Finite State Machine to switch between various states. Easy way around is to create a flag to control what things are updated when game is paused. Alternatively if you want to use Time.timeScale you can set up your own custom deltaTime by taking difference of previously recorded Time.realtimeSinceStartup from the current one.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.