Unityのコルーチンの使い方についての質問です。
lang
1using UnityEngine; 2using System.Collections; 3 4public class Emitter : MonoBehaviour 5{ 6 7 public GameObject[] waves; 8 9 private int currentWave; 10 11 public bool wait; 12 13 14 IEnumerator Start() 15 { 16 while(wait == false) 17 { 18 yield return new WaitForEndOfFrame(); 19 } 20 if (waves.Length == 0) 21 { 22 yield break; 23 } 24 25 while (true) 26 { 27 GameObject wave = (GameObject)Instantiate(waves[currentWave], transform.position, Quaternion.identity); 28 29 wave.transform.parent = transform; 30 31 while (wave.transform.childCount != 0) 32 { 33 yield return new WaitForEndOfFrame(); 34 } 35 36 Destroy(wave); 37 38 if (waves.Length <= ++currentWave) 39 { 40 currentWave = 0; 41 } 42 43 } 44 } 45 46
こちらのスクリプトには基本的に4~6個のウェーブがあります。
今では1→2→3→4→5→6とウェーブが終わるとまた1に戻って処理を再開します。
しかし、そのEmitter内の最後のウェーブを生成すると処理を停止するようにしたいです。
yield break;をどんな条件でどこに入れればいいかわかりません。
回答よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/02/15 13:06