UI Buttons sometimes not detecting touch

Hi.

I’m making a 2D game and I’m trying to port this to Android. I’m using script below to touch left and right side of screen to move player (with OnPointerUp and Down). Unfortunately sometimes game not recognizing I’ve touched button. It’s totally random. Can someone tell me, what’s going on? (sorry for my English btw)

Best Regards.

Script:

    public bool moveLeft;
	public bool moveRight;
	public float buttonsSpeed;

	public void Buttons()
	{
		if (moveLeft && !moveRight)
			GetComponent<Rigidbody2D> ().transform.Translate (Vector3.left * buttonsSpeed);

		if (moveRight && !moveLeft)
			GetComponent<Rigidbody2D> ().transform.Translate (Vector3.right * buttonsSpeed);
	}

	public void MoveMeLeft()
	{
		moveLeft = true;
	}

	public void StopMeLeft()
	{
		moveLeft = false;
	}

	public void MoveMeRight()
	{
		moveRight = true;
	}

	public void StopMeRight()
	{
		moveRight = false;
	}

so your player cant stop moving,his going to left or right;

just change your code to it

 public void MoveMeLeft()
 {
     moveLeft = true;
                      moveRight = false;
                       }

         public void MoveMeRight()
              {
        moveLeft = false;
               moveRight = true;
             }

and you don’t need a pointer up function anylonger if your character can’t stop moving.
and if you want your character to stop just in pointer up function call stop moving function hope this helps.