创建以下脚本组件,建议绑定到UI所在Canvas
using UnityEngine;
using UnityEngine.UI;public class UIFrameAnimation : MonoBehaviour
{public Image image; // 绑定 UI Imagepublic Sprite[] frames; // 帧动画的图片数组public float frameRate = 0.1f; // 每帧的时间private int currentFrame;private float timer;void Update(){if (frames.Length == 0) return;timer += Time.deltaTime;if (timer >= frameRate){timer = 0;currentFrame = (currentFrame + 1) % frames.Length;image.sprite = frames[currentFrame];}}
}