Skip to content

Commit 1224d70

Browse files
committed
Add comprehensive New Input System documentation with examples for keyboard, mouse, gamepad, Input Actions, runtime rebinding, and best practices
1 parent eaef7a0 commit 1224d70

8 files changed

Lines changed: 999 additions & 7 deletions

File tree

README.md

Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
- [Keyboard](#keyboard)
3131
- [Mouse](#mouse)
3232
- [Touch](#touch)
33+
- [New Input System](#new-input-system)
3334
- [UI](#ui)
3435
- [Button](#button)
3536
- [Slider](#slider)
@@ -76,7 +77,6 @@
7677
- [Fade UI element](#fade-ui-element)
7778
- [Load next scene](#load-next-scene)
7879
- [TBD (To Be Documented)](#tbd-to-be-documented)
79-
- [Input](#input-1)
8080
- [Scripting](#scripting-1)
8181

8282
## Basics
@@ -382,6 +382,79 @@ if (Input.touchCount > 0) {
382382
}
383383
```
384384

385+
### New Input System
386+
387+
The Input System package is the **standard for Unity 6** and recommended for all new projects. It provides flexible, multi-device input handling with runtime rebinding support.
388+
389+
> For the complete guide with all examples, see [New Input System](docs/input/new-input-system.md)
390+
391+
#### Quick Setup
392+
```
393+
Window > Package Manager > Unity Registry > Input System > Install
394+
Edit > Project Settings > Player > Active Input Handling > Input System Package (New)
395+
```
396+
397+
#### Direct Device Access
398+
```csharp
399+
using UnityEngine.InputSystem;
400+
401+
// Keyboard
402+
if (Keyboard.current.spaceKey.wasPressedThisFrame) {
403+
Debug.Log("Space pressed");
404+
}
405+
406+
// Mouse
407+
Vector2 mousePos = Mouse.current.position.ReadValue();
408+
if (Mouse.current.leftButton.wasPressedThisFrame) {
409+
Debug.Log("Left click at " + mousePos);
410+
}
411+
412+
// Gamepad (always check for null!)
413+
if (Gamepad.current != null) {
414+
Vector2 leftStick = Gamepad.current.leftStick.ReadValue();
415+
if (Gamepad.current.buttonSouth.wasPressedThisFrame) {
416+
Debug.Log("A/Cross button pressed");
417+
}
418+
}
419+
```
420+
421+
#### Using Input Actions (Recommended)
422+
```csharp
423+
using UnityEngine;
424+
using UnityEngine.InputSystem;
425+
426+
public class PlayerController : MonoBehaviour
427+
{
428+
[SerializeField] private InputActionReference moveAction;
429+
[SerializeField] private InputActionReference jumpAction;
430+
431+
void OnEnable()
432+
{
433+
moveAction.action.Enable();
434+
jumpAction.action.Enable();
435+
jumpAction.action.performed += OnJump;
436+
}
437+
438+
void OnDisable()
439+
{
440+
jumpAction.action.performed -= OnJump;
441+
moveAction.action.Disable();
442+
jumpAction.action.Disable();
443+
}
444+
445+
void Update()
446+
{
447+
Vector2 move = moveAction.action.ReadValue<Vector2>();
448+
transform.Translate(move.x * Time.deltaTime, 0, move.y * Time.deltaTime);
449+
}
450+
451+
void OnJump(InputAction.CallbackContext context)
452+
{
453+
Debug.Log("Jump!");
454+
}
455+
}
456+
```
457+
385458
## UI
386459

387460
### Button
@@ -1401,12 +1474,8 @@ if (nextSceneToLoad < totalSceneCount) {
14011474

14021475
The following topics are planned to be added to the documentation:
14031476

1404-
### Input
1405-
- [ ] New Input System
1406-
- [ ] Input Actions
1407-
- [ ] Input Action Assets
1408-
- [ ] Player Input Component
1409-
- [ ] Input System Events
1477+
### Scripting
1478+
- [ ] More advanced scripting topics coming soon
14101479

14111480
---
14121481

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ A comprehensive guide to Unity development patterns and practices.
2828
- [Keyboard](input/keyboard.md)
2929
- [Mouse](input/mouse.md)
3030
- [Touch](input/touch.md)
31+
- [New Input System](input/new-input-system.md)
3132

3233
### UI
3334

docs/_sidebar.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
* [Keyboard](input/keyboard.md)
3232
* [Mouse](input/mouse.md)
3333
* [Touch](input/touch.md)
34+
* [New Input System](input/new-input-system.md)
35+
* [Direct Device Access](input/new-input-system.md#direct-device-access)
36+
* [Input Actions](input/new-input-system.md#input-actions)
37+
* [Using in Code](input/new-input-system.md#using-input-actions-in-code)
38+
* [Runtime Rebinding](input/new-input-system.md#runtime-rebinding)
3439
* UI
3540
* [Button](ui/button.md)
3641
* [Slider](ui/slider.md)

docs/input/keyboard.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Keyboard
22

3+
> **Note:** This page covers the **Legacy Input Manager**. For Unity 6+ projects, see the [New Input System](new-input-system.md) which is now the standard.
4+
35
```csharp
46
// Returns true during the frame the user starts pressing down the key
57
if (Input.GetKeyDown(KeyCode.Space)) {

docs/input/mouse.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Mouse
22

3+
> **Note:** This page covers the **Legacy Input Manager**. For Unity 6+ projects, see the [New Input System](new-input-system.md) which is now the standard.
4+
35
```csharp
46
if (Input.GetAxis("Mouse X") < 0) {
57
Debug.Log("Mouse moved left");

0 commit comments

Comments
 (0)