1、先新建一个canvas,在canvas右击--UI--Button-TextMeshPro,新建一个button
canvas设置,要不然运行时看不到按钮
给按钮设置背景颜色
设置字体颜色和大小
写一个脚本监听它的点击事件,改变它的文字
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class buttonClick : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
GetComponent<Button>().onClick.AddListener(delegate ()
{
// 点击监听
TMP_Text a = GetComponentInChildren<TMP_Text>();
a.text = "我点击了按钮";
});
}
// Update is called once per frame
void Update()
{
}
}
点击前后对比