How to change the text inside UI>Text
I want to show player points in a Text box. How can i make that using a script? I put the default text as "0" and i want to change it to "1","2",....."n". I tryied this:
public class SomeClass : MonoBehaviour
{
Text myText;
public void Start()
{
myText = GetComponent<Text>();
}
public void UpdateText()
{
mytext.text = "Some new string value";
}
}
but I get this error: The type or namespace name `Text' could not be found. I am using the latest version of Unity
Answer by Positive7 · Sep 17, 2015 at 05:07 PM
With using UnityEngine.UI;
using UnityEngine;
using UnityEngine.UI;
public class SomeClass : MonoBehaviour
{
Text myText;
public void Start()
{
myText = GetComponent<Text>();
}
public void UpdateText()
{
myText.text = "Some new string value";
}
}
also i found that i can just add +variableName after "Some new string value" and the value will be displayer, very cool.
Your answer
Follow this Question
Related Questions
Is it possible for camera to detect a collision between 2 different objects it's looking at? 0 Answers
UI and GUI not updating score? 1 Answer
Score wont display 0 Answers
I have this code and I want every time you destroy the hexagon to add + 1 to the text 0 Answers
UI text script working on an object but not working on copied object 0 Answers