Adding a int and a float?
This seems like a dumb question but is there no way to covert ints to floats and vice versa to add them together? I figured something like this would work int num = Mathf.round(myFloat);
but it doesn't. Anyway around this? or should I just use floats for everything and round?
C# is a real language, so you can find lots and lots of this on regular C# sites. For example, Convert.ToInt is on the microsoft site (and many other places) or you might see the shorter (int) caste, which ShadyProd is suggesting.
Those sites will probably explain more about computer math in general, like why 5/3 is 1.
Answer by Astraphobia95 · Jan 27, 2016 at 10:49 AM
Mathf.Round (Don't forget the capital R, syntax matters) will still return a float, although it will be rounded to the nearest integer. If you want to then turn this float into an int, you need to convert it. Try using something like this:
int num = Convert.ToInt32(Mathf.Round(myFloat));
Answer by Yetter · Jan 27, 2016 at 02:22 PM
Hmm, tried that, I get the error 'The name 'Convert' does not exist in the current context. And I always have had the R capitilized, just missed it in my example question. Thanks for the reply anyways
int num = int($$anonymous$$athf.Round(myFloat));
Oh my bad, just add using System;
to your references at the top of the page and it will work fine.