- Home /
How to make my health decrease?
Could someone please help me edit this code so my health decreases when it touches an object?
It's just like a loading bar at the moment, and i have no clue how to fix it. I need this done today and i havent got a clue how to do this, so please help! :(
var barDisplay : float = 0;
var pos : Vector2 = new Vector2(20,40);
var size : Vector2 = new Vector2(60,20);
var progressBarEmpty : Texture2D;
var progressBarFull : Texture2D;
function OnGUI()
{
GUI.BeginGroup (new Rect (pos.x, pos.y, size.x, size.y));
GUI.Box (Rect (0,0, size.x, size.y),progressBarEmpty);
GUI.BeginGroup (new Rect (0, 0, size.x * barDisplay, size.y));
GUI.Box (Rect (0,0, size.x, size.y),progressBarFull);
GUI.EndGroup ();
GUI.EndGroup ();
}
function Update()
{
barDisplay = Time.time * 0.05;
}
Answer by kaolas · Nov 30, 2012 at 06:36 PM
It looks like you have it working on a timer rather than a collision. Depending on how you're doing collision detection, you would want that to trigger the bar's "value" to change (what you're currently using "barDisplay" for it seems) rather than the Update() function.
If what you're really asking is "how do I do collision detection", then you should do some research - there are tons of resources out there such as: Basic Collision Detection Tutorial
Your answer
Follow this Question
Related Questions
Player health dropping far to fast 1 Answer
Health Code, Damage and Healing 0 Answers
unity health bar not losing health 1 Answer
I need some help with a Fractional Heart System? 1 Answer
How to Make Health Decrease Over Time 2 Answers