Hi, I’ve been pounding at this code all day, can’t figure it out. I have two turrets that once fired, activate a cooldown state of about 44 seconds, along with shrinking a status bar using time.time (using time.deltatime only shrinks it by 1.0 then stops). I can get the status bar to shrink, and reset the bool, but for some reason the bool won’t reset after firing again.
Here is the code for one of the turrets (the one for the second is identical, only 1 replaced with 2 for the second one)
if (activeCD1)
{
Turret1Status.GetComponent<UnityEngine.UI.Image>().color = Color.red;
Turret1Status.sizeDelta = new Vector2(tur1width - 1.0f * Time.time, 6);
if (Turret1Status.sizeDelta.x <= 0)
{
activeCD1 = false;
Turret2Status.sizeDelta = new Vector3(44, 6);
}
}
else
{
Turret1Status.GetComponent<UnityEngine.UI.Image>().color = Color.green;
Turret1Status.sizeDelta = new Vector3(44, 6);
}
There is some bizarre de-synch with tur1width and Turret1Status.sizeDelta.x. It properly goes
down, and the activeCD1 gets set to false and status bar is reset to normal size. But when
the function gets called again, turret1status.sizedelta.x is still 0. I tried everything to
set it back to 44, but nothing works. Is there something I’m missing, or am I doing this wrong?
Here is the function that calls activeCD1 to be true incase there’s something I missed:
public void Turret1Off()
{
activeCD1 = true;
Turret1Active = false;
hp1.SendMessage("TurnOff");
emit = false;
beamtake = 0;
runcycle = 0;
}