Не вызывайте StartCoroutine в обновлении. Вместо этого оберните логическое значение в свойстве, чтобы при его изменении или установке вы также могли вызывать StartCoroutine.
Допустим, счетчик устанавливает его:
private IEnumerator coroutine = null;
private int counter = 0;
public int Counter
{
get{ return this.counter; }
set
{
this.counter = value;
if(this.counter == conditionValue)
{
if(this.coroutine != null){ return; } // already running
this.coroutine = StartProcess();
StartCoroutine(this.coroutine); }
}
}
и для вашей сопрограммы:
private IEnumerator StartProcess()
{
yield return StartCoroutine (Process1());
yield return StartCoroutine (Process2());
}
вам на самом деле не нужно проверять, завершен ли Процесс 1, поскольку ваша сопрограмма уже ожидает его выполнения, прежде чем продолжить.
Если вам нужно проверить что-то внутри процесса 1 для запуска процесса 2, вот решение:
private IEnumerator StartProcess()
{
bool condition = false;
yield return StartCoroutine (Process1(ref condition));
if(condition == false){ yield break; }
yield return StartCoroutine (Process2());
this.coroutine = null;
}
private IEnumerator Process1(ref bool condition)
{
// some code
yield return null;
// more code
condition = true; // or false
}