Assigning a variable to my label
Hello fellow coders: I'm currently working on a small tower defense game of sort. I'm using NGUI for my user interface. However, I've been having difficulties assigning variables to my Labels. I'm trying to have a Scoreboard that shows up at the end of each level. I've created an empty Gameobject called Scoreboard and added different Labels as its children. I created a script called Statistics inside Scoreboard that should handle all the different variables (which is working fine). But I cant get my labels to show the result of that script.
So to be brief, how can I assign the Label.text a specific variable instead of a static text. I believe that I might need to getcomponent() but I'm not quiet sure which/how.
public static var DamageDone : float;
public static var DamageReceived : float;
public static var Experience : float;
public static var EnemiesKilled : int;
public static var EnemiesCrossed : int;
public static var BossesKilled : int;
public static var HealthRemaining : float;
public static var ShocksLeft : int;
public static var Duration: float;
public static var TotalScore : float;
function Update () {
Scoreboard.EnemiesKilledLabel.text = EnemiesKilled; //Assigning variable to label
}
Thanks, Have a good day!
Answer by Jason2014 · Mar 11, 2016 at 06:24 PM
If you have a numeric variable and want to write value in a text you need to add "ToString" function with empty parenthesis. That's all!
Scoreboard.EnemiesKilledLabel.text = EnemiesKilled.ToString ();