IEnumerator CoTest Main()
{
yield return CoTest_A();
yield return CoTest_B();
yield return CoTest_C();
}
I want to escape if CoTest_B has some problem and don’t read CoTest_C() Code
IEnumerator CoTest Main()
{
yield return CoTest_A();
yield return CoTest_B();
yield return CoTest_C();
}
I want to escape if CoTest_B has some problem and don’t read CoTest_C() Code
There are a couple of errors in your code:
You should not have a space between “CoTest” and “Main”;
Use yield return StartCoroutine(CoTestB())
to start it.
To bypass CoTestC, you need to set the boolean runCoTestC to false in CoTestB.
Here is some sample working code.
using System.Collections;
using UnityEngine;
public class test4 : MonoBehaviour
{
bool runCoTestC = false;
private void Start()
{
StartCoroutine(CoTestMain());
}
IEnumerator CoTestMain()
{
yield return StartCoroutine(CoTestB());
if (runCoTestC)
{
yield return StartCoroutine(CoTestC());
}
}
IEnumerator CoTestB()
{
Debug.Log("CoTestB");
runCoTestC = false;
yield return null;
}
IEnumerator CoTestC()
{
Debug.Log("CoTestC");
yield return null;
}
}