0

I am new in Unity and trying to make a 2d simple car game. I got 4 mobile ui buttons that makes car accelerate, stop, move left, move right. I am using event triggers for every button to transmit the command to the car. PointerDown and PointerUp events correspond following functions: (the exception is every button's PointerUp event goes to 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();
    }

And carController class has following codes to operate:

    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;
    }

So far so good but here is the problem: When i test the game on my phone, the buttons dont work at the same time. I can not accelerate the car while steering left or right. Am i missing something important about event triggers?

metzelder
  • 655
  • 2
  • 15
  • 35
  • You need to store the pointer id in order to determine which button is down. `CrossPlatformInputManager` is already doing this for you. See the duplicate for how to get that – Programmer Dec 16 '17 at 20:00
  • Actually, i dont want a joystick. All i need is to have 2 buttons work at the same time. – metzelder Dec 17 '17 at 07:45

0 Answers0