- Home /
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:
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!
Answer by Shiropopi · Jun 20, 2020 at 08:21 AM
@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 : https://www.youtube.com/watch?v=wlo-ZvV3ovg&t
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
}
Your answer
Follow this Question
Related Questions
Error with pause menu script. 0 Answers
Pause menu not working 1 Answer
LeanTween, Problem with slower device when loop create and cancel tween in sequences 0 Answers
How to run DOTween tweens in succession? 0 Answers
C# problem with pause menu 2 Answers