|
Using C#, in the OnGUI function I just have something simple like this:
someFloatMemberVariable is of type float and is initialized to say 1.5, but when I type in the textfield another float, the decimal won't show up, and I always get a FormatException. Any thoughts?
(comments are locked)
|
|
The trick here is to use a string format for the variable which forces the decimal point. Like so: EDIT: It is also possible by adding a bool to store if a . is entered. Downside is that it needs a further variable:
(comments are locked)
|
|
when you trying to parse to float and parse value is not valid ("3.5g", "4.k3", ...), it throw exception you can write follow Yes, I know about try/catch and how it works. That doesn't solve my problem though.
Mar 01 '11 at 05:21 PM
jacksmash2012
(comments are locked)
|

I think when you get as far as typing "12." then the decimal point would be stripped by the parsing operation. You would have the same problem with trailing zeroes after the decimal. I suggest you let the user type into a string variable, then parse that into your float, rather than continuously converting the float to a string. Not sure about the format exception though.