r/UnityHelp • • Apr 13 '21

Any understand this??

Post image
4 Upvotes

6 comments sorted by

1

u/globalmaster17 Apr 13 '21

Just says wrong imput format

1

u/globalmaster17 Apr 14 '21

Solved

So I binned of the 'convert' and stuck with 'parse' but the real problem was I was using GetComponent<textmeshprogui>().text to grab some text from an input field. This works fine for most cases however if you want to parse it doesn't. Turns out it was supposed to be GetComponent<TMP_inputfield>().text. I literally spent about 12 hrs sorting that but thanks 😊

1

u/lavatasche Apr 13 '21

You cant convert a string to int

1

u/Fancy_Edge2509 Apr 13 '21

my input field is a string number. I just want to do basic maths with it? surely its possible.

2

u/porphyrion09 Apr 13 '21

If your input string is just a number, maybe use Int.Parse() or Int.TryParse(). That's what I usually use when trying to get an int variable out of a string and it's never given me troubles before.

As far as I know, Convert methods are generally more useful for objects than basic data types. I could be wrong, I'm not exactly an experienced user myself, but I've also never needed to use Convert before.

1

u/lavatasche Apr 13 '21

A string is an array of chars. You can convert char to int.