v4.6 Create GUI Elements Via Script?


I am a little bit affraid, because I think the solution must be so easy…
BUT, like the title says, I want to create a Text just like

Text text = new Text();

maybe also

Text str = new Text("Hello");

But it keeps saying “`UnityEngine.UI.Text.Text()’ is inaccessible due to its protection level”

So, is it just not possible?

Thanks in advance


UI elements are components just like most things you use in unity, so just call AddComponent():

Text text = gameObject.AddComponent<Text>();
text.text = "Hello";