如何在Unity中同时操作两个ui按钮

时间:2017-12-16 19:55:59

标签: unity3d

我是Unity的新手,并尝试制作一款简单的2D游戏。我有4个移动ui按钮,使汽车加速,停止,向左移动,向右移动。我正在为每个按钮使用事件触发器将命令发送到汽车。 PointerDown和PointerUp事件对应以下函数:(例外情况是每个按钮的PointerUp事件都发送到MobileMoveStop)

 public void MobileMoveLeft()
    {
        carController.MobileMoveLeft();
    }

    public void MobileMoveRight()
    {
        carController.MobileMoveRight();
    }

    public void MobileMoveForward()
    {
        carController.MobileMoveForward();

    }

    public void MobileMoveBackward()
    {
        carController.MobileMoveBackward();
    }

    public void MobileMoveStop()
    {
        carController.MobileMoveStop();
    }

carController类有以下代码可供操作:

    public void FixedUpdate(){
      if(leftPressed){
       //operations
      }
      if(rightPressed){
       //operations
      } 
      .
      . 
      .
    }

   public void MobileMoveLeft()
    {
        leftPressed = true;
    }

    public void MobileMoveRight()
    {
        rightPressed = true;
    }

    public void MobileMoveForward()
    {
        upPressed = true;
    }

    public void MobileMoveBackward()
    {
        downPressed = true;

    }

    public void MobileMoveStop()
    {
        rightPressed = false;
        leftPressed = false;
        upPressed = false;
        downPressed = false;
    }

到目前为止一直很好,但问题是:当我在手机上测试游戏时,按钮不能同时工作。我左右转向时无法加速。我错过了关于事件触发器的重要事项吗?

0 个答案:

没有答案