- Home /
mecanim animation while timescale is zero
Hi there, In pause menu, we set timescale to zero. It causes severe problem when we want some sprite animations for buttons. I am using mecanim for GUI sprite animations. So when I go to pause menu, every animation just stops. I do not want that. I want every animation in pause menu to play, even though timescale is zero. Is there any solution for this problem? Thanks.
though not a solution by mecanim, I think we can do sprite animation while we are in pause menu. The way I thought was: having an array of sprites and an script attached to it the button gameobject. When we are in pause menu, we can turn renderer on(vice versa). and in script we update sprite index according to elapsed time. Lets say for a 4fps animation having 4 sprites. Each one must remain 1/4=0.25seconds. So we constantly check the interval.(Here we trace time by Time.realtimeSinceStartup). When interval passed, we update renderer's sprite property by changing index. I havn't test it yet but my sixth sense tells me it is gonna work. What do you think guys?
I can't upvote but this is an issue for me too. Nothing posted on the web works, nothing from the Unity docs works.
maul, here is the class I developed for this purpose.
copy the codes to a C# script, name the script as the class name. Lets say you need a blinking button. So you have made four sprites of same hight-width(important for visually aesthetic quality). Now you put the array size of "sprites" to 4. You assign your sprite sequentially. You can adjust fps-turnOn-turnOff-pause$$anonymous$$enukey etc if necessary. Boom!
using UnityEngine;
using System.Collections;
public class pauseAnim : $$anonymous$$onoBehaviour {
public Sprite[] sprites;
public float fps=4;
public $$anonymous$$eyCode turnOn$$anonymous$$ey=$$anonymous$$eyCode.A;
public $$anonymous$$eyCode turnOff$$anonymous$$ey=$$anonymous$$eyCode.D;
public $$anonymous$$eyCode pause$$anonymous$$enuButton=$$anonymous$$eyCode.Escape;
private float interval;
private float activeTime;
private int index;
// Use this for initialization
void Start () {
gameObject.renderer.enabled=false;
}
// Update is called once per frame
void Update () {
if(Input.Get$$anonymous$$eyDown(pause$$anonymous$$enuButton)){Time.timeScale=0;}
interval=1/fps;
if(Input.Get$$anonymous$$eyDown(turnOff$$anonymous$$ey))
{
gameObject.renderer.enabled=false;
}
if(Input.Get$$anonymous$$eyDown(turnOn$$anonymous$$ey)) //we are in pause menu
{
activeTime=Time.realtimeSinceStartup;
if(Time.timeScale==0)
{gameObject.renderer.enabled=true;}
gameObject.GetComponent<SpriteRenderer>().sprite=sprites[0];
index=0;
}
if(gameObject.renderer.enabled==true)
{
if(Time.realtimeSinceStartup>=(activeTime+interval))
{
activeTime=Time.realtimeSinceStartup;
gameObject.GetComponent<SpriteRenderer>().sprite=sprites[index+1];
index=index+1;
if(index==(sprites.Length-1))
{
index=0;
}
}
}
}
}
Answer by flyingbanana · Nov 21, 2015 at 08:58 PM
Your answer
Follow this Question
Related Questions
Mecanim mirror mode is doing...things. 0 Answers
Sharing some but not all animator states between characters 0 Answers
Is there a way to abstract sprite from animation clip? 0 Answers
Animation Preview 0 Answers