【发布时间】:2023-02-22 09:50:13
【问题描述】:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class Text : MonoBehaviour
{
Text txt;
string story;
public bool PlayOnAwake = true;
public float Delay;
void Awake()
{
txt = GetComponent<Text>();
if (PlayOnAwake)
ChangeText(txt.Text, Delay);
}
//Update text and start typewriter effect
public void ChangeText(string _text, float _delay= 0f)
{
StopCoroutine(PlayText()); //stop Coroutime if exist
story = _text;
txt.text = ""; //clean text
Invoke("Start_PlayText", _delay); //Invoke effect
}
void Start_PlayText()
{
StartCoroutine(PlayText());
}
IEnumerator PlayText()
{
foreach (char c in story)
{
txt.text += c;
yield return new WaitForSeconds(0.125f);
}
}
}
错误 CS1061:“文本”不包含“文本”的定义,并且找不到接受类型为“文本”的第一个参数的可访问扩展方法“文本”(是否缺少 using 指令或程序集引用?)
【问题讨论】:
标签: c#