- Home /
New 4.6 UI text
How do I change or target the text script through code? Where is the old 3D text from before 4.6? (TextMesh)
Answer by AyAMrau · Sep 01, 2014 at 03:40 PM
You can still add a TextMesh component to an object if you want.
And when using a new text is:
gameObject.GetComponent<Text>().text = "new text";
to change the string value of the text.
Requires: using UnityEngine.UI;
I think that should be:
gameObject.GetComponent<Text$$anonymous$$esh>().text = "new text";
To clarify, the new UI system doesn't use Text$$anonymous$$esh any more. The new component is called Text. It's part if the UnityEngine.UI namespace.
Answer by exorakhilas · Jan 30, 2015 at 08:49 AM
Hi. Not sure if this is helpful but I hope it does.
#pragma strict
var dt : System.DateTime = System.DateTime.Now;
var h : int = dt.Hour;
var m : int = dt.Minute;
var displayTime : String;
var s : int = dt.Second;
function Start () {
displayTime = gameObject.GetComponent(UI.Text).text;
}
function Update () {
displayTime = (h+":"+m"+s);
gameObject.GetComponent(UI.Text).text = displayTime;
}
This did display the time but only the one that was at the time of saving the script or applying to gameobject, I believe theres a refresh each second function missing. Correct me if I'm wrong, I'm using these forums to learn :D
And also 1 digit values such as 2 dont have a 0 before them, how do i apply that to use with a clock? I believe it has something to do with int?
Your answer