- Home /
[4.6 UI] Show text as an int variable error
Hello Unity Community!
I'm having troubles scripting a text in the new 4.6 UI, in trying to access the text in the script and make it shows an int variable. I think the script it's right but I can't understand why it doesn't work. Unity's console shows this error "BCE0022: Cannot convert 'int' to 'String'.". This is the script:
var playerDamage : playerScript;
var myText : UnityEngine.UI.Text;
function Update () {
myText.text = playerDamage.damageHit;
}
I can't understand this because I can write the number in the text field in inspector and Unity doesn't give any error but I need to use my variable. The variable it's in another script but it's just a number which it's changing constanly.
Answer by VesuvianPrime · Feb 01, 2015 at 05:52 PM
Try:
myText.text = playerDamage.damageHit.ToString();
Answer by Derek-Wong · Feb 01, 2015 at 05:55 PM
Or you can use a magic
myText.text = ""+playerDamage.damageHit;
Your answer
Follow this Question
Related Questions
I can't print a int.ToString() variable in a guiText.text 1 Answer
Displaying variable on UI text every frame (JS) 1 Answer
InputField in a different scene to Text 1 Answer
Variable data type for two ints (x and y) in inspector 3 Answers
Problem with variables,Problem with identifying a variable 2 Answers