【Unity】コルーチン 使用方法(一時停止・再開・全て停止)

1. コルーチンの書き方

public void DownRoom(){
	//コルーチンを生成する。
	StartCoroutine(DownRoomWait());
}

// publicにする。
public IEnumerator DownRoomWait(){
}
// 又はprivateにすることもできる。
IEnumerator DownRoomWait(){
}


[StartCoroutine, IEnumerator]
コルーチンを呼び出したい時、二重構造にする必要がある。

	public void DownRoom(){
		StartCoroutine(DownRoomWait());
	}
        // this.gameObject の順番
	public IEnumerator DownRoomWait(){
		iTween.MoveTo (this.gameObject, iTween.Hash("y",-1.5,"time", 1f));
		yield return new WaitForSeconds (1.5f);
		iTween.ScaleTo (FrontRoom.gameObject, iTween.Hash("x",1,"time",0.5f));
		yield return new WaitForSeconds (0.75f);
		iTween.ShakePosition (this.gameObject, iTween.Hash("x",0.2f,"time",0.9f));
		yield return new WaitForSeconds (1f);
		iTween.ShakePosition (this.gameObject, iTween.Hash("x",0.4f,"time",0.5f));
	}




1. 一時停止・再開

IEnumerator coroutineMethod;
public void RunTime(){
	coroutineMethod = RunTimeWait();
	StartCoroutine(coroutineMethod);
}
public void StopRunTimeTemp(){
	StopCoroutine(coroutineMethod);
}


2. StopAllCoroutines
そのスクリプト内のコルーチンをすべて停止する
Behaviour 上で実行されているコルーチンを全て停止します

public void StopRunTime(){
	StopAllCoroutines();
}