前提・実現したいこと
Unity2Dで横スクロールアクションゲームを作成しているのですが、
プレイヤーが特定の位置まで移動する→操作の説明などを含めたチュートリアルイベントが発生→イベントが終わったら移動可能になる→また別の位置で違った内容のチュートリアルイベントが発生…
という流れを作りたいと考えています。
現在、特定の位置に達したらそれぞれ発生させたいイベント処理を書いたコルーチンを呼び出す、という風に実装しているのですが、発生させたいイベントの数だけ同じようなコルーチンが増えてしまうためあまりよくない記述の仕方をしているように思えます。
何かほかにもっと良い実装方法をご存じの方がいらっしゃいましたらご教授いただけますと幸いです。
試したこと
Timelineを活用できないか試しましたが特定の位置に来たら、という条件では使用できないようなので断念しました
追記
現在イベントを発生させるため空オブジェクトにアタッチしているスクリプトになります。
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using UnityEngine.UI; 5 6public class Turorial : MonoBehaviour 7{ 8 List<string> Texts = new List<string> 9 { "セリフ1", "セリフ2", "セリフ3", 10 "セリフ4","セリフ5" }; 11 12 [SerializeField] private Text test; 13 [SerializeField] private Pausable pausable; 14 [SerializeField] private GameObject Serif_Player; 15 [SerializeField] private GameObject Serif_Sistem; 16 17 [SerializeField] private Player player; 18 19 void Start() 20 { 21 StartCoroutine(Walk()); 22 } 23 24 void Update() 25 { 26 27 } 28 29 private IEnumerator Walk() 30 { 31 yield return new WaitForSeconds(2f); 32 //プレイヤーの動きなどを止める 33 pausable.pausing = true; 34 //メッセージウィンドウを表示 35 Serif_Player.SetActive(true); 36 Serif_Sistem.SetActive(false); 37 for (int i = 0; i <= 2; i++) 38 { 39 if(i == 2) 40 { 41 Serif_Player.SetActive(false); 42 Serif_Sistem.SetActive(true); 43 pausable.pausing = false; 44 } 45 test.text = Texts[i]; 46 //タッチでメッセージを送る 47 yield return new WaitUntil(Touch); 48 yield return new WaitWhile(Touch); 49 } 50 yield return new WaitForSeconds(1f); 51 Serif_Sistem.SetActive(false); 52 test.text = ""; 53 yield break; 54 } 55 56 private IEnumerator Key() 57 { 58 player.DashAnim_Stop(); 59 pausable.pausing = true; 60 Serif_Player.SetActive(true); 61 for (int i = 3; i <= 4; i++) 62 { 63 test.text = Texts[i]; 64 yield return new WaitUntil(Touch); 65 yield return new WaitWhile(Touch); 66 } 67 Serif_Player.SetActive(false); 68 test.text = ""; 69 pausable.pausing = false; 70 yield break; 71 } 72 73 void OnTriggerEnter2D(Collider2D col) 74 { 75 StartCoroutine(Key()); 76 } 77 78 bool Touch() 79 { 80 return Input.anyKeyDown; 81 } 82} 83
補足情報(FW/ツールのバージョンなど)
Unity2018.3.5f1
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/08/05 13:21
2019/08/06 01:41
2019/08/10 11:29