-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimatedTextureAndy.cs
More file actions
46 lines (40 loc) · 1.21 KB
/
AnimatedTextureAndy.cs
File metadata and controls
46 lines (40 loc) · 1.21 KB
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
39
40
41
42
43
44
45
46
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AnimatedTexture : MonoBehaviour
{
//Declaring each member variable and method
public Texture2D[] textures;
public float framerate = 60;
private float waitSeconds;
private int numTextures;
private int i = 0;
private Material material;
//Initialize to feed into main loop
void Start()
{
material = gameObject.GetComponent<MeshRenderer>().material;
numTextures = textures.Length;
StartCoroutine(AnimateTexture());
}
//Dont know why, just need this here so that we can have the animated texture
IEnumerator AnimateTexture()
{
while (true)
{
if (i == numTextures)
{
i = 0;
}
material.SetTexture("_BaseMap", textures[i]);
i++;
//delays the loop speed so that its not running at insane speed
yield return new WaitForSeconds(waitSeconds);
}
}
//This is the main loop that we supplied initial conditions to with void Start()
void Update()
{
waitSeconds = 1 / framerate;
}
}