我试图使用现有的预制建立在C#代码按钮。所有我在网站上发现了类似添加按钮编程统一C#
public GameObject a;
public RectTransform ParentPanel;
void Start()
{
for (int i = 0; i < 5; i++)
{
GameObject goButton = (GameObject)Instantiate(a); /error
goButton.transform.SetParent(ParentPanel, false);
goButton.transform.localScale = new Vector3(1, 1, 1);
Button tempButton = goButton.GetComponent<Button>();
}
}
在Unity项目中,我有预制称为“ButtonPrefab”这里我把按钮对象。在下面的行中有错误
UnassignedReferenceException:NewBehaviourScript的变量a尚未分配。 你可能需要分配NewBehaviourScript脚本变量的检查。
我是新来统一。怎么会没有分配var a可以使用Instantiate()给我按钮?为什么我有这个错误?
如果它只是为了调试,你可能会逃脱这个http://docs.unity3d.com/ScriptReference/GUI.Button.html – slf
你是否从编辑器中拖动和跳转GameObject? –