So I’ve been at this all day, but I’m making a little practice game that is similar to those old arcade space bullet hells, and I want a boost mechanic with a cool down timer, but can’t seem to get unity to start the charge timer. This is my current code.
:Code for moving the ship:
public string GetKey;
public float startTime;
public string currentTime;
public float chargeTime;
void Update () {
updateBoost();
if (chargeTime == 5) // <=== Not seeing the change and starting the countdown for the cool down
{
//run the use timer.
chargeTime -= Time.deltaTime;
currentTime = string.Format("{0:0.0}", chargeTime);
print(currentTime);
if (chargeTime <=0)
{
startTime = 5;
print("You are ready to boost.");
GetKey = "t";
}
}
//Texture movement
TextureOffset += ScrollSpeed * Time.deltaTime;
GetComponent<Renderer>().material.SetTextureOffset("_MainTex", TextureOffset);
}
void updateBoost(){
if (Input.GetKey(GetKey)){
TextureOffset += ScrollSpeed * Time.deltaTime * 5;
//run the use timer.
startTime -= Time.deltaTime;
currentTime = string.Format("{0:0.0}", startTime);
print(currentTime);
if (startTime <=0)
{
chargeTime = 5;
print("You are out of fuel.");
GetKey = "r";
}
}
}
First time posting here, so I think this is everything I need to post. I’m kinda new at this.