mirror of
https://github.com/CoonS2/Unity2DProject.git
synced 2026-02-04 12:13:22 +09:00
42 lines
860 B
C#
42 lines
860 B
C#
using System;
|
|
using UnityEngine;
|
|
|
|
public class AnimationController : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private SpriteRenderer spriteRenderer;
|
|
|
|
[SerializeField]
|
|
private Sprite[] sprites;
|
|
|
|
[SerializeField]
|
|
private float waitTick = 1;
|
|
|
|
private int index;
|
|
|
|
private float currentTime;
|
|
|
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
currentTime = Time.realtimeSinceStartup;
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if(Time.realtimeSinceStartup - currentTime < waitTick)
|
|
return;
|
|
|
|
currentTime = Time.realtimeSinceStartup;
|
|
|
|
if (index >= sprites.Length)
|
|
{
|
|
index = 0;
|
|
}
|
|
|
|
spriteRenderer.sprite = sprites[index++];
|
|
}
|
|
}
|