相关疑难解决方法(0)

Unity从脚本创建UI控件

我通过代码创建了一个切换,但它不会显示.此外,我无法改变文本字段的位置.我尝试了很多,没有任何作用.这是我目前的版本,也许你看错了.

我是Unity新手,非常困难.

public class Game : MonoBehaviour 
{

    public GameObject canvas;

    void Start () 
    {
        GameObject newGO = new GameObject("myTextGO");
        newGO.transform.SetParent(this.transform);
        newGO.transform.position = new Vector3(0, 0, 0);

        Text myText = newGO.AddComponent<Text>();
        myText.text = "Ta-dah!";
        Font ArialFont =  
           (Font)Resources.GetBuiltinResource(typeof(Font),"Arial.ttf");
        myText.font = ArialFont;
        myText.material = ArialFont.material;
        myText.color = Color.black;
        myText.transform.position = new Vector3(0, 10, 0);

        GameObject secGO = new GameObject("myGO");
        secGO.transform.SetParent(this.transform);
        Toggle myToggle = secGO.AddComponent<Toggle>();
        myToggle.isOn = true;
        myToggle.transform.position = new Vector3(10, 10, 0);
    }
}
Run Code Online (Sandbox Code Playgroud)

c# toggle unity-game-engine unity5

7
推荐指数
1
解决办法
5019
查看次数

标签 统计

c# ×1

toggle ×1

unity-game-engine ×1

unity5 ×1