iLMS知識社群歷程檔登入
位置: 黃國哲 > Unity
1100930 TextMeshPro自動填字
by 黃國哲 2021-09-30 09:45:59, 回應(0), 人氣(625)

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

public class searchitem : MonoBehaviour
{
    public TextMeshProUGUI itemtext; //提取名字為 itemname.text  //TMP_Text
    private string itemname;

    public void getnamebtn()
    {
        itemname = itemtext.GetComponent<TextMeshProUGUI>().text ;
        { GameObject.Find(itemname).GetComponent<ItemDisplay>().enabled = true; }
    }


    public void leavenamebtn()
    {
        itemname = itemtext.GetComponent<TextMeshProUGUI>().text;
        { GameObject.Find(itemname).GetComponent<ItemDisplay>().enabled = false; }
    }
}



///////////////////

using UnityEngine;
using System.Collections;
using TMPro;

public class ExampleClass : MonoBehaviour
{
    void Example()
    {
        TextMeshPro textmeshPro = GetComponent<TextMeshPro>();
        textmeshPro.SetText("The first number is {0} and the 2nd is {1:2} and the 3rd is {3:0}.", 4, 6.345f, 3.5f);
        // The text displayed will be:
        // The first number is 4 and the 2nd is 6.35 and the 3rd is 4.
    }
}
回應