Make an energy wich decreases when the character jumps

I need to make an energy wich decreases when i jump, or when i press space. Practically my character need to fly, so i’ve made a script that makes him jump too when he is in the air. The only problem is that i don’t want he flyes endlessly! Possibly in C#! Oh, and you can tell me also how to make that when the character is on the ground that energy will restore, and maybe how to make a bar that sign how much energy is left? I know it is a really complex question, and understand an as terrible english like mine is difficult, but i hope to find my answer

using UnityEngine;
using System.Collections;

`````` public class Volo : MonoBehaviour {
float jumpCount;
public Vector2 jumpForce = new Vector2(0, 300);
bool grounded;
void Update()
{
// If the character has more than 0 jumps left
if (Input. GetKeyDown("space") && jumpCount > 0)
{
GetComponent<Rigidbody2D>().velocity = Vector2.zero;
jumpCount--; // Reduce the amount of jumps left by 1
}
// If the character is touching the ground
if (grounded)
{
jumpCount = 4; // Reset amount of jumps left to 4
}
}

void OnCollisionEnter(Collision col) // When the character collides with something
{
if(col.collider.tag == "ground") // If the object has the tag "ground"
{
grounded = true;
}
}
void OnCollisionExit(Collision col) // When the character stops colliding with something
{
if(col.collider.tag == "ground") // If the object has the tag "ground"
{
grounded = false;
}
}
}
``````

@Konomira ok, This is the script,

``````using UnityEngine;
using System.Collections;

public class Volo : MonoBehaviour {
public Vector2 jumpForce = new Vector2(0, 300);
float flightSpeed = 10.0f; // Set this speed to whatever you want.
float energyDecay = 1.0f; // Set this to whatever you want.
float energy;
const float maxEnergy = 100;
bool grounded;

void Update ()
{
Vector2 jumpForce = new Vector2(0, 300);
if (Input.GetKeyDown("space") && grounded) // Controls the initial jump
{
GetComponent<Rigidbody2D>().velocity = Vector2.zero;
}
if (Input.GetKey("space") && energy > 0) // Controls flight for as long as space is held down
{
Vector2 v = GetComponent<Transform>().velocity; // Creates a temporary velocity variable
v.y = flightSpeed; // Sets the temporary variables Y velocity to the flightSpeed
GetComponent<Transform>().velocity = v; // Sets the character velocity to the flightSpeed
energy -= energyDecay; // Reduces energy by energyDecay every frame
}
}

void OnCollisionEnter(Collision col) // When the character collides with something
{
if(col.collider.tag == "ground") // If the object has the tag "ground"
{
energy = maxEnergy; // Reset energy to max
grounded = true;
}
}
void OnCollisionExit(Collision col) // When the character stops colliding with something
{
if(col.collider.tag == "ground") // If the object has the tag "ground"
{
grounded = false;
}
}
}
``````

Now when i apply it to the character, when i press play there is another error:

Assets/scripts/Volo.cs(24,59): error CS1061: Type `UnityEngine.Transform' does not contain a definition for `velocity’ and no extension method `velocity' of type `UnityEngine.Transform’ could be found (are you missing a using directive or an assembly reference?)

What should i do? Sorry for all those probems, but i really need it in a few days XD