So… how’s it going?
If you’re comparing floating point numbers (such as transform.position.z) be sure you do so by asking if the difference between the two values is below a certain amount. NEVER check floating point numbers for equality. Here’s why.
Floating (float) point imprecision:
Never test floating point (float) quantities for equality / inequality. Here’s why:
https://starmanta.gitbooks.io/unitytipsredux/content/floating-point.html
Now that you have had your coffee, don't forget about floating point imprecision:
// @kurtdekker: don't forget about floating point imprecision
using UnityEngine;
public class FloatingPointImprecision : MonoBehaviour
{
void Start ()
{
float a = 2000.0f;
float b = 0.1f;
float product = (a * b);
float answer = 200;
Debug.Log( "a = " + a);
Debug.Log( "b = " + b);
Debug.Log( "product of a*b = " + product);
Debug.Log( "answer …
This will explain it all.
In an IEEE single-floating point number you can represent certain numbers perfectly and unambiguously.
For instance, 0.5f is precisely represented as 0x3f000000
However, 0.1f CANNOT be precisely represented. One possible approximate representation is 0x3DCCCCCD
The analogy is that you cannot show 1/3rd precisely as a decimal.
0.33 is correct to 2 decimal places
0.3333 is correct to 4 places
etc.
But you can never exactly represent 1/3rd as a decimal numeral. Yo…
How to report your problem productively in the Unity3D forums:
http://plbm.com/?p=220
This is the bare minimum of information to report:
what you want
what you tried
what you expected to happen
what actually happened, especially any errors you see
links to documentation you used to cross-check your work (CRITICAL!!!)
If you post a code snippet, ALWAYS USE CODE TAGS:
How to use code tags: Using code tags properly