I just wrote a bit of code for my shop system and a very simple line wasn't working:
...
if (dir == "left" && rect.anchoredPosition.x != -217.5f) {...}
...
The code in the {} would still run if the anchored position.x was -217.5. But some lines under there is this line:
...
else if(rect.anchoredPosition.x != 217.5f)
...
and that worked fine!
Later I changed the first line to:
if (dir == "left")
{
if (rect.anchoredPosition.x != -217.5f)
{
...
}
}
...
and that worked fine, just as intended.
I checked the anchored position several times, so it wasn't it's fault. I know that dir was "left" so that one was true, but the anchored was -217.5 so it should've returned false.
I don't know why it did this. In the end it doens't matter, because with the two if-statements seperate it works, but I still want to understand why.
Thanks