If statement returning true without all conditions being met

The bool shouldChange is defaulted to false, and when it is true, and other conditions are met, the parent of the gameObject should change, however, the parent changes even when shouldChange is false. shouldChange is always, false, it never changes in this example.

        if (collision.CompareTag("hallway"))
        {
            bool shouldChange = false;
            
            Vector2 pos = transform.position;
            Vector2 parentPos = collision.transform.position;
            if (pos.x > parentPos.x + 3 || pos.x < parentPos.x - 3 && shouldChange) 
            {
                transform.SetParent(collision.transform);
                Debug.Break();
            }
        }

I have no idea why this is happening and I need a fix.

That’s an || or operator, so my guess is that the left side of your if statement pos.x > parentPos.x + 3 is true.

I would try this to make sure the If statement is separating the AND statement from the OR


if ((pos.x > parentPos.x + 3 || pos.x < parentPos.x - 3) && shouldChange)