-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimation.cs
More file actions
33 lines (30 loc) · 789 Bytes
/
Animation.cs
File metadata and controls
33 lines (30 loc) · 789 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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Animation : MonoBehaviour {
public Sprite[] sprites;
public int fps;
private float t;
private float time;
private SpriteRenderer spriteRenderer;
private int index;
// Use this for initialization
void Awake() {
spriteRenderer = GetComponent<SpriteRenderer>();
t = 1.0f / fps;
}
// Update is called once per frame
void Update () {
time += Time.deltaTime;
if (time >= t)
{
time = 0;
spriteRenderer.sprite = sprites[index];
index++;
if (index >= sprites.Length)
{
index = 0;
}
}
}
}