Class ButtonControl
An axis that has a trigger point beyond which it is considered to be pressed.
Inherited Members
Namespace: UnityEngine.InputSystem.Controls
Assembly: Unity.InputSystem.dll
Syntax
public class ButtonControl : AxisControl
Remarks
By default stored as a single bit. In that format, buttons will only yield 0 and 1 as values. However, buttons return are AxisControls and yield full floating-point values and may thus have a range of values. See pressPoint for how button presses on such buttons are handled.
Constructors
ButtonControl()
Default-initialize the control.
Declaration
public ButtonControl()
Remarks
The default format for the control is FormatBit. The control's minimum value is set to 0 and the maximum value to 1.
Fields
pressPoint
The minimum value the button has to reach for it to be considered pressed.
Declaration
public float pressPoint
Field Value
Type | Description |
---|---|
float | Button press threshold. |
Remarks
The button is considered pressed, if it has a value equal to or greater than this value.
By default, this property is set to -1. If the value of the property is negative, defaultButtonPressPoint is used.
The value can be configured as a parameter in a layout.
public class MyDevice : InputDevice
{
[InputControl(parameters = "pressPoint=0.234")]
public ButtonControl button { get; private set; }
//...
}
See Also
Properties
isPressed
Whether the button is currently pressed.
Declaration
public bool isPressed { get; }
Property Value
Type | Description |
---|---|
bool | True if button is currently pressed. |
Remarks
A button is considered press if it's value is equal to or greater than its button press threshold (pressPointOrDefault).
See Also
pressPointOrDefault
Return pressPoint if set, otherwise return defaultButtonPressPoint.
Declaration
public float pressPointOrDefault { get; }
Property Value
Type | Description |
---|---|
float | Effective value to use for press point thresholds. |
See Also
wasPressedThisFrame
Whether the press started this frame.
Declaration
public bool wasPressedThisFrame { get; }
Property Value
Type | Description |
---|---|
bool | True if the current press of the button started this frame. |
Remarks
// An example showing the use of this property on a gamepad button and a keyboard key.
using UnityEngine;
using UnityEngine.InputSystem;
public class ExampleScript : MonoBehaviour
{
void Update()
{
bool buttonPressed = Gamepad.current.aButton.wasPressedThisFrame;
bool spaceKeyPressed = Keyboard.current.spaceKey.wasPressedThisFrame;
}
}
wasReleasedThisFrame
Declaration
public bool wasReleasedThisFrame { get; }
Property Value
Type | Description |
---|---|
bool |
Methods
IsValueConsideredPressed(float)
Whether the given value would be considered pressed for this button.
Declaration
public bool IsValueConsideredPressed(float value)
Parameters
Type | Name | Description |
---|---|---|
float | value | Value for the button. |
Returns
Type | Description |
---|---|
bool | True if |