Trying to make a meter grow based on length of user input

Hi. I’m just starting out with Unity and I’m trying to start by making a simple program where the user simply has to hold down the space bar to make a meter fill up to the top and “win.” I’ve gotten a script that will track whether the space bar is being held down, how long it has been held down for, and how fast the “chargeRate” of the bar should be. However, I’m not really sure how to actually make the bar fill up visually. I’m assuming it has to do with applying a 2D Vector and transform to the Sprite Renderer, but I have a limited understanding of how to actually make it so that the sprite (a simple green bar) will grow from nothing to 100%. Sorry if this is pretty basic! Most of the answers yielded scripts that were mainly for health bars that I could not get working.

EDIT: I managed to find this script, which let me create a functional bar and input my variables. However, when I press space, the bar loads from top to bottom, rather than bottom to top like I’d want. I updated my script to reflect these changes. Basically, my new problem is that I’m trying to flip the GUI.box that my meter is made out of so that it fills from bottom to top.

#pragma strict
 
var ap : float = 0; //action points meter; how long the player has held down space
var chargeRate : float = 0.05; //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(550,8);
var size : Vector2 = new Vector2(66,368);
var progressBarEmpty : Texture2D;
var progressBarFull : Texture2D;
 
function Start () {
 
}
 
 
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, 0, size.x, size.y * barDisplay));
            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!");
}
else
{
    charging = 0;
    Debug.Log("Charging is False!");
}
 
if (charging==1)
{
	spaceTime += Time.deltaTime;
    ap = (chargeRate * spaceTime);
    print("The variable is :"+ap);
}
    barDisplay = ap;
 
}

GUI.BeginGroup (new Rect (0, size.y - (size.y * barDisplay), size.x, size.y));
line 27