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 The-Goliath

$
0
0
I agree that you should probably use GUITextures for this. I've written some example code based on what it looks like you're trying to achieve. I'm sure this could be cleaned up a bit, as I know JS but I wouldn't say I was an expert. So my apologies if it's a little messy. I've added commenting to explain the different behaviors, and I hope I've done this adequately. Please let me know if you have any problems or questions. //The GUITexture for the health. Create a GUITexture and assign the full //health texture to it var healthTexture : GUITexture; //Then assign the corresponding health textures directly to these slots var health0 : Texture2D; var health1 : Texture2D; var health2 : Texture2D; var health3 : Texture2D; var health = 100; //Starting health var zeroThirdHealth = 0; //The amount of health that counts as none (I'm assuming it's 0) var oneThirdHealth = 30; //The amount of health that counts as 1 third var twoThirdHealth = 65; //The amount of health that counts as 2 thirds var threeThirdHealth = 100; //The amount of health that counts as 3 thirds //The GUITexture for the lives. Create a GUITexture and assign the full //lives texture to it var livesTexture : GUITexture; //Then assign the corresponding life textures directly to these slots var lives0 : Texture2D; var lives1 : Texture2D; var lives2 : Texture2D; var lives3 : Texture2D; var lives = 3; //Starting lives //Is there a life 0? In other words, once the life count reaches 0, does the //player die, or do they still have one more try? var life0 = false; //You can use this just to test the damage system beforehand. Just click //the box in the inspector to call the ApplyDamage function with 35 damage var testApplyDamage = false; function Start () { } function Update () { //Just for testing if (testApplyDamage == true) { testApplyDamage = false; ApplyDamage(35); } if (health > threeThirdHealth) //If health gets above the 3 thirds point, bring it back down { health = threeThirdHealth; } if (health = twoThirdHealth && health = oneThirdHealth && health zeroThirdHealth && health 1) { lives -= 1; health = threeThirdHealth; healthTexture.texture = health3; //Add any sounds/effects for losing a life here } //If health is under or equal to the zero thirds point and the player had 0 lives //left, they die. (This is if life0 is set to true) if (health

Viewing all articles
Browse latest Browse all 6

Latest Images

Trending Articles





Latest Images