Unity幀動畫

等我買個橘子丶發表於2020-10-12

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;
    }       
}

}

相關文章