Now in Unity there are at least three standard ways to display text on the screen:
old UI (as you specified via OnGUI ())
new ui
via TextMesh (better to use when you need to display text in the game space, rather than via UI)
If I understand the question correctly, then you need the Text component in the new UI. Then an option for an example:
- We add in the hierarchy of the scene a new UI-> Text
- In the necessary script, add the field public Text MyTestLabel;
- The script must be added to any element in the hierarchy (for example, some kind of scene controller, or even a UI object itself, it depends on your architecture).
- In the scene element inspector, to which you connected the script, drag an element into the appeared field (via the scene hierarchy)
- For example, in the Start () method, add the line MyTestLabel.text = "Hello world";
The position on the screen for the Text component will be set in the editor.
Try adding a Debug.Log in the Start () method (the name of the variable, the value you want to display); It is possible that at this moment the desired value is not ready. Transfer to Update, for example. Look at it, what is the value of the variable
In addition, if the script is inherited from the Monobehaviour class, then all standard functions such as Start (), Update (), etc. available for definition.
Awakemethod yourself, nobody forbids you) - Alexey Shimansky