Problem displaying a variable with UI Text
Hi, i created a UI.Text object to display the number of gold colected in a clicker game, but it only displays the tet directly inputed into the text box. this is the script that i used to try to display it.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Click : MonoBehaviour {
public int Gold = 0;
public int goldPerClick = 1;
public Text goldDisplay;
void start()
{
countGold();
}
void update()
{
countGold();
}
public void Button(){
Gold = Gold + goldPerClick;
}
void countGold()
{
goldDisplay.GetComponent<Text>().text = "Gold: " + Gold.ToString();
}
}
i tried using: goldDisplay.text = "Gold: " + Gold.ToString(); goldDisplay.GetComponent().text = "Gold: " + Gold; goldDisplay.GetComponent().text = "Gold: " + Gold;
the variable changes but the text isnt displayed. can anyone help me?
Answer by saschandroid · Jun 29, 2016 at 07:55 AM
Programming is case sensitive. You have to use Update()
and Start()
otherwise these functions aren't called by unity.
Oh that i didnt know, since i just programmed in jprocessing and c# is fairly similar to java i thought it wasnt case sensitive. Thank you
People with typical aggressive IDEs can easily not know their language is case-sensitive. They may have heard it mentioned once, but you type "FOR" and the IDE automatically lower-cases and turns it cyan. You know the cyan is to make it pretty, so you can easily assume the lower-casing is also cosmetic.
That's probably why so many mess up Update and OnTriggerEnter.
And, just to be thorough, program$$anonymous$$g itself isn't case-sensitive. There are non-case-sensitive languages, just not so common any more.
Your answer
![](https://koobas.hobune.stream/wayback/20220612083821im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
UI TEXT not showing up in game mode 1 Answer
GameObject destroyed when changing scene 1 Answer
uGUI Text draw calls 1 Answer
I can't change Text color 3 Answers