Unity detect left/right/up/down

I am implementing my code on an object and the player’s hand is the origin to detect if it is in the direction of right/left/up/down.

So far the code is working to detect all 4 axis but there is a problem. If the direction is left/right, it prints both “Left” and “Up”, similarly “Right” and “Up”. Can it be just “Left” or “Right” and not print the y axis along with it?

How do I fix this?

public GameObject playersHand;
private Transform targetOrigin;
private Vector2 targetPos;
private Vector2 mypos;

void Start()
{
    targetOrigin = this.gameObject.transform;
}

void Update()
{
    mypos = playersHand.transform.position;
    targetPos = targetOrigin.position;

    if (targetOrigin.position.x < mypos.x && changed(mypos.y, targetPos.y))
    {
        print ("Right");
    }
    else if (changed(mypos.y, targetPos.y))
    {
        print ("Left");
    }

    if (targetOrigin.position.y < mypos.y && changed(mypos.x, targetPos.x))
    {
        print ("Up");
    }
    else if (changed(mypos.x, targetPos.x))
    {
        print ("Down");
    }
}

bool changed(float a, float b)
{
    if ((int)a == (int)b)
    {
        return true;
    }
    else
    {
        return false;
    }
}

could add return; after the print (so it doesn’t continue the loop further)

but maybe instead of that,
you’d want to check which one is larger value, left or up, then print that?

I tried to do return; but that would just stop at left/right and would not check up or down. I can try to check which value is higher perhaps.

Well its strange, left value is like 0.0012 something and up is like 1.234 something, even when the direction is in left, the up value remains higher.