Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new InputAction.
Unity
var jumpAction = new InputAction(name: [1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the action name.
Using a variable name without quotes.
✗ 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 InputAction.
Unity
jumpAction.[1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling start() instead of enable().
Using activate() which does not exist.
✗ Incorrect
To start listening for input, you must call the enable() method on the InputAction.
3fill in blank
hardFix the error in the code to read the value of the InputAction 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 which is not suitable for analog input.
Using string or bool which are invalid types here.
✗ Incorrect
The ReadValue method should use float to get the input value as a floating-point number.
4fill in blank
hardFill both blanks to create a dictionary of action names and their enabled status.
Unity
var actionStatus = actions.ToDictionary(action => [1], action => action.[2]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using isEnabled or active which are not valid properties.
Using enabled without the action prefix.
✗ Incorrect
Use action.name as the key and action.enabled as the value to get the enabled status.
5fill in blank
hardFill all three blanks to subscribe to the performed event with a callback method.
Unity
jumpAction.[1] += [2] => [3]();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using started event instead of performed.
Not using a parameter in the lambda.
Calling a method name that does not exist.
✗ Incorrect
Subscribe to the performed event using a lambda with context parameter calling OnJump method.