increment the energy per second using Time.deltaTime
when charging, like so…
[SerializeField] private float curEnergy;
[SerializeField] private float maxEnergy = 100;
void Update()
{
if ( Input.GetKey( KeyCode.Space ) )
{
Charge();
}
}
void Charge()
{
if (curEnergy < maxEnergy )
{
curEnergy += Time.deltaTime;
}
else
{
curEnergy = maxEnergy;
}
}
this is just an example…
Thanks alot! It worked like a charm. I completely forgot about the deltatime.