- Home /
UI text showing money
I want to make a text on my screen that is showing money. Example: Money: 217 . How do i do that? i tried using this code:
GetComponent<GUIText> ().text = "Money:" + database.money;
but its GUIText but my UI text does not have that component if i do add it nothing changes only text (script) text is showing up. Can someone tell me how to do this? i tried searching everywhere but all is outdated. I am using unity 5 beta purchased.
The database.money is from a script from other gameobject. it has a value there. public int money = 0; the value changes.
Answer by tigertrussell · Mar 17, 2015 at 02:26 PM
You don't use GUIText
if you're on 4.6 or higher.
Use UnityEngine.UI.Text
like this:
using UnityEngine.UI;
// ...
Text t = GetComponent<Text>();
t.text = "Money: " + database.money;
Answer by dr3th · Mar 17, 2015 at 03:50 PM
You should be using UnityEngine.UI.Text it's apart of unity 5.
using UnityEngine.UI;
Find Your UI Text.
GameObject textGameObj= GameObject.Find("myText");
Set the text
textGameObj.GetComponent<Text>().text = "Money:" + database.money;
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Request feedback for C# script (instantiating UI elements depending on Player Input) 0 Answers
UI Decreasing Timer Bar Not Executing Print? 1 Answer
How to make a GUI Tabel. 0 Answers