Quantcast
Channel: Answers for "Please help me make a health system with GUI. I cant do it!"
Viewing all articles
Browse latest Browse all 6

Answer by gajdot

$
0
0
K, i took the time to write something you want, it wasn't tested, but you need something like this. Put this script on an empty gameobject and hook up the guitexture, textures, and tweak values if you wish. public int health = 100; public int maxHealth = 100; public int minHealth = 0; public int lives=3; public int damage = 35; public GUITexture gui; public Texture[] textures; private int lastTexture; // Use this for initialization void Start () { } public void Damage() { health-=damage; } // Update is called once per frame void Update () { if(health<0) health =0; if(health>100) health = 100; int currentTexture = health % 25; if (lastTexture!=currentTexture) { lastTexture=currentTexture; gui.texture = textures[currentTexture]; } if(health == 0) { Destroy(GameObject.Find("Character")); health = 100; --lives; //do respawn } if(lives == 0 ) { Application.LoadLevel("Game_Over"); } }

Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>