Description
Interface for handling user Input.
Static Methods
Method | Function |
FindInputBindings | Loads the first InputBindings found in the project. |
DoubleTap | Returns true if the player presses the same button twice. |
HoldButton | Returns true if the player keeps the button pressed in a time interval. |
GetButton | Returns true if the player is pressing the button. |
GetButtonDown | Return true if the player has pressed the button. |
GetButtonUp | Return true if the player has released the button. |
GetAxis | Returns the value of the virtual axis with smoothing filtering. |
GetAxisRaw | Returns the value of the virtual axis. |
GetAlphaKeyCode | Returns the value alpha key (1, 2, 3, 4, 5, 6, 7, 8, 9, 0) based on the given index. |
FindButton | Returns the first found button with the given name. |
FindAxis | Returns the first found axis with the given name. |
EditButton | Edit the key used by the button. |
EditAxis | Edit the keys used by the axis. |
GetButtonData | Returns all buttons registered in the InputBinding. |
GetAxisData | Returns all axes registered in the InputBinding. |
Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 | // Reference to the "Jump" button defined in the Input Bindings.
private Button jump;
private void Start()
{
// The FindButton function is efficient if used only a few times,
// for example when starting the object. For performance reasons,
// do not cache Buttons/Axes in functions called every frame.
jump = InputManager.FindButton("Jump");
}
// Prints a message in the console if the player
// holds the "Jump" button during 1 second.
private void Update()
{
// Check if the player is holding the button.
// After 1 second holding the button the function will return true.
if (InputManager.HoldButton(jump, 1.0f))
{
Debug.Log("Foo");
}
// Another way, but less efficient, is to pass the button name
// to be located instead of caching.
if (InputManager.GetButtonDown("Fire"))
{
Debug.Log("Fire!");
}
}
|