欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Unity帧动画

程序员文章站 2024-03-25 20:05:10
...

Unity帧动画

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class FrameAnimation : MonoBehaviour
{
public Sprite[] pictures;
public bool loop=false;
float frequence = 0.1f;
float calTime = 0f;
int index = 0;
Image img;
// Start is called before the first frame update
void Start()
{
img = GetComponent();
img.sprite = pictures[index];
}

// Update is called once per frame
void Update()
{
    if (Time.time - calTime>frequence)
    {   
        if (index==pictures.Length-1)
        {
            index = 0;
        }
        img.sprite = pictures[++index];
        calTime = Time.time;
    }       
}

}