0
我想爲我的遊戲製作一個對話框腳本,使用某種自動分類樣式。問題是當我開始遊戲時,它給了我一個錯誤:IndexOutOfRangeException:數組索引超出範圍。在我解決這個問題之後,我失去了自動分型效果,該消息立即出現。統一遊戲自動打字問題的c#對話框腳本
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class texttype : MonoBehaviour {
public float letterPause = 0.2f;
//public AudioClip[] typeSound1;
//public int next;
string message;
public GameObject textB;
public Text text;
public TextAsset textf;
public string[] lines;
public int currentLine;
public int endline;
void Start() {
if (text == null) {
text = GetComponent<Text>();
}
message = text.text;
StartCoroutine(TypeText());
if (textf != null) {
lines = (textf.text.Split('\n'));
}
if (endline == 0) {
endline = lines.Length - 1;
}
}
IEnumerator TypeText() {
foreach (char letter in message.ToCharArray()) {
text.text += letter;
yield return 0;
yield return new WaitForSeconds (letterPause);
}
}
void Update() {
text.text = lines [currentLine];
if (Input.GetKeyDown (KeyCode.Space)) {
currentLine += 1;
}
if (currentLine > endline) {
textB.SetActive(false);
}
}
}