Unity Create UI controle a partir do script
Eu criei uma alternância por código, mas ela não será exibida. Além disso, não posso mudar a posição do meu campo de texto. Eu tentei muito e nada funciona. Esta é a minha versão atual, talvez você veja o erro.
Sou novo na Unity e é muito difícil.
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);
}
}