Nextrek
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
47
48
49
50
51
52
|
using UnityEngine;
using System.Collections;
public class health : MonoBehaviour
{
//An array of Objects that stores the results of the Resources.LoadAll() method
private Object[] objects;
//Each returned object is converted to a Texture and stored in this array
private Texture[] textures;
//With this Material object, a reference to the game object Material can be stored
private Material goMaterial;
//An integer to advance frames
private int frameCounter = 0;
private float a=1; //alpha control
public static float health_=100;
void Awake()
{
//Get a reference to the Material of the game object this script is attached to
this.goMaterial = this.GetComponent<Renderer>().material;
this.GetComponent<Renderer>().material.color = new Color(this.GetComponent<Renderer>().material.color.r,this.GetComponent<Renderer>().material.color.b,this.GetComponent<Renderer>().material.color.g,.65f*a);
}
void Start ()
{
//Load all textures found on the Sequence folder, that is placed inside the resources folder
this.objects = Resources.LoadAll("Holographic/output/main/health", typeof(Texture));
//Initialize the array of textures with the same size as the objects array
this.textures = new Texture[objects.Length];
//Cast each Object to Texture and store the result inside the Textures array
for(int i=0; i < objects.Length;i++)
{
this.textures[i] = (Texture)this.objects[i];
}
}
void OnGUI () {
}
void Update ()
{
frameCounter=(int)Mathf.Round((100f-health_)/5.263f);
goMaterial.mainTexture = textures[frameCounter];
}
}
|