Challenge 1: Setting up the Input System

Tutorial

·

Beginner

·

+0XP

·

20 mins

·

(226)

Unity Technologies

Challenge 1: Setting up the Input System

In this tutorial you will configure the Input System, and create the first input along with the corresponding C# script.

Make sure to download the project materials below and import them into a New Unity project before starting.

Languages available:

1. Set up and configure the Input System

To get started, you'll first want to make sure that you have Postprocessing Version 2.0.3 installed.

1. Update the Post Processing package to 2.3.0 using the Package Manager (Window > Package Manager).

2. Download the Input System from the Package Manager (Window > Package Manager).

3. Ensure the project settings are switched over to use the new Input system by opening the project settings clicking on Player > Other > Active Input Handling and setting it to “Both” (note: the editor may restart after making this change).

4. Create a new Input Actions Asset and name it “Primary Input Actions.”

5. Double click on the asset to open it up in the Input window and dock it in the bottom of the editor (for quick access).

6. Click on the “+” button next to Action Maps to add a new action map and name it “Gameplay.”

7. There is a default Action created, go ahead and rename it “Next Vehicle.”

8. Select the Binding under the Next Vehicle and set it to the K key on the keyboard.

9. Create a new Action called “Reset Vehicle” and add a binding for Reset Vehicle and set it to the R key on the keyboard:

10. Click Save Asset at the top of the Input actions window to save the asset.

11. Open the CarSwitcher.cs C# component that is attached to the “Main Camera” GameObject (Cameras > Main Camera).

12. Add the Input System using statement at the top of the script and the following variable declarations:

13. In the Awake method add the following logic to setup the Next Vehicle and Reset Vehicle inputs.

14. Before heading back to the Unity Editor, add and configure the following OnEnable and OnDisable methods:

15. The deprecated Update method is no longer needed, so go ahead and remove it.

16. In the Editor set the reference to the Input Actions in the Car Switcher component.

17. Go into Play mode and ensure you can transition between vehicles by pressing the K key and reset vehicles by pressing the R key.

Complete this tutorial