UniversalViewer/Assets/Scripts/AnimatorLooper.cs

33 lines
684 B
C#
Raw Normal View History

2024-04-21 22:38:26 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AnimatorLooper : MonoBehaviour
{
Animator anim;
// Start is called before the first frame update
void Start()
{
anim = GetComponentInChildren<Animator>();
if(anim == null)
{
Destroy(this.gameObject);
}
}
// Update is called once per frame
void Update()
{
if(anim.GetCurrentAnimatorStateInfo(0).normalizedTime > 1)
{
anim.Play(anim.GetCurrentAnimatorStateInfo(0).fullPathHash, 0, 0);
}
}
public void Toggle()
{
anim.speed = anim.speed == 1 ? 0 : 1;
}
}