【发布时间】:2018-10-29 20:28:41
【问题描述】:
我试图在 Unity 中打开场景时更改 Button 的文本。我尝试了不同的方法来更改 Button 的文本。
这是我的代码:
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";
}
}
【问题讨论】:
-
您要创建动态按钮吗?
-
究竟是什么不工作/行为与您的预期不同?
-
它给了我这个错误:Assets/Scripts/script.cs(15,43): error CS0030: Cannot convert type
UnityEngine.UI.Button' toUnityEngine.GameObject' -
是的,它会因为 GameObject b1object = (GameObject)Instantiate(b1); 而出现该错误;