I asked that question before but I got no answer and I stuck so I need to solve that problem to continue making my game!!!
I make a third person game and I created in the game health, energy and delay bars based on this answer. I edited a bit the code so it will be fit to my game (bar for each weapon and time to fill each bar) and the bars are seeing all the time.
In the question I used for help, asked about how to reset the bar but I try to do wat the answed say and it don't works in my game.
Here is parts my code (the code is very long and you don't need to see all of it...):
//2D bars
var basicSize : Vector2 = new Vector2(150,20);
var otherSize : Vector2 = new Vector2(100,10);
//health
var healthBarDisplay : float = 100;
var healthPos : Vector2 = new Vector2(130,60);
var healthBarEmpty : Texture2D;
var healthBarFull : Texture2D;
//energy
var energyBarDisplay : float = 100;
var energyPos : Vector2 = new Vector2(130,85);
var energyBarEmpty : Texture2D;
var energyBarFull : Texture2D;
//bombs
var bombBarDisplay : float = 0;
var bombPos : Vector2 = new Vector2(80,110);
var bombBarEmpty : Texture2D;
var bombBarFull : Texture2D;
there are 2 more weapon based like the bombs
energyBarDisplay += Time.time * 0.0002;
energyBarDisplay = Mathf.Clamp01(energyBarDisplay);
bombBarDisplay += Time.time * 0.0015;
bombBarDisplay = Mathf.Clamp01(bombBarDisplay);
teleBarDisplay += Time.time * 0.0015;
teleBarDisplay = Mathf.Clamp01(teleBarDisplay);
rocketBarDisplay += Time.time * 0.0002;
rocketBarDisplay = Mathf.Clamp01(rocketBarDisplay);
what i did for reset:
function Explode ()
{
if (bombUse)
{
animation.Play("RockExp");
var expEffect1 = Instantiate(bombEffect1, GameObject.Find("spawnPointA").transform.position, transform.rotation);
yield WaitForSeconds(0.5);
var expEffect2 = Instantiate(bombEffect2, GameObject.Find("spawnPointA").transform.position, transform.rotation);
var ballExp = Instantiate(bombs, GameObject.Find("spawnPointA").transform.position, Quaternion.identity);
ballExp.gameObject.tag = "CharacterProjectile";
ballExp.rigidbody.AddForce(transform.forward * 10000);
bombBarDisplay = 0.0f;
//for delay
bombUse = false;
yield WaitForSeconds(5.0);
bombUse = true;
}
}
to make the bars:
//bombs
// draw the background:
GUI.BeginGroup (new Rect (bombPos.x, bombPos.y, otherSize.x, otherSize.y));
GUI.Box (Rect (0,0, otherSize.x, otherSize.y),bombBarEmpty);
// draw the filled-in part:
GUI.BeginGroup (new Rect (0, 0, otherSize.x * bombBarDisplay, otherSize.y));
GUI.Box (Rect (0,0, otherSize.x, otherSize.y),bombBarFull);
GUI.EndGroup ();
GUI.EndGroup ();
The problem is when I use the weapon and the delay works (there is a delay) the bar needs to show on how much time I will be able to use the weapon again, When I use it the bar reset but it filled again in notime (it flashing with the empty bar). how I can reset the bars?
Another question I want to ask is how to show by numers the bullets I have, show the ammo?