Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question Onscreen Butten and Onscreen Stick isn't working

Discussion in 'Input System' started by Aniruddha_03, Aug 7, 2023.

  1. Aniruddha_03

    Aniruddha_03

    Joined:
    Jul 31, 2023
    Posts:
    2
    I have put 2 buttons on canvas and both has got on-screen button, which which is supposed to act as gamepad left stick/ left and right. So in Input Actions, I set gamepad left stick/left and right bindings, and player object has been set a player input which has call back context of gamepad, which should call a method, which prints "Touch Fired", atleast that's how I want it to work. But when I click those buttons while game is running, nothings prints in the console. But the keyboard actions that i have set works correctly. So i tried setting up a dummy onscreen stick, and in run mode im able to move the stick but that also isnt firing the OnTouch method which is supposed to print "Touch Fired" in console.

    PlayerControls.cs :

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.InputSystem;
    3.  
    4. public class PlayerControl : MonoBehaviour
    5. {
    6.     public Rigidbody rb;
    7.     public float forwardForce = 2000f, horForce = 2000f;
    8.  
    9.     private float inputMovement = 0, rawInput;
    10.  
    11.     [SerializeField] private PlayerInput playerInput;
    12.  
    13.     public void OnMovement(InputAction.CallbackContext value)
    14.     {
    15.         Debug.Log("Keyboard Fired");
    16.         inputMovement = value.ReadValue<float>();
    17.     }
    18.  
    19.     public void OnTouch(InputAction.CallbackContext value)
    20.     {
    21.         Debug.Log("Touch Fired");
    22.     }
    23.  
    24.     void FixedUpdate()
    25.     {
    26.         rb.AddForce(inputMovement * horForce * Time.deltaTime, 0, forwardForce * Time.deltaTime);
    27.     }
    28.  
    29. }
    30.  
    Here is my Input Action and button setups, followed by player settings
    Settings.png
    PlayerSettings.png
     
  2. Mj-Kkaya

    Mj-Kkaya

    Joined:
    Oct 10, 2017
    Posts:
    172
    Where do you get this error? On player mode in editor or On any mobile device?
    Because "Use in control scheme" value is mobile. This means it works only on "Mobile".
    Actually I can't see which devices are in the "Mobile" scheme but, I guess your problem is related with this.
     
  3. Aniruddha_03

    Aniruddha_03

    Joined:
    Jul 31, 2023
    Posts:
    2
    I get the error in unity editor, but even if i set control scheme to both mobile and keyboard, and run OnTouch method isn't called.
    Mobile has gamepad device and keyboard has keyboard.