using UnityEngine;
using System.Collections;
public class CooldownTest : MonoBehaviour {
public bool onCooldown = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (onCooldown == false Input.GetKeyDown(KeyCode.H)) {
onCooldown = true;
Cooldown();
}
Debug.Log("Pressing H: " + Input.GetKey(KeyCode.H));
}
IEnumerator Cooldown() {
yield return new WaitForSeconds(3);
onCooldown = false;
}
}
This code is supposed to be so that when you press H, it sets the bool as true and goes directly to the coroutine, waiting 3 seconds and then setting the bool to false. Why will it not work? Thanks
Thanks But now I have the problem, the coroutine starts when the game loads, and not when the player presses H. But I can’t put the StartCoroutine in the Update beecause Update updates it every frame…what do I do?