TaiZhouCangChu_VRanime/Assets/动画/Scripts/LoopAnimation.cs

30 lines
667 B
C#

using UnityEngine;
public class LoopAnimation : MonoBehaviour
{
public string animationStateName;
private Animator animator;
void Start()
{
animator = GetComponent<Animator>();
if (animator == null)
{
Debug.LogError("Animator component not found on the object.");
}
}
public void ResetAnimationPlay()
{
if (animator != null && !string.IsNullOrEmpty(animationStateName))
{
animator.Play(animationStateName, -1, 0f);
}
else
{
Debug.LogError("Animation state name is not set or Animator is null.");
}
}
}