Class StickControl
A two-axis thumbstick control that can act as both a vector and a four-way dpad.
Inherited Members
Namespace: UnityEngine .InputSystem .Controls
Assembly: Unity.InputSystem.dll
Syntax
public class StickControl : Vector2Control
Remarks
Stick controls are used to represent the thumbsticks on gamepads (see left
Essentially, a stick is an extended Vector2
control that can function either
as a combined 2D vector, as independent vertical and horizontal axes, or as four
individual, directional buttons. The following example demonstrates this based on the
gamepad's left stick.
// Read stick as a combined 2D vector.
Gamepad.current.leftStick.ReadValue();
// Read X and Y axis of stick individually.
Gamepad.current.leftStick.x.ReadValue();
Gamepad.current.leftStick.y.ReadValue();
// Read the stick as four individual directional buttons.
Gamepad.current.leftStick.up.ReadValue();
Gamepad.current.leftStick.down.ReadValue();
Gamepad.current.leftStick.left.ReadValue();
Gamepad.current.leftStick.right.ReadValue();
In terms of memory, a stick controls is still just from one value for the X axis and one value for the Y axis.
Unlike dpads (see Dpad
Properties
down
A synthetic button representing the lower half of the stick's Y axis, i.e. the -1 to 0 range (inverted).
Declaration
public ButtonControl down { get; set; }
Property Value
Type | Description |
---|---|
Button |
Control representing the stick's lower half Y axis. |
Remarks
The control is marked as synthetic.
left
A synthetic button representing the left half of the stick's X axis, i.e. the -1 to 0 range (inverted).
Declaration
public ButtonControl left { get; set; }
Property Value
Type | Description |
---|---|
Button |
Control representing the stick's left half X axis. |
Remarks
The control is marked as synthetic.
right
A synthetic button representing the right half of the stick's X axis, i.e. the 0 to 1 range.
Declaration
public ButtonControl right { get; set; }
Property Value
Type | Description |
---|---|
Button |
Control representing the stick's right half X axis. |
Remarks
The control is marked as synthetic.
up
A synthetic button representing the upper half of the stick's Y axis, i.e. the 0 to 1 range.
Declaration
public ButtonControl up { get; set; }
Property Value
Type | Description |
---|---|
Button |
Control representing the stick's upper half Y axis. |
Remarks
The control is marked as synthetic.
Methods
FinishSetup()
Perform final initialization tasks after the control hierarchy has been put into place.
Declaration
protected override void FinishSetup()
Overrides
Remarks
This method can be overridden to perform control- or device-specific setup work. The most common use case is for looking up child controls and storing them in local getters.
Examples
public class MyDevice : InputDevice
{
public ButtonControl button { get; private set; }
public AxisControl axis { get; private set; }
protected override void OnFinishSetup()
{
// Cache controls in getters.
button = GetChildControl("button");
axis = GetChildControl("axis");
}
}