Answers for "if statement for infinity. How to check if a variable is Infinity?"
http://answers.unity.com/questions/1393664/if-statement-for-infinity-how-to-check-if-a-variab.html
The latest answers for the question "if statement for infinity. How to check if a variable is Infinity?"Answer by Bunny83
http://answers.unity.com/answers/1393803/view.html
If you don't care if the value is PositiveInfinity orNegativeInfinity you can simply use [IsInfinity][1]
if(vectorForce.x.IsInfinity())
However if you want to distinguish between positive and negative infinity you would simply use:
if(vectorForce.x == float.PositiveInfinity)
// or
if(vectorForce.x == float.NegativeInfinity)
IsInfinity will return true in both cases. Note: if the infinity value isn't expected by you, you might want to investigate where it actually comes from. Common causes are that you divided your vector by "0". Dividing a value different from 0 by zero doesn't result in an error but in positive or negative infinity.
So in general it's better to handle that situation before you divide. Note that when you divide 0 by 0 it will result in a NaN value instead as 0/0 is not defined.
[1]: https://msdn.microsoft.com/en-us/library/system.single.isinfinity(v=vs.110).aspxTue, 15 Aug 2017 01:04:49 GMTBunny83Answer by tanoshimi
http://answers.unity.com/answers/1393675/view.html
I don't quite understand the use case, but you can test whether a float value is at its max possible using:
if(vectorForce.x == float.MaxValue)Mon, 14 Aug 2017 18:19:13 GMTtanoshimiAnswer by unidad2pete
http://answers.unity.com/answers/1393674/view.html
Try:
if (vectorForce.x == Mathf.Infinity)
{
Debug.Log("infinity");
}
or this:
if (vectorForce.x.ToString() == Mathf.Infinity.ToString())
{
Debug.Log("infinity");
}Mon, 14 Aug 2017 18:18:55 GMTunidad2pete