mirror of
https://github.com/CoonS2/Unity2DProject.git
synced 2026-02-04 12:13:22 +09:00
2DProject 및 Sprite 생성
1. 2DProject 생성 2. Sprite 및 AnimationController
This commit is contained in:
41
Assets/AnimationController.cs
Normal file
41
Assets/AnimationController.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
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++];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user