My fallDamage gets returned as something like 10.2367844 depending on distance.
How can I round this up or down in script?
I could just say if var > 1 but < 2 = 1, but I'd have to do that right the way through to 100.
Is there an easier way?
My fallDamage gets returned as something like 10.2367844 depending on distance.
How can I round this up or down in script?
I could just say if var > 1 but < 2 = 1, but I'd have to do that right the way through to 100.
Is there an easier way?
Use Mathf.Round, Mathf.Ceil, Mathf.Floor, or cast them to ints:
int asInt = (int)floatValue;
For your example, you want to use Mathf.Floor or int casting, depending on your needs. Mathf.Floor return a float value. Casting returns of course an int value. Both approaches will get rid of any decimals.
You can use .Net functions in your scripts, take a look at Round function documentation:
http://msdn.microsoft.com/en-us/library/system.math.round(v=vs.71).aspx
Take a look at Mathf functions too:
http://unity3d.com/support/documentation/ScriptReference/Mathf.html
http://unity3d.com/support/documentation/ScriptReference/Mathf.FloorToInt.html
Example:
// Prints 10
Debug.Log(Mathf.FloorToInt(10.7));