- Home /
Question by
BDX777 · Jan 19, 2015 at 02:43 PM ·
textclassuser interfacename
Changing Text in new UI tools via script?
Hi, I am wondering what the class name for the new Text script is, as I want to write a script that changes it's text.
Edit: Add "using UnityEngine.UI"
Comment
Best Answer
Answer by Ultroman · Jan 19, 2015 at 03:43 PM
The class name is 'Text'
For C#, do something like this (for JS, chariot's comment has some sample-code):
using UnityEngine;
using UnityEngine.UI;
// attach the Text-object from your scene to this using the inspector
public Text myGuiText;
void Update(){
myGuiText.text = "I love text. I love it good!";
}
or get the component from script:
using UnityEngine;
using UnityEngine.UI;
private Text myGuiText;
void Start(){
myGuiText = GetComponent<Text>();
}
void Update(){
myGuiText.text = "I love text. I love it good!";
}
For JS
private var textField : UI.Text;
void Start () {
textField = GetComponent(UI.Text);
textField.text = "Ur text";
}
and don't forget to put
using UnityEngine.UI;
For C# or
import UnityEngine.UI;
For Javascript.
Not important to import UI, if u use only one thing from here