- Home /
Do i need to make a Text variable for each variable i will use in the UI?
So I have a lot of variables that make up the character, lets say around 50+ do I need to cast them each of them into a public text variable?
private int var1 private int var2 private int var3 private int Va4.... private int var50
into public Text var1text; public Text var2text.... public Text var50text
then to a method that sets them depending on what we want
public void setText(Text varText, int varnumber){ varText.text = varnumber.ToString(); }
isnt there any other way to just print these on the UI without requiring me to double the amount in variables? Like with Java printText where all I gotta do is
private int var1;
printText("Stat: " + var1);
I am a java programmer but been finding C# to my liking, just want to know if there is other less typing consuming ways to print all these stats into the UI without me having to create Text duplicates for each of the variables I have in my character... its just crazy.. and what is with that putting Text vars as public? its so cringey....
Answer by UnityCoach · May 05, 2017 at 04:41 PM
You can use an array, a list or dictionary.
string [] textArray;
List<string> textList;
Dictionary<string, string> textDictionary;
dictionaries are especially useful for localisation, as you can provide a unique key.