I have been searching for something that should be simple, but Unity 5's documentation on that is fairly outdated. What I want to achieve is to be able to create UI Text totally from script, i.e. fully dynamically - in my real case application, I will do that in a loop of not pre defined number of iterations.
A search using Google will find quite many examples on how to do that, but all I saw either use methods that are already deprecated (are from before Unity version 5) or are simply wrong (no surprise here...). I already know that I should first add a Canvas to my project, then I should include using UnityEngine.UI
in my C# code, and also that I could declare a UI Text like Text _guitext
.
However, the code below does not work. I mean, it's not that it crashes, but rather that nothing is shown:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class MyClass: MonoBehaviour {
Text _guitext;
// Use this for initialization
void Start () {
_guitext.text = "testing";
}
// Update is called once per frame
void Update () {
}
}
Worse than that, it seems that while game is played, no new object appears in the object hierarchy list.
Could you please point me out in the right direction here? Thanks.