Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Unity script that allows for animation while Time.timeScale = 0. See http://www.asteroidbase.com/?p=569 for context.
using UnityEngine;
using System.Collections;
public class TimeScaleIndependentAnimation : TimeScaleIndependentUpdate
{
//inspector fields
public bool playOnStart;
public string playOnStartStateName;
//private fields
AnimationState currentState;
System.Action currentCompletionHandler;
float elapsedTime;
bool playing;
void Start()
{
if(playOnStart)
{
Play(playOnStartStateName);
}
}
protected override void Update()
{
base.Update();
if(playing)
{
elapsedTime += deltaTime;
currentState.normalizedTime = elapsedTime / currentState.length;
if(elapsedTime >= currentState.length)
{
playing = false;
if(currentState.wrapMode == WrapMode.Loop)
{
Play(currentState.name);
}
else
{
if(currentCompletionHandler != null)
{
currentCompletionHandler();
}
}
}
}
}
public void Play(string stateName, System.Action completionHandler = null)
{
elapsedTime = 0f;
currentState = animation[stateName];
currentState.normalizedTime = 0;
currentState.enabled = true;
currentState.weight = 1;
currentCompletionHandler = completionHandler;
playing = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.