trying to create a tap to fill power bar that appears after destroying game object.
Hi all. I'm having an issue that I need a little help with. I trying to make a fill meter appear after a game object has been caught and destroyed, then have players tap the bar to fill it up. once full players are rewarded with X points. I have the bar appearing but it is constant but fills up when key is held, this also makes the points continuously rise. I struggle to grasp writing code and would appreciate any help to build my design portfolio . Here is my code for the bar. I have other scripts that add points on destroy which all work fine. #pragma strict
var ap : float = 0; //action points meter; how long the player has held down space var chargeRate : float = 0.08; //the rate that the meter fills up; will vary based on level var charging = 0; //whether or not the player is holding down space to charge var spaceTime : float = 0;
var barDisplay : float = 0; var pos : Vector2 = new Vector2(399,0); var size : Vector2 = new Vector2(10,000); var progressBarEmpty : Texture2D; var progressBarFull : Texture2D;
function OnTriggerEnter (info : Collider) { Destroy(gameObject); }
function OnGUI()
{
// draw the background:
GUI.BeginGroup (new Rect (pos.x, pos.y, size.x, size.y));
GUI.Box (Rect (0,0, size.x, size.y),progressBarEmpty);
// draw the filled-in part:
GUI.BeginGroup (new Rect (0, size.y - (size.y * barDisplay), size.x, size.y));
GUI.Box (Rect (0,0, size.x, size.y),progressBarFull);
GUI.EndGroup ();
GUI.EndGroup ();
}
function Update () {
if (Input.GetKey(KeyCode.Space))
{
charging = 1;
Debug.Log("Charging is True!");
Gamescore.gscore += 15;
}
else
{
charging = 0;
Debug.Log("Charging is False!");
}
if (charging==1) { spaceTime += Time.deltaTime; ap = (chargeRate * spaceTime); print("The variable is :"+ap);
} barDisplay = ap; }
Your answer
Follow this Question
Related Questions
Resetting Power up bar 0 Answers
particle system going wild 1 Answer
Get all combinations of a list of lists of arrays... 2 Answers
Function not running everytime 0 Answers
2D game score 1 Answer