【问题标题】:What do I need to put?我需要放什么?
【发布时间】: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#


    【解决方案1】:

    text应该是小t,也就是text

    ChangeText(txt.text, Delay);
    

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

    【讨论】:

      猜你喜欢
      • 2014-04-10
      • 1970-01-01
      • 2019-06-09
      • 2012-05-21
      • 1970-01-01
      • 1970-01-01
      • 2011-02-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多