Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a new InputAction.
Unity
InputAction jumpAction = new InputAction(name: [1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put the name in quotes causes a syntax error.
Using a variable without declaration causes an error.
✗ Incorrect
The InputAction constructor requires the name as a string, so it must be in quotes.
2fill in blank
mediumComplete the code to enable the input action.
Unity
jumpAction.[1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling Start() or Run() instead of Enable() causes errors.
Forgetting to enable the action means input won't be detected.
✗ Incorrect
To start listening for input, you must call Enable() on the InputAction.
3fill in blank
hardFix the error in the code to read the input value as a float.
Unity
float value = jumpAction.ReadValue<[1]>(); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using int or bool causes runtime errors or wrong values.
Using string is invalid for input values.
✗ Incorrect
The input value for actions like jump is a float, so ReadValue() is correct.
4fill in blank
hardFill both blanks to create an InputAction that triggers on pressing the space key.
Unity
InputAction jumpAction = new InputAction(name: "Jump", binding: [1]); jumpAction.[2]();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong binding string like mouse button.
Calling Start() instead of Enable().
✗ Incorrect
The binding string "/space" sets the space key, and Enable() activates the action.
5fill in blank
hardFill all three blanks to create an InputAction that reads a Vector2 from WASD keys and enables it.
Unity
InputAction moveAction = new InputAction(name: [1], binding: [2]); Vector2 move = moveAction.ReadValue<[3]>();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect binding strings or types.
Not matching the ReadValue type to the expected input.
✗ Incorrect
The action is named "Move", uses the composite binding "2DVector", and reads a Vector2 value.