I am trying to make my first mobile game and make a cooldown time to the skill using UI button. The things I want to do is after i pressed the UI button, the skill function will be called(is finished), and then wait for few seconds the skill can be used again. The way that I was used is using button onClick and when it clicked the skill will be used. Now, if i pressed the button many times the skill will happen many times, so I want to set a timer to count the cooldown time for the function will be called next times. I find some video on youtube, most of them is putting the cooldown timer on the update function and if the cooldown time go to zero and input.getkeydown(xxx) then the skill can be use again. However, I want to use UIbutton instead of the key on the keyboard or mouse. Please help me TT, thank you.
you need something like this
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class testCD : MonoBehaviour {
public bool SpellIsReady;
// Use this for initialization
void Start () {
SpellIsReady = true;
}
public void ClickOnBTN(){
if(SpellIsReady){
Debug.Log ("stun");
SpellIsReady = false;
StartCoroutine ("wait");
}
}
public IEnumerator wait(){
yield return new WaitForSeconds (5);
SpellIsReady = true;
}
}
so if you use Coroutine you don’t need an update method
watch this video.