问题描述
如图当挂载animation对象反复active inactive时(常用于智驾可视化渲染),会出现动画重置,我期望在隐藏时动画也能在后台播放时间,使整个过程能流畅衔接
解决方案:
将下面脚本挂载到对象上,代码逻辑很简单,不多赘述。
public class AnimationTest : MonoBehaviour {
private Animation ani;
private AnimationState mState;
// Start is called before the first frame update
void Awake() {
ani = this.GetComponent<Animation>();
mState = ani["YourAnimanClicpName"];
ani.Play();
}
private void OnEnable() {
mState.time = Time.time % mState.length;
ani.Play("YourAnimanClicpName");
}
}