エラーコードはこれです。IndexOutOfRangeException: Index was outside the bounds of the array.
セリフ用2.Update () (at Assets/セリフ用2.cs:34)
構文は
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class セリフ用2 : MonoBehaviour
{
public string[] texts;//Unity上で入力するstringの配列
int textNumber;//何番目のtexts[]を表示させるか
string displayText;//表示させるstring
int textCharNumber;//何文字目をdisplayTextに追加するか
int displayTextSpeed; //全体のフレームレートを落とす変数
bool click;
bool textStop; //テキスト表示を始めるか
void Start() { } private void Update() { transform.position = Vector3.one; // コルーチンの起動 if (textStop == false) //テキストを表示させるif文 { displayTextSpeed++; if (displayTextSpeed % 5 == 0)//5回に一回プログラムを実行するif文 { if (textCharNumber != texts[textNumber].Length)//もしtext[textNumber]の文字列の文字が最後の文字じゃなければ { displayText = displayText + texts[textNumber][textCharNumber];//displayTextに文字を追加していく textCharNumber = textCharNumber + 1;//次の文字にする } else//もしtext[textNumber]の文字列の文字が最後の文字だったら { if (textNumber != texts.Length - 1)//もしtexts[]が最後のセリフじゃないときは { StartCoroutine(DelayCoroutine(5, () => { // n秒後にここの処理が実行される displayText = "";//表示させる文字列を消す textCharNumber = 0;//文字の番号を最初にする textNumber = textNumber + 1;//次のセリフにする transform.position = Vector3.zero; })); } else //もしtexts[]が最後のセリフになったら { StartCoroutine(DelayCoroutine(5, () => { // n秒後にここの処理が実行される displayText = ""; //表示させる文字列も消す textCharNumber = 0; //文字の番号を最初にする textStop = true; //セリフ表示を止める transform.position = Vector3.zero; })); } } this.GetComponent<Text>().text = displayText;//画面上にdisplayTextを表示 click = false;//クリックされた判定を解除 } if (Input.GetMouseButton(0))//マウスをクリックしたら { click = true; //クリックされた判定にする } } } // Update is called once per frame // Update is called once per frame private IEnumerator DelayCoroutine(float seconds, Action action) { yield return new WaitForSeconds(seconds); action?.Invoke(); }
}
です。
いろいろ間違っていてもご了承ください

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/04/02 12:10