我将尝试在Unity场景打开时更改按钮的文本。我尝试了不同的方法来更改按钮的文本。
这是我的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class script : MonoBehaviour {
public Button b1;
public TMP_Text b1text;
void Start()
{
GameObject b1object = (GameObject)Instantiate(b1);
b1text = b1object.GetComponentInChildren<TMP_Text>(true);
btnValue();
}
public void btnValue()
{
b1text.text = "sdfa";
}
}
UnityEngine.UI.Button' 转换为
UnityEngine.GameObject'。 - Ak Pasaf