Button OnClick not work that I think

Hello,

I have player object with this script:

    void Update()
    {
        startPos = gameObject.transform.position;
        if ((Input.GetKeyDown (KeyCode.RightArrow) || MobileRight == true) && gameObject.transform.position == endPos && gameObject.transform.position.x <= 2)
        {
            endPos = new Vector3 (transform.position.x + 1, transform.position.y, transform.position.z);
        }
        if ((Input.GetKeyDown (KeyCode.LeftArrow) || MobileLeft == true) && gameObject.transform.position == endPos && gameObject.transform.position.x >= -2)
        {
            endPos = new Vector3 (transform.position.x - 1, transform.position.y, transform.position.z);
        }

        gameObject.transform.position = Vector3.Lerp (startPos, endPos, perc);
    }

If on Keybord I pressed and hold Left or Right Arrow my player run only one in left or right direction(transform position +/- 1).
When I create button and click this my player run to the max in left or right direction.

I try OnClick, PointerDown with Pointer Up and PointerClick with this code

    public void Prawy()
    {
        MobileRight = true;
        MobileLeft = false;
    }
    public void Lewy()
    {
        MobileLeft = true;
        MobileRight = false;
    }
    public void Prawy(bool Pbool)
    {
        MobileRight = Pbool;
        MobileLeft = false;
    }
    public void Lewy(bool Lbool)
    {
        MobileLeft = Lbool;
        MobileRight = false;
    }

If somebody have any idea how I make button click script I will be grateful for help.

Input.GetKeyDown returns true only once, this means that your code is only executed once, therefore the jump +/-1.

But you never reset your MobileRight/MobileLeft flags, therefore the code is executed every frame. What you need to add is MobileLeft = MobileRight = false at the end of your update method.

Even better would be to move the code into a function and call it only once in your OnClick method of your button.