So im trying to convert my floating number to a String using the ToString() function, but im getting the error 'Cannot convert 'String' to 'float'', which is the opposite of what im trying to achieve.
What i am actually trying to do is to create a Lap Timer where it displays the Mins, seconds and hundredths of seconds but im way off this as i can even convert my data types from a float to a string which is rather annoying.
First post on here so go easy on me please :P
min = "0" + min.ToString(); }
you declare the variable min as a float....
And then you try to assign a string to it..
So that's why it's complaining. You do the same thing with sec, though the typing there is implied rather than explicit.
unityscript doesn't let you change a variable's type on the fly like this. You'll need to use a separate variable of type string to hold these results.
answered Nov 17 '11 at 01:38 PM
Well, the problem is pretty much as the title says! You shouldn't be trying to assign the result of a 'ToString()' function back to the variable which you are calling it on. Instead, you should create new variables of the correct type, which you use for the GUI.
These bits are correct-
These bits are bad (trying to put a string into a float-shaped hole)-
Instead, make new string variables to hold this information
On a side note, why don't you use an integer for the 'minutes' value? I don't think you'll ever want to have decimal values there, so there's no reason not to.
answered Nov 17 '11 at 01:47 PM