[英]UI Button reference not visible in the inspector
I declared my Button[] public so i can reference it from my inspector我宣布我的 Button[] 是公开的,所以我可以从我的检查员那里引用它
but it does not appear in my inspector.但它没有出现在我的检查员中。 Please help!!!
请帮忙!!!
I tried restarting the C# as well as re-importing everything in unity....我尝试重新启动 C# 以及统一重新导入所有内容....
public rocket rocket;公共火箭火箭;
public Button[] levelButtons;
void Start()
{
for(int i=1 ; i<levelButtons.Length ; i++)
{
// if(i + 1 > rocket.level)
levelButtons[i].SetEnabled(false);
}
}
Button actually is GameObject include Component Button. Button 其实就是 GameObject 包括 Component Button。 And you should init size for Array you want to create before using it.
并且您应该在使用它之前为要创建的数组初始化大小。 I had edited code for example:
我编辑了代码,例如:
//Your array
public GameObject[] levelButtons;
//Object to attach Button
public GameObject panelShow;
//Size for Array
public int sizeArrayButton = 5;
void Awake()
{
//Init size for Array
levelButtons = new GameObject[sizeArrayButton];
for (int i = 0; i < levelButtons.Length; i++)
{
//Create new Object and random for position of Gameobject
GameObject button = new GameObject();
button.transform.parent = panelShow.transform;
button.AddComponent<RectTransform>();
button.AddComponent<Button>();
button.transform.position = new Vector3(Random.Range(100, 50), Random.Range(100, 26), Random.Range(-25, 26));
button.AddComponent<Image>();
button.GetComponent<Button>().onClick.AddListener(() => { Debug.Log($"Button: +{i}+ was clicked"});
levelButtons[i] = button;
}
}
And in Unity, you also make it by using List and Prefabs.在 Unity 中,您还可以使用 List 和 Prefabs 来实现。
so the issue is solved...so basically what i did was just update my unity version and then it allowed me to use UnityEngine.UI and the issue is now fixed...所以问题解决了......所以基本上我所做的只是更新我的统一版本然后它允许我使用UnityEngine.UI并且问题现在已经修复......
Thank you everyone for your time...much apppreciated谢谢大家的时间...非常感谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.