作者是一名OIer,因为兴趣,想在寒假期间开发一款文字游戏的demo。
本博客仅用作记录,马蜂极度不符合规范。
但是,可以用来避坑。
1.等待功能——使用的是协程函数,且调用与常规调用函数不同。
private IEnumerator Sco(){isScoelling = 1;senten.text = "";foreach(char letter in dialog[dires].ToCharArray()){senten.text += letter;yield return new WaitForSeconds(textspeed);//等待多久}isScoelling = 0;}StartCoroutine(你要用的函数);//调用
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using System;public class bplan : MonoBehaviour
{// Start is called before the first frame updatepublic TMP_Text senten;public float textspeed;string[] dialog = new string[1001] ;int tot = 0;void add(string a){dialog[tot] = a;tot++;}void Start(){TextAsset txt = Resources.Load("test01") as TextAsset;//Debug.Log(txt);dialog = txt.text.Split('\n');}// Update is called once per frameint dires = 0;int isScoelling = 0;private IEnumerator Sco(){isScoelling = 1;senten.text = "";foreach(char letter in dialog[dires].ToCharArray()){senten.text += letter;yield return new WaitForSeconds(textspeed);}isScoelling = 0;}void Update () {if (Input.GetKeyUp(KeyCode.A)&&isScoelling == 0){dires++;StartCoroutine(Sco());}}
}