現在制作中のゲームで上の画像のような形でシナリオを複数管理しています。
この場合ゲームを実行して一つのテキストを進めると他の表示されていない分のテキストまで進行してしまい、困っています。最初はスクリプトを全て同じもので使っていたからかと思いセリフの数だけコピペでスクリプトを増やしました(下記)
それぞれ別のセリフにアタッチし、これでうまくいくかと思いましたが、変わらずセリフが同時に進んでしまっています。
原因は何が考えられるでしょうか?
解決策など、教えていただけたら幸いです。
よろしくお願いします。
C#
1コード(使っているスクリプトです) 2using UnityEngine; 3using System.Collections; 4using UnityEngine.UI; 5 6public class TextController3 : MonoBehaviour 7{ 8 public string[] scenarios; 9 [SerializeField] Text uiText; 10 11 [SerializeField] 12 [Range(0.001f, 0.3f)] 13 float intervalForCharacterDisplay = 0.05f; 14 15 private string currentText = string.Empty; 16 private float timeUntilDisplay = 0; 17 private float timeElapsed = 1; 18 private int currentLine = 0; 19 private int lastUpdateCharacter = -1; 20 21 // 文字の表示が完了しているかどうか 22 public bool IsCompleteDisplayText 23 { 24 get { return Time.time > timeElapsed + timeUntilDisplay; } 25 } 26 27 void Start() 28 { 29 SetNextLine(); 30 } 31 32 void Update() 33 { 34 // 文字の表示が完了してるならクリック時に次の行を表示する 35 if (IsCompleteDisplayText) 36 { 37 if (currentLine < scenarios.Length && Input.GetKeyDown(KeyCode.Keypad0)) 38 { 39 SetNextLine(); 40 } 41 } 42 else 43 { 44 // 完了してないなら文字をすべて表示する 45 if (Input.GetKeyDown(KeyCode.Keypad0)) 46 { 47 timeUntilDisplay = 0; 48 } 49 } 50 51 int displayCharacterCount = (int)(Mathf.Clamp01((Time.time - timeElapsed) / timeUntilDisplay) * currentText.Length); 52 if (displayCharacterCount != lastUpdateCharacter) 53 { 54 uiText.text = currentText.Substring(0, displayCharacterCount); 55 lastUpdateCharacter = displayCharacterCount; 56 } 57 } 58 59 60 void SetNextLine() 61 { 62 currentText = scenarios[currentLine]; 63 timeUntilDisplay = currentText.Length * intervalForCharacterDisplay; 64 timeElapsed = Time.time; 65 currentLine++; 66 lastUpdateCharacter = -1; 67 } 68}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。