forked from sarbian/ModuleManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCatAnimator.cs
More file actions
38 lines (30 loc) · 874 Bytes
/
Copy pathCatAnimator.cs
File metadata and controls
38 lines (30 loc) · 874 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System.Collections;
using UnityEngine;
namespace ModuleManager.Cats
{
class CatAnimator : MonoBehaviour
{
public Sprite[] frames;
public float secFrame = 0.07f;
private SpriteRenderer spriteRenderer;
private int spriteIdx;
void Start()
{
spriteRenderer = this.GetComponent<SpriteRenderer>();
spriteRenderer.sortingOrder = 3;
StartCoroutine(Animate());
}
IEnumerator Animate()
{
if (frames.Length == 0)
yield return null;
WaitForSeconds yield = new WaitForSeconds(secFrame);
while (true)
{
spriteIdx = (spriteIdx + 1) % frames.Length;
spriteRenderer.sprite = frames[spriteIdx];
yield return yield;
}
}
}
}