【问题标题】:text mesh pro text isnt going in text slottext mesh pro 文本不会进入文本槽
【发布时间】:2023-01-12 22:07:15
【问题描述】:

很明显,我正在处理我的游戏对话,当然,我必须将文本放入我的代码的文本槽中。我试着把它放在插槽中,但没有用。我尝试将“Text”更改为“TextMesh”,但仍然没有用。

这是我为游戏尝试的代码。

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Goose : MonoBehaviour
{
   public GameObject dialoguePanel;
   public TextMesh dialogueText;
   public string[] dialogue;
   private int index;

   public float wordSpeed;
   public bool playerIsClose;

    // Update is called once per frame
    void Update()
    {
        if(Input.GetKeyDown(KeyCode.E) && playerIsClose)
        {
            if(dialoguePanel.activeInHierarchy)
            {
                zeroText();
            }
            else
            {
                dialoguePanel.SetActive(true);
                StartCoroutine(Typing());
            }
        }
    }



    public void zeroText()
    {
        dialogueText.text = "";
        index = 0;
        dialoguePanel.SetActive(false);
    }


IEnumerator Typing()
{
    foreach(char letter in dialogue[index].ToCharArray())
    {
        dialogueText.text += letter;
        yield return new WaitForSeconds(wordSpeed);
    }
}

public void NextLine()
{
    if(index < dialogue.Length - 1)
    {
        index++;
        dialogueText.text = "";
        StartCoroutine(Typing());
    }
    else
    {
        zeroText();
    }
}


    private void OnTriggerEnter2D(Collider2D other)
    {
        if(other.CompareTag("Player"))
        {
            playerIsClose = true;
        }
    }

    private void OnTriggerExit2D(Collider2D other)
    {
        if(other.CompareTag("Player"))
        {
            playerIsClose = false;
            zeroText();
        }
    }
}

【问题讨论】:

    标签: c# unityscript


    【解决方案1】:

    我想你需要的是public TMP_Text dialogueText

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-30
      • 2021-07-12
      • 2013-05-18
      • 2013-06-07
      • 2016-06-28
      • 2016-11-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多