我有一个带有while循环的IEnumerator,它应该运行100次,当我从同一脚本中的start方法调用此方法时,它可以完美地运行。但是,当我从另一个脚本调用IEnumerator时,它将被调用,而while循环仅运行一次。
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
}
}
您正在使用