My code is not working - HELP - IEnumerator Coroutines
I´m making a timer with coroutines (more like 1). I have 2 scripts: 1- Counter (attached to gameObject: 'Clock'), then 2- GameManager. So, basically, what I´m doing is storing the value of the countdown timer in "Clock" and trying to execute the Coroutines (IEnumerator startCountdown) in the Start method of the GameManager, and work from there. Setting a random value for the timer:
public class Countdown : MonoBehaviour {
private float randomNum;
//max range number you decide to put. to begin countdown
public int mNum;
public GameObject button;
//-----------------------------------------------------------------------
private void setRandom(int maxNum){
randomNum = Random.Range(3, maxNum+1);
}
public void setTimer(){
setRandom(mNum);
if(button.active){
button.SetActive(false);
}
}
public IEnumerator startCountdown()
{
while(randomNum > 0)
{
yield return new WaitForSeconds(1f);
randomNum--;
Debug.Log("this is from IEnumerator startCountdown");
}
}
//-----------------------------------------------------------------------
}
Then in the GameManager start method i just have it like this:
void Start() {
StartCoroutine(clock.GetComponent<Countdown>().startCountdown());
}
I´m definitely not understanding and/or applying the concepts right, because nothing is working. The value set for the timer works, the only thing that doesn´t is the IEnumerator. I´ve investigated and read on many different Q&A, looked up videos but this specific Coroutine (I have another that executes when the game ends, just ends the game after 5 seconds). The Debug.Log doesn´t appear on the console.
Your answer
Follow this Question
Related Questions
Do Slowmotion effect for x seconds 1 Answer
Problem with particle effects and detonating bombs 0 Answers
Start and Stop Timer Help 1 Answer
Player Countdown Interaction/Time Reduction+Addition 0 Answers
Help with coroutines 1 Answer