I have this piece of code and i need to put a countdown in SECONDS not by frame… l already try InvokeRepeting… but not work
// some code
// condition on while because curHeatLevel needs to decrease every time that Fire1 is not press
while (!Input.GetButton("Fire1") && curHeatLevel > 0 )
{
curHeatLevel--; // i need to decrease on every second here!
}
Easiest solution would be to make a update function that runs only once every second.
Have a look at [invoke repeating][1] function.
function Start()
{
InvokeRepeating("ManageTurretHeat",1f,1f);
}
function ManageTurretHeat()
{
if(!Input.GetButton("Fire1") && curHeatLevel > 0 )
{
curHeatLevel--;
}
}
This method will work but might run unwanted so if there are 100 turrets, 100 times a second this function will be called regardless of if the turrent is hot or not. The performance loss wont be too much since the function hardly does anything other than a --. if you would like to handle it you can use Nested Invokes.