- Home /
Lifebar Help
Hi, I have created a lifebar which decreases in increments when a Healthfield is entered and a trigger is activated by the Player. It works well but I cannot understand how to load a new scene when 3 negative increments have been reached. Can anyone help on this? Here is my current code for the Healthfield..
var Hurtbox: boolean = false;
function OnTriggerEnter(other: Collider){
if(other.gameObject.tag == ("Player")){
if(Hurtbox && LifeBar.Health >= 0){
LifeBar.Health--;
}
else if(!Hurtbox && LifeBar.Health<=2){
LifeBar.Health++;
}
//Destroy(gameObject);
}
}
Where are you setting Hurtbox to true? also what is LifeBar? It sounds like you have a simple problem but you've got some confusing bits. help us help you :D
Rennat, Hi, a Lifebar is the same as a Healthbar. Blocks of color that increase or decrease on collision. The video links posted by HTH_mrsnake are in the right direction I think but I'm not sure how insert a check into the above code. I need to know when there is no Health left so I can then switch levels with.. Application.LoadLevel(myLevel); Thanks.
:) What I meant was when you type LifeBar
are you working with a class? Where is that class defined?
It's defined in the Lifebar script which builds the shape of the Lifebar and calls images to have it appear onscreen. The above code is placed on a collision object. The Lifebar script is basically..
static var Health : int = 3; var bgImage : Texture2D; // background image that is 256 x 32 var fgImage : Texture2D; // foreground image that is 256 x 32 var OutlineImage : Texture2D; // Outline image that is 256 x 32
function OnGUI () {...
Answer by Rush-Rage-Games · Aug 23, 2011 at 05:34 PM
Try these 2 videos:
http://www.unity3dstudent.com/2010/09/beginner-b20-if-statements-and-booleans/
http://www.unity3dstudent.com/2010/07/beginner-b16-switching-scenes/
Your answer
![](https://koobas.hobune.stream/wayback/20220612190557im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Basic Health Bar Display Problem 1 Answer
Health Bar to Render On Top 2 Answers
Healthbar Energy Bar and MiniMaps? 0 Answers
need help with GUI healthbar 1 Answer
Need help with health script 2 Answers