I want my player to fire one bullet, then to wait 3 seconds in order to be able to fire the next one.
The thing is the player doesn’t fire at all.
Notes:
I deleted all the unnecessary things to see from my script so it is easier to read
The script worked before I added the cooldown. I mean the player would fire a bullet every time I pressed Q.
You’re setting timeStampF to be time plus 3. So it is always greater than time. After that you’re checking whether it is less than time to fire.
Instead, you could do this:
void Update () {
// default value of timeStampF is 0, so it allows us to fire for the first time
if (Input.GetKeyDown(KeyCode.Q) && Time.time >= timeStampF) {
Fire1();
// set timeStampF to be current time + 3.
// Time.time increases, so it will reach timeStampF in three seconds.
timeStampF = Time.time + 3f;
}
}