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.