Need help with UI.text
So, im making csgo bomb for airsoft and i need some help.
Then i click one of the buttons UI.text appears on the screen. Then i press 1 for example and then press 2, 1 disappears. I know why but i have not been able to fix that.
var Text : UnityEngine.UI.Text;
var On = 1;
function OnMouseDown ()
{
if(GameObject.Find("1"));
Text.text = "" + On;
}
Those "" are causing old text to go away.
$$anonymous$$aybe += works in this situation, to append the data rather than overwrite it. It might not. In any case you should be using On.ToString().
You simply need to record what was previously in the Text field and add to it.
Also, dont call your variable "Text". That name is already taken! Use var myText or something like that. We conventionally start variables with lower case letters to tell them apart from Functions, $$anonymous$$ethods, Classes and Types.
Answer by ComradeVanti · Mar 19, 2016 at 02:24 PM
This happens because you set your text to "" witch is nothing + your variable. So whatever was there before gets deleted.
What you really want is:
Text.text = Text.text + On.toString();
By using the command above you just add your new variable to the already existing text.
Good luck! :)
$$anonymous$$y heroes! =) Unity has such nice community!
Your answer
Follow this Question
Related Questions
How do You add a Scrollbar in a textbox C# code 0 Answers
Help with arrays of arrays please 2 Answers
Input Field Problem 0 Answers
uGUI Text draw calls 1 Answer
null reference exception with text 0 Answers