Early on i would like to point out I use C#. Ok So the problem im having is making a sort of sprint ability (using the left shift) that then will let the player sprint at a accelerated speed while it draws energy from a energy GUI. I have the GUI’s script however I have not been able to create a working sprint within it or in another script. So below is a script for my GUI.
using UnityEngine;
using System.Collections;
public class EnergyScript : MonoBehaviour {
// Stamina Bar
public int Maxenergy = 100;
public int curEnergy = 100;
public Texture2D bgImage;
public Texture2D fgImage;
public float EnergyBarLength;
void Start () {
EnergyBarLength = Screen.width /2;
}
void Update () {
AddjustcurrentEnergy(0);
}
void OnGUI() {
GUI.BeginGroup (new Rect (10,10, EnergyBarLength,20));
GUI.Box (new Rect (10,10, EnergyBarLength,20), bgImage);
GUI.BeginGroup (new Rect (10,10, curEnergy / Maxenergy * EnergyBarLength, 20));
GUI.Box (new Rect (10,10,EnergyBarLength,20), fgImage);
GUI.EndGroup ();
GUI.EndGroup ();
}
void AddjustcurrentEnergy(int adj){
curEnergy += adj;
if(curEnergy <0)
curEnergy = 0;
if(curEnergy > Maxenergy)
curEnergy = Maxenergy;
if (curEnergy < 100)
if(Maxenergy <1)
Maxenergy = 1;
EnergyBarLength =(Screen.width /2) * (curEnergy / (float)Maxenergy);
}
}
Any help is appreciated.