1
\$\begingroup\$

I downloaded this package ("Frost Effect by Steven Craeynest") on Unity Asset Store and altered it into making the effect happen once I click on a button (button 1), I first disabled the frost button (button 1) in my inspector before playing the game and created another button (button 2) to activate the frost button(button1). However I'm having issues with the frost effect. You see when I click on button 2 to activate the frost button (button 1) frost effect works for a bit but then stops at delayBeforeUnfreeze like time.timescale is equaled to 0 and the only way of making time.timescale is equaled to 1 is by pressing my pause button and clicking the resume button. Anyway this is my script:

private FrostEffect frost;
float duration = 0.2f;
float delayBeforeUnfreeze = 0.34f;
private float previousTimeScale;
public GameObject frostbutton;
public int buttonCount = 0;
int timesActivated =  0;

public void Check() {
    buttonCount ++;
}

// Use this for initialization

void Start () { 
    previousTimeScale = Time.timeScale;
}

public void Activate ()
{
    frostbutton.SetActive (true);
}
public void CreateFrost ()
{
    if(timesActivated < buttonCount)
    {
        timesActivated++;

        GameObject.Find ("Main Camera").GetComponent<FrostEffect> ().enabled = true;
        //Slow timescale
        Time.timeScale = 0.06f;
        //Freeze time effect
        DOTween.To (x => FrostEffect.FrostAmount = x, 0.0f, 0.34f, duration)
    .OnComplete (() => { 
            //Unfreeze tween effect
            DOTween.To (x => FrostEffect.FrostAmount = x, 0.34f, 0f, duration)
                .SetDelay (delayBeforeUnfreeze);

            //Set timescale back to previous.
            Time.timeScale = previousTimeScale;
        });
    }
}

} Thank you. :)

Second Edit

This is my panel animation script:

public void DisableBoolAnimator(Animator anim)
{
    anim.SetBool ("Shown", false);
}

public void EnableBoolAnimator(Animator anim)
{
    anim.SetBool ("Shown", true);
}

This Youtube link will show you what my panel animation looks like: 31:47. Thank you. :)

\$\endgroup\$
1
\$\begingroup\$

Taking a quick scan of the DOTween documentation, it looks like by default it uses Unity's time / deltaTime values to advance the tween.

That means when you set timeScale to zero, you not only stop the game, you stop the tween too. Since the tween never finishes, it never runs the OnComplete method that restores the previousTimeScale.

Fortunately, this is literally the third item covered in the library's Frequently Asked Questions:

Snipped from the DOTween FAQ, reproduced in text below.

How to ignore Unity's Time.timeScale when tweening?

Just chain the SetUpdate method to a tween, passing a value of TRUE to the isIndependentUpdate parameter. transform.DOMoveX(2, 1).SetUpdate(true);

So, it looks like your code would become something like this:

DOTween.To (x => FrostEffect.FrostAmount = x, 0.0f, 0.34f, duration)
    .OnComplete (() => { 
        //Unfreeze tween effect
        DOTween.To (x => FrostEffect.FrostAmount = x, 0.34f, 0f, duration)
            .SetDelay (delayBeforeUnfreeze);

        //Set timescale back to previous.
        Time.timeScale = previousTimeScale;
    })
    .SetUpdate(true);
\$\endgroup\$
  • \$\begingroup\$ Thank you for the reply, but it's still doing the same thing. I think that it has to do with the Slide panel animation, this panel animation slides in and it contains the the button that activates my frost button, please look at my second edit above. Thank you again. :) \$\endgroup\$ – Jessca Stone Sep 2 '16 at 6:24
  • \$\begingroup\$ This is video will show you what I am dealing with \$\endgroup\$ – Jessca Stone Sep 3 '16 at 11:54

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.