unity3d 文本mesh pro文本不在文本槽中

lmvvr0a8  于 2023-01-26  发布在  其他
关注(0)|答案(1)|浏览(106)

很显然,我正在做我的游戏对话框,当然,我必须把我的代码文本槽的文本。我试图把它放在槽,但它没有工作。我试图改变“文本”为“文本网格”,但仍然,没有工作。

这是我的代码,我尝试了游戏。

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();
        }
    }
}
vq8itlhq

vq8itlhq1#

我觉得你需要的是public TMP_Text dialogueText

相关问题