Creating a Pause Menu with DOTween

Hello,
I’m using DOTween to create a more interesting UI compared to before where I just turn gameObjects on/off. In my game that I’m making, I have a pause menu where you press a button and it pauses the game.


What I want to happen is that when I press my UI button, it “plays” my DOTween animation and when the animation is complete, it pauses the game, this is my UI:
154339-2020-03-16-15-08-10.gif


The “animation” works the way I want it to, however, the game isn’t “paused”, this is a snippet of the code that I use to do the “animation”:

    public void EnterPauseMenu()
    {
        GameUI.DOAnchorPos(-1100, 0), 0.75f);
        PauseMenu.DOAnchorPos(new Vector2(0, 0), 0.75f);
        BackgroundImage.DOFade(0.25f, 0.75f);
    }

This is how it typically looks like, I put my DOTween stuff inside a method and in the Editor, on a Buttons on click event, I set it for example to the method above.

In an another class I have a method that pauses the game by setting Time.timeScale to zero, I’m wondering how I can pause the game after the “animation” is done.


Thanks for your time!

@functionSam
DOTween have a function for that type of case.
Just call OnComplete at the end of one of your tween.
Then put inside a method to call a event to communicate that the tweening is done.
Pass the event to your pausegame method and done.

Tuto for events : Communicating with Events in Unity - YouTube

Something like that :

using System; // You need this one for calling an Action
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;

public static event Action<bool> OnAnimEnding = delegate { };

public void EnterPauseMenu()
     {
         GameUI.DOAnchorPos(-1100, 0), 0.75f);
         PauseMenu.DOAnchorPos(new Vector2(0, 0), 0.75f);
         
         // Call OnComplete
         BackgroundImage.DOFade(0.25f, 0.75f).OnComplete(AnimEnd);
     }

public void AnimEnd()
     {
         OnAnimEnding(true); // Invoke the event
     }