|
30 | 30 | - [Keyboard](#keyboard) |
31 | 31 | - [Mouse](#mouse) |
32 | 32 | - [Touch](#touch) |
| 33 | + - [New Input System](#new-input-system) |
33 | 34 | - [UI](#ui) |
34 | 35 | - [Button](#button) |
35 | 36 | - [Slider](#slider) |
|
76 | 77 | - [Fade UI element](#fade-ui-element) |
77 | 78 | - [Load next scene](#load-next-scene) |
78 | 79 | - [TBD (To Be Documented)](#tbd-to-be-documented) |
79 | | - - [Input](#input-1) |
80 | 80 | - [Scripting](#scripting-1) |
81 | 81 |
|
82 | 82 | ## Basics |
@@ -382,6 +382,79 @@ if (Input.touchCount > 0) { |
382 | 382 | } |
383 | 383 | ``` |
384 | 384 |
|
| 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 | + |
385 | 458 | ## UI |
386 | 459 |
|
387 | 460 | ### Button |
@@ -1401,12 +1474,8 @@ if (nextSceneToLoad < totalSceneCount) { |
1401 | 1474 |
|
1402 | 1475 | The following topics are planned to be added to the documentation: |
1403 | 1476 |
|
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 |
1410 | 1479 |
|
1411 | 1480 | --- |
1412 | 1481 |
|
|
0 commit comments