0

I am trying to Debug None in console when transform position x of line1 equals to a specific value, but even when condition gets true, the block is not executing, can anyone help? Thanks

this is my code

Ruzihm
  • 19,749
  • 5
  • 36
  • 48
Jay
  • 11
  • 1
  • 4

1 Answers1

0

I'm guessing it's because you're comparing a float value with a very particular (float) value.

So the real value is perhaps 510.70128374628734 which is not equal to 510.701, but when it is rounded off in the inspector it is.

Try changing your logic to use > or < instead, or use something like Vector3.Distance(pos1, pos2) < 1. (https://docs.unity3d.com/ScriptReference/Vector3.Distance.html)

Other things to verify in the case of "it's true but isn't running" is to make sure that you didn't forget to attach the script to the object.

Fredrik Schön
  • 4,888
  • 1
  • 21
  • 32