- Home /
WaitForSeconds not working C#
I want a "cooldown" timer before a player is allowed to fire another attack but i never see the second debug message.
private void Fireball(){
StartCoroutine(Wait());
Transform pos = transform.Find("shootPos");
GameObject Fireball = Instantiate (Resources.Load ("Prefabs/Character/Sorceress/SorceressAbilities/Fireball"), pos.position, transform.rotation) as GameObject;
}
private IEnumerator Wait()
{
Debug.Log ("Wait started");
yield return new WaitForSeconds (55.0f);
Debug.Log ("Wait ended");
}
Answer by tatoforever · Oct 15, 2014 at 11:08 PM
You probably want to check if your timescale din't changed. Also, your code isn't right. if you want to wait for some function to finish, you have to yield the function itself. Like this (pseudo code):
private bool isFiring;
void Update()
{
if(!isFiring)
{
StartCoroutine(Fireball());
}
}
IEnumerator Fireball()
{
isFiring = true;
yield return StartCoroutine(Wait());//yielded function
Transform pos = transform.Find("shootPos");
GameObject Fireball = Instantiate (Resources.Load ("Prefabs/Character/Sorceress/SorceressAbilities/Fireball"), pos.position, transform.rotation) as GameObject;
isFiring = false;
}
IEnumerator Wait()
{
Debug.Log ("Wait started");
yield return new WaitForSeconds (55.0f);
Debug.Log ("Wait ended");
}
Answer by KpjComp · Oct 15, 2014 at 08:13 PM
yield WaitForSeconds(55.0f)
Your currently asking to wait one frame then returm
Your answer
Follow this Question
Related Questions
Definition of Script.function() depends on Script.function()... 3 Answers
Using Yield Wait for seconds with instantiate 1 Answer
Why Is yield return new WaitForSeconds() not working 2 Answers
yield WaitForSeconds waits for too long. 2 Answers
Yield and WaitForSeconds not stopping at correct points? 1 Answer