Hello folks, I’ve come with coroutines madness:
First Question is Understanding WHY the MainCheckRoutine() is executed twice…
private bool ready;
private float customTime;
void Awake()
{
ready = false;
}
void Start () {
customTime = 0.8f;
StartCoroutine( ELbuscon());
}
void Update()
{
customTime -= Time.deltaTime;
if (customTime < 0)
{
if (ready == false)
{
GameObject[] fs = GameObject.FindGameObjectsWithTag("litrick");
GameObject[] ts = GameObject.FindGameObjectsWithTag("estrello");
GameObject[] rs = GameObject.FindGameObjectsWithTag("match");
if (fs.Length > 0 || ts.Length > 0 || rs.Length >0)
{
//nothing
}
else
{
ready = true;
}
}
}
}
IEnumerator ELbuscon()
{
while(ready == false)
{
yield return new WaitForFixedUpdate();
}
MainCheckRoutine();
}
void MainCheckRoutine(){
Debug.Log("why am i exectude twice?");
SomeCheckingThingFunc();
FinalStep();
}
void FinalStep(){
if(something==else){
StartCoroutine(Elbuscon());}
// THIS Freezes out everything
}
The fact is that if i swtich Start function to IEnumerator Start(){}. and i make some yield inside… the code just runs once… makes no sense on me because even Coroutines play independient its supose to yield the instructions after ready = true is met… Just once becouse Start is fired once… dont understand yah! :(_
Second Question is about looping and freezing. Which would be the best approach to loop the Elbuscon() function after a requirements on the very end of this fucntion; like FinalStep(); this way seems to freeze unityeditor couse a infinite loop even it’s not.(my guess…)
Thank You !