title: Unity 2018: UI button OnPointerDown not function as expected
body: <p>I am testing the function of UI Arrow Button which is supposed to translate a car object in x and z position in a 3D scene. </p>
  
  <p>My target platform is WebGL. I coded both the control of keyboard arrow button for desktop and control of UI arrow button for both desktop and mobile. </p>
  
  <p>The keyboard control worked fine in PC but the UI arrow button didn't work as expected both in desktop and mobile. </p>
  
  <p>I logged the OnPointerDown() function which is in the script attached in the UI arrow button and the log didn't show up when the UI button was pressed down.</p>
  
  <p>How to get the UI arrow button function when it is pressed down?</p>
  
  <p>The Image of the Interface is here.
  <a href="https://i.stack.imgur.com/mK17G.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mK17G.png" alt="enter image description here"></a> </p>
  
  <p>And my scripts are here:</p>
  
  <p>the one attached to car object</p>
  
  <pre><code>using UnityEngine;
  
  public class CarPlayerControl : MonoBehaviour {
  
  public float speed = 40;
  private bool touchCtrl = false;
  private float xInput = 0f;
  private float zInput = 0f;
  
  void Awake(){
      //if (Input.touchSupported &amp;&amp; Application.platform 
           //     != RuntimePlatform.WebGLPlayer){
          //touchCtrl = true;
          //}
          }
  
  void FixedUpdate(){
  
      xInput = 0f;
      zInput = 0f;
  
      if (touchCtrl)
      {
          //if (Input.GetButton("ButtonUp"))
          //{
          //    xInput = 1.0f;
          //    Debug.Log("button up " + xInput);
          //}
          //else if (Input.GetButton("ButtonDown"))
          //{
          //    xInput = -1.0f;
          //    Debug.Log("button down " + xInput);
          //}
          //else if (Input.GetButton("ButtonLeft"))
          //{
          //    zInput = 1.0f;
          //    Debug.Log("button left " + zInput);
          //}
          //else if (Input.GetButton("ButtonRight"))
          //{
          //    zInput = -1.0f;
          //    Debug.Log("button right " + zInput);
          //}
      }
      else //mouse
      {
          xInput = Input.GetAxis("Horizontal");
          zInput = Input.GetAxis("Vertical");
      }
  
      Move(xInput, zInput);
  }
  
  public void Move(float xInput, float zInput)
  {
      float xMove = xInput * speed * Time.deltaTime;
      float zMove = zInput * speed * Time.deltaTime;
  
      float x = KeepXWithinRange(xMove);
      float y = transform.position.y;
      float z = KeepZWithinRange(zMove);
  
      transform.position = new Vector3(x, y, z);
  }
  
  private float KeepXWithinRange(float xMove){
      float x = transform.position.x + xMove;
      return Mathf.Clamp(x, 0, 900);
  }
  
  private float KeepZWithinRange(float zMove)
  {
      float z = transform.position.z + zMove;
      return Mathf.Clamp(z, -470, 500);
  }
  }
  </code></pre>
  
  <p>and the one attached to the UI Up arrow button</p>
  
  <pre><code>using UnityEngine;
  
  public class ButtonUpControl : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
  {
  public GameObject car;
  private CarPlayerControl carPlayerControl;
  private bool mouseDown;
  private float xInput;
  
  void Awake()
  {
      carPlayerControl = car.GetComponent&lt;CarPlayerControl&gt;();
      mouseDown = false;
  }
  void Start()
  {
  
  }
  
  void FixedUpdate()
  {
      if (mouseDown) {
          xInput = 1.0f;
      }
      else {
          xInput = 0f; 
      }
  
      carPlayerControl.Move(xInput, 0f);
  }
  
  public void OnPointerDown(PointerEventData eventData)
  {
      mouseDown = true;
      Debug.Log("on ptr down btn up ");
  }
  
  public void OnPointerUp(PointerEventData eventData)
  {
      mouseDown = false;
      Debug.Log("on ptr up btn up ");
  }
  }
  </code></pre>