pezz
1
Hi everyone,
I would liek to create a count down time. Lets say its start counting down from 2 and when it gets to 0 it sets a boolean to false.
I am having a little problem developing the logic. I thought it would have been so easy.
I always want the timer count down to start from 2 and reset to 0 where it will start from 2 again when I press “down”. However it doesnt happen.
Where did I go wrong?
My code is below.
public float keyTime = 2;
public float guiTime;
public bool canUseKey = false;
void Update()
{
if (Input.GetKeyDown("down"))
{
canUseKey = true;
}
if(canUseKey == true)
{
keyTime -= Time.deltaTime;
if(keyTime <=0)
{
canUseKey = false;
keyTime = 2;
}
}
}
set it to 2 when you get a key down
dkozar
4
You could use this lib (a Timer class). Usage:
int _count = 5;
void Start() {
Timer t = new Timer(1, 5); // tick each second, five times
t.Tick += delegate { _count--; Debug.Log("Timer tick: " + _count); };
t.Complete += delegate { Debug.Log("Timer complete. Now showing the 'Play again' button..."); };
t.Start();
}
Another timer example here.
pezz
6
I am getting a couple parsing errors with this.
This surprisingly works.
dkozar
7
Please, drop the eDriven.Core.dll into the project before trying the example 