---
tags:
    - "Analog"
    - "Joystick"
    - "DPad"
    - "Horizontal"
    - "Vertical"
---

# Gamepad Stick Axis

[Input](index.md) / **Gamepad Stick Axis**

<div class="grid cards" markdown>

* :green_circle: Can Read

* :red_circle: Cannot Write

</div>

## Description

Returns a single axis of the specified Gamepad stick

## Parameters

| Name | Description |
| :--- | :---------- |
| Stick | Which stick of the current Gamepad is read |
| Axis | Whether the horizontal or the vertical value is returned |

## Code

```cs
using System;
using UnityEngine;
using UnityEngine.InputSystem;
using VisualScript.Icons;

namespace VisualScript.Runtime
{
    [Get]

    [Title("Gamepad Stick Axis")]
    [Category("Input/Gamepad Stick Axis")]

    [Description("Returns a single axis of the specified Gamepad stick")]
    [Image(typeof(IconJoystick), ColorTheme.Type.Blue, typeof(BadgeDot))]

    [Parameter("Stick", "Which stick of the current Gamepad is read")]
    [Parameter("Axis", "Whether the horizontal or the vertical value is returned")]

    [Keywords("Analog", "Joystick", "DPad", "Horizontal", "Vertical")]

    [Serializable]
    public class TypeNumberInputGamepadStickAxis : TypeNumber
    {
        [SerializeField] private GamepadStick m_Stick = GamepadStick.Left;
        [SerializeField] private InputAxis m_Axis = InputAxis.Horizontal;

        public override double Get(Args args)
        {
            Gamepad gamepad = Gamepad.current;
            if (gamepad == null) return 0d;

            Vector2 value = this.m_Stick switch
            {
                GamepadStick.Left => gamepad.leftStick.ReadValue(),
                GamepadStick.Right => gamepad.rightStick.ReadValue(),
                GamepadStick.DirectionalPad => gamepad.dpad.ReadValue(),
                _ => throw new ArgumentOutOfRangeException()
            };

            return this.m_Axis == InputAxis.Horizontal ? value.x : value.y;
        }

        public override string ToString()
        {
            return $"Gamepad {this.m_Stick} {this.m_Axis}";
        }

        protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
    }
}

```

