Challenge 2: Configure the Wheel Drive Component’s Handbrake Input

Tutorial

·

Beginner

·

+0XP

·

15 mins

·

(198)

Unity Technologies

Challenge 2: Configure the Wheel Drive Component’s Handbrake Input

In this tutorial you will setup the Input System to use the 1D axis to control a 1D axis movement. In addition you will setup the Input System and C# scripting to use the Button and Modifier actions.

Languages available:

1. Working with the Wheel Drive Component's Handbrake Input

1. In the Primary Input Action’s Asset, add a new Action called “Handbrake” and set the binding to the “X” key on the keyboard.

ec5e069e-e6f4-411c-ab88-1d55a6753c01_ch1.gif

2. Click Save Asset at the top of the Input Action Asset.

000a24ee-4847-40e7-85fd-b48843ab749f_ch2.gif

3. Open the Family Car Wheel Drive script in your code editor:

2d13679f-25bd-44b0-959d-a6ad6c85bae9_ch3.gif

4. Add the Input System namespace at the top of the script:

2ad9fb6c-3212-40db-9a6b-e37ecc278cfb_ch4.png

5. Create the following variable declarations:

693156f8-e7d0-4d38-ab22-593ef53d0cb8_ch5.png

6. Create an Awake method and add the following logic to the Awake method body:

9f33419e-69ea-41ef-874c-75f52372fc19_ch6.png

7. Create a new method called GetHandBrakeInput that appears as follows:

7ac8dc0d-fbb3-49da-96fd-3f931bc4a219_ch7.png

8. Add the following OnEnable and OnDisable methods to the script:

ad7798c9-56ce-4238-9004-322183ea29f0_ch8.png

9. Remove the original handBrake input logic from the Update method:

e7da4b1f-a264-46f3-a846-37a544469922_ch9.gif

10. Back in the editor, add the Primary Input Actions Reference to the WheelDrive component on each of the vehicles:

0947d4d1-5400-4f45-bac8-4156fdb8332c_ch10.gif

11. Go into Play mode and test out the handbrake input you just implemented by pressing the X key.

Complete this tutorial