我需要放什么?

问题描述 投票:0回答:1
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# unity3d
1个回答
0
投票

文字要小t,也就是文字

ChangeText(txt.text, Delay);

错误信息表明Text类没有名为Text的属性或字段。这是因为Unity中的Text类已经有一个名为text的属性加上小写的“t”,代表UI元素的文本内容

© www.soinside.com 2019 - 2024. All rights reserved.