Testing x value when using transform.translate

I have a cube which I move using transform.Translate like this:

transform.Translate(rate * Time.deltaTime,0,0);

I want to detect when x is a exactly specific value (for example, 10) but doing this doesn’t work:

		float x = -cube.transform.position.x;   //using negative value because cube is going backwards on x-axis
		if(x == 10){
			Debug.Log("x is 10!"); //This text does not show in Console
		}

I’m guessing this doesn’t work because it is going so fast that it can’t exactly detect when x is 10. What options do I have here? I’m doing this for procedural generation.

It will never be exactly 10.0 regardless of how fast it’s going due to Time.deltaTime, and floating point imprecision. You can detect if it’s greater than 10.0, or use Lerp instead of Translate.

Floats are never going to be accurate like that. As said in the other answer you can act on >= or you can use Mathf.Approximately