Ciejkee
Ciejkee

Reputation: 111

Unity's New Input System for Mobile touch doesn't work

I'm creating a shooting system like angry birds with press/release in the new input system. It works with a mouse but I'm having trouble with mobile.

In input actions I assigned Shoot: [Left Mouse Button] & [Primary Touch/Touch Contact] [Touchscreen] for the same action, both with press and release behavior.

The mouse position is MousePosition: Position[Mouse] & Primary Touch/Position [Touchscreen]

    private void OnEnable()
    {
        controls.Gameplay.Enable();
        controls.Gameplay.Shoot.started += ctx => PlayerAimingStart(ctx);
        controls.Gameplay.Shoot.canceled += ctx => PlayerAimingCanceled(ctx);
    }
    
    private void PlayerAimingStart(InputAction.CallbackContext context)
    {
        Debug.Log("start");
        shootingPositionStart = controls.Gameplay.MousePosition.ReadValue<Vector2>(); shootingPositionStart.z = 0f;
    }
    
    private void PlayerAimingCanceled(InputAction.CallbackContext context)
    {
        Debug.Log("canceled");
        shootingPositionEnd = controls.Gameplay.MousePosition.ReadValue<Vector2>(); shootingPositionEnd.z = 0f;
        Shoot();

I have movement with the keyboard WASD keys and the onscreen joystick with Left Stick [Gamepad]; the joystick works fine with Unity Remote on an android phone. The Build setting is set to Android.

I've tried to print with debug.log without result. Also in the update function there was no input for MousePosition (for mobile using a mouse, it works). I tried to make another action TouchPosition with Primary Touchscreen [position] but also no results. Like my phone is dead but it somehow works with joystick.

Upvotes: 2

Views: 9257

Answers (2)

krnitheesh16
krnitheesh16

Reputation: 308

Yeah Unity Remote doesn't work with Unity's New Input System, but you can use Legacy Input System by enabling both in Edit -> Project Settings -> Player -> Active Input Handling to "Both".

For development, you can use "both" input systems and for production, you can switch to "New Input System" because only Unity's Remote doesn't support New Input System, but Your Mobile Build will work with New Input System

In Simple words:
Use "Both" Input for Remote Play (For Development)
Use "New Input System" for Mobile Build App (For Production) enter image description here

I'm just using this technique. It just works fine!

Upvotes: 4

Ciejkee
Ciejkee

Reputation: 111

The problem was that Unity Remote doesn't work with the New Input System.

Here is a thread about it. It now builds and works.

Upvotes: 0

Related Questions