Unityscript Textfield Error

Hey guys, I’m pretty new to Unity, but I’ve been learning pretty quick. I’m having trouble making some text appear properly,

    var ammo;
    var remainingammo;

    var remainingfont : GUIStyle; // This font is 20px

    ammo = 100;
    remainingammo = ammo*1.8;

	GUI.TextField(Rect(645,Screen.height-38,80,30),remainingammo,remainingfont);

The problem I’m getting is “InvalidCastException: Cannot cast from source type to destination type.”
What I’m trying to have it do is to print the number over an ammo bar, and as the ammo is used, the number goes down. What I have provided is only a fraction of the whole code, but if it’s necessary to help you solve this, I can post the whole code. Does anyone have any insight on my problem?

Thanks in advance.

If we look at the documentation for the method GUI.TextField() we see that the format you are using wants:

Rect, String, GUIStyle

as the three parameters.

However, your variable, remainingammo is of data type “float” and that is probably what is causing the type error. Try the following as your code:

GUI.TextField(Rect(645,Screen.height-38,80,30),"" + remainingammo,remainingfont);

Note the usage of the String append as a converter.