Keep button animation and Button Audio while pause and after pause?

Ok, so i have a game that im making that uses interactive buttons. On the screen i have score, time, and an exit button. I also have numerous buttons alligned on the screen that the player clicks to define which color is different. each button has an animator and an audio. Push the button and it plays an animation and a click sound. If you click the Exit button a message window pops up asking if you would like to exit the game. At this point the Timer pauses. If you hit cancel it goes back to the game level. The timer then continues but the button animations and the sound doesnt work anymore…? Below is my scripts i use. As well as the approaches i took to fix the problem. Any help would be awesome!! Thanks.

The StopTime Script

function OnGui() {
   
        doPauseToggle();
    }
   

function doPauseToggle() {
    // here we check to see if we are running at a time scale above 0
    if(Time.timeScale<0){
        // time scale is above zero, so we need to pause the game here
        pauseGame();
    }
}
function pauseGame () {
    // set scale at which time passes to 0, freezing time(!)
    Time.timeScale=0;
   AudioListener.pause = false;
   
}

StartTime Script

        doPauseToggle();
    }
   

function doPauseToggle() {
   
    if(Time.timeScale<0){
       
        unPauseGame();
    }
}

function unPauseGame () {
  
    Time.timeScale=1;
    AudioListener.pause = false;
    Animator.speed = false;
   
}

CountDownTimer Script

using System.Collections;
using UnityEngine.UI;




public class CountDownTimer : MonoBehaviour {


    public float startingTime;

    private Text theText;





    void Start () {


        theText = GetComponent<Text>();
    }

    void Update (){

        //response = 0;
        float startTime = Time.time;

        startingTime -= Time.deltaTime;

        if (startingTime <= 0) {
            Destroy (gameObject, 16);



                Application.LoadLevel("Game_Over");
               

        }

        theText.text = "" + Mathf.Round (startingTime);
    }
}

MenuManager Script that handles switching to another menu as well as other things

using System.Collections.Generic;
using UnityEngine;

public class MenuManager : MonoBehaviour
{


    [SerializeField]
    private string m_animationPropertyName;

    [SerializeField]
    private GameObject m_initialScreen;

    [SerializeField]
    private List<GameObject> m_navigationHistory;

    public void GoBack()
    {
        if (m_navigationHistory.Count > 1)
        {
            int index = m_navigationHistory.Count - 1;
            Animate(m_navigationHistory[index - 1], true);

            GameObject target = m_navigationHistory[index];
            m_navigationHistory.RemoveAt(index);
            Animate(target, false);
        }
    }

    public void GoToMenu(GameObject target)
    {

        //Time.timeScale = 0;


        if (target == null)
        {
            return;
        }

        if (m_navigationHistory.Count > 0)
        {
            Animate(m_navigationHistory[m_navigationHistory.Count - 1], false);
        }

        m_navigationHistory.Add(target);
        Animate(target, true);
        AudioListener.pause = false;

    }

    private void Animate(GameObject target, bool direction)
    {
        if (target == null)
        {
            return;
        }

        target.SetActive(true);

        Canvas canvasComponent = target.GetComponent<Canvas>();
        if (canvasComponent != null)
        {
            canvasComponent.overrideSorting = true;
            canvasComponent.sortingOrder = m_navigationHistory.Count;
        }

        Animator animatorComponent = target.GetComponent<Animator>();
        if (animatorComponent != null)
        {
            animatorComponent.SetBool(m_animationPropertyName, direction);
        }
    }

    private void Awake()
    {
        m_navigationHistory = new List<GameObject>{m_initialScreen};

    }

    public void QuitApplication()
    {
        Application.Quit();
    }


}

Now the timer works as it should. When i click the exit button the timer stops using the stop time script that is attached to the Exit Button. Then when you Exit the message panel the time starts again. Yet the buttons no longer work. I cant click the blue boxes in the game. See the image for instance.
If you look at the Start and Stop Time Scripts youll see i added

  • AudioListener.pause = false;

Which doesnt work. and i tried

  • Animator.speed = false;

Which also doesnt work.

2181878--144568--Screen.PNG

If you have Animation transitions in your canvas, be sure to set the Update Mode of your Animator to “Unscaled Time”

1 Like

I set all button animations to Unscaled Time.

2181954--144575--animator.PNG

Im going to upload a video to show you exactly the problem.

Problem Fixed. Both Canvases were in a main canvas. the message canvas was fine, but the level1 canvas needed to be deleted. so i just drug out the level1 items from the canvas and it worked.