Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Pausing Dotween

Discussion in 'Animation' started by Nadoc_NewLedge, Sep 30, 2021.

  1. Nadoc_NewLedge

    Nadoc_NewLedge

    Joined:
    Nov 26, 2020
    Posts:
    19
    hello
    I'm using DoTween in my project and trying to implement a pause system, which DoTween seems to ignore.
    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using DG.Tweening;
    4. [RequireComponent(typeof(DOTweenAnimation))]
    5. public class DoAffactByPause : MonoBehaviour
    6. {
    7.  
    8.     DOTweenAnimation _anim;
    9.     public Transform _transform;
    10.     bool paused = false;
    11.  
    12.     // Start is called before the first frame update
    13.     void Awake()
    14.     {
    15.         _transform=transform;
    16.         _anim = GetComponent<DOTweenAnimation>();
    17.     }
    18.     void Update()
    19.     {
    20.         if (PauseManager.Pause && !paused)
    21.         {
    22.             Pause();
    23.         }
    24.         else if (!PauseManager.Pause && paused)
    25.         {
    26.             Unpause();
    27.         }
    28.     }
    29.  
    30.     void Pause()
    31.     {
    32.         DOTween.Pause(_transform);
    33.         paused = true;
    34.     }
    35.     void Unpause(){
    36.         DOTween.Play(_transform);
    37.         paused = false;
    38.     }
    39. }
    40.  
    the script is implemented on the same transform in which the animation runs.
    What did I miss?

    Edit: I did manage to stop it when using the obvious Time.timescale=0.
    However it would like a solution that doesn't affect the whole scene necessarily.
     
    Last edited: Oct 1, 2021