Support => NGUI 3 Support => Topic started by: Demigoth on March 13, 2014, 09:40:38 PM
Title: Assign a variable value to a UILabel
Post by: Demigoth on March 13, 2014, 09:40:38 PM
Hey guys,
So I have these variables in a Player.cs file, like health and gold and a bunch of public variables that constantly change in game, so I was wondering I have a UITexture with a child UILabel on it but I cant seem to find a way to assign the label text this variables value. Any help would be greatly appreciated. I was trying something like this:
public UILabel healthLabel;
void Update()
{
healthLabel.text= Player.health.ToString();
}
Any help would be great!
Victor
Title: Re: Assign a variable value to a UILabel
Post by: rain on March 14, 2014, 06:44:15 AM
What is 'Player' in this context? The class itself? An instance? Your code should work as long as neither 'healthLabel' , 'Player' and 'Player.health' is null.
If Player is actually a class and not an reference to an instance, you should have something in your script like
public Player player;
And then assign value to it via inspector or code. After that, you can easily reference it in your Update method (example full script):