I have a IEnumerator with a while loop that should run 100 times that works perfectly when I call this from the start method in the same script. But when I call the IEnumerator from another script it gets called but the while loop only run once.
public class script1: MonoBehaviour
{
private void Start()
{
//StartCoroutine(StartCountdown(3));
// When I call it here the while loop runs 100
}
public IEnumerator StartCountdown(float countdownValue)
{
float waiteTime = countdownValue / 100;
int loopNumber = 100;
//float idk = 0;
while (loopNumber > 0)
{
Debug.Log("aufgerufen");
circle.fillAmount -= 0.01f;
yield return new WaitForSeconds(waiteTime);
loopNumber -= 1;
}
}
}
public class script2 : MonoBehaviour
{
public void GameOver()
{
panel.SetActive(true);
Time.timeScale = 0;
GameObject circle = GameObject.FindGameObjectWithTag("LoadCircle");
StartCoroutine(circle.GetComponent<LoadCircle>().StartCountdown(3));
//When I call it from here the while loop only run once
}
}