0
0
Unityframework~10 mins

Input action maps in Unity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a new InputAction.

Unity
InputAction jumpAction = new InputAction(name: [1]);
Drag options to blanks, or click blank then click option'
A"Jump"
BJump
Cjump
D"jump"
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.
2fill in blank
medium

Complete the code to enable the input action.

Unity
jumpAction.[1]();
Drag options to blanks, or click blank then click option'
AEnable
BStart
CActivate
DRun
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.
3fill in blank
hard

Fix 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'
Aint
Bfloat
Cstring
Dbool
Attempts:
3 left
💡 Hint
Common Mistakes
Using int or bool causes runtime errors or wrong values.
Using string is invalid for input values.
4fill in blank
hard

Fill 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'
A"<Keyboard>/space"
BEnable
CStart
D"<Mouse>/leftButton"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong binding string like mouse button.
Calling Start() instead of Enable().
5fill in blank
hard

Fill 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'
A"Move"
B"2DVector"
CVector2
D"<Keyboard>/w"
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect binding strings or types.
Not matching the ReadValue type to the expected input.