Timescale Pause Combined with Animated UI
the passed days i've been creating my game, and set up the hole game with GUI. now i switched to UI since it is super cool stuff. Now i stumbled upon the fact that when i pause the game, i use Time.timeScale = 0.0F; so everything freezes. it didn't effect the GUI buttons. now i changed everything to UI, and the animation freezes allong with the rest of the game, which is normal, but how do i have to work arround it? i did stumble upon something called "realtimeSinceStartup" but i have no idea if it is a good salution or how to set it up. thanks in advance.
also, i managed all the menus in 1 animator which starts at the start of the scene. i could change it, but just so you know.
You could try using iTween to animate the elements with "ignoreTimeScale" property.
thanks for the awnser, but i dont want to use external stuff if the existing animation is very good in unity itself. I cant be the only one who has stubled upon this problem and i cant imagine that there wouldn't be a simple fix within unity itself. so sorry and thanks?
See here. It shows that the only thing not paused is realtimeSinceStartup and so is the best thing to use for things that ignore the time scaled deltaTime.
This forum thread talks about how to go about doing that. For book-keeping I have added the relevant snippet of code that Tuhljin wrote.
public class Timekeeper : $$anonymous$$onoBehaviour {
private float prevRealTime;
private float thisRealTime;
void Update () {
prevRealTime = thisRealTime;
thisRealTime = Time.realtimeSinceStartup;
}
public float deltaTime {
get {
if (Time.timeScale > 0f) return Time.deltaTime / Time.timeScale;
return Time.realtimeSinceStartup - prevRealTime; // Checks realtimeSinceStartup again because it may have changed since Update was called
}
}
}
thank you for the comment. but sadly enough, my problem is not that i cant call anything. the animations of the menu's freeze along with the timescale. which is completely normal and understandable, but i don't want it! meanwhile i found this http://answers.unity3d.com/questions/32753/ideas-for-animating-while-paused.html but i cant seem to get it working..
Answer by BeB_Wir3 · May 07, 2015 at 02:03 PM
I found the salution! I found it here http://www.adventurecreator.org/forum/discussion/2257/pause-menu-not-affecting-the-menu-animation
and it accualy pritty simple, and i cant imagine i didn't find this sooner.. salution, as a quote!
SilverVoo February 11 edited February 11
If you are using "time.timeScale = 0" for pause, then this must help;
Choose button/canvas/etc that you need -> Animator -> Update Mode -> Unscaled Time
hope it will help anyone.
Spent hours looking at various scripts to manage this! All along a simple option was there!!!
Thanks
It took several googles and multiple incorrect answers before I found this perfect answer! Animated UI while game is paused. Thanks!
well, i'm not using the animations for the UI button but just color transition, how can i fix the problem with time scale??? :(
One option would be to find another way of pausing your game. If you want some things to be affected by time and others not to be, then taking complete control of the issue yourself may be the best way to go.
Your answer
Follow this Question
Related Questions
How to create a game map? 0 Answers
Unity animator not playing animation, collider problems 0 Answers
Control UI Input Field entirely with code? 1 Answer
How to know the animator's bones 0 Answers