Unity2D: Frost effect Time.timescale = 0
I downloaded this package ("Frost Effect by Steven Craeynest") on Unity Asset Store and altered using DOTween to make the effect coming like an animation and only happens once I click on my frost button (button 1), I first disabled the frost button (button 1) in my inspector before playing the game, I 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 the first time, but when my character dies and I click on button 2 again to use the frost effect button again, the frost effect work as it comes in but just when it's about to come out it stops everything (time.timescale = 0), until I press my pause button and the resume button then the frost effect animation comes out like normal. It doesn't only happens when I click to activate my frost button again, but it also happens when you play the game, then die and restart it, when you click on button 2 to activate the frost effect button it does the same thing as I mentioned above. Please if anyone can help that would be great. :)
This is video will show you what I am dealing with. Anyway this is my script:
using UnityEngine;
using System.Collections;
using DG.Tweening;
using UnityEngine.UI;
public class FrostScriptButton : MonoBehaviour {
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 ++;
}
public void MinusFrostOrb() {
PowerUpScript.FrostEffect = PowerUpScript.FrostEffect - 1;
}
// Use this for initialization
void Start () {
previousTimeScale = Time.timeScale;
}
public void Activate ()
{
frostbutton.SetActive (true);
}
public void CreateFrost ()
{
//if (frostActive) {
// yield break;
//}
//if (!isCoroutineStarted) {
//isCoroutineStarted = true;
if(timesActivated < buttonCount)
{
timesActivated++;
GameObject.Find ("Main Camera").GetComponent<FrostEffect> ().enabled = true;
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);
}
}
}
Thank you. :)