0
0
Unityframework~10 mins

Controller/gamepad support 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 check if the A button on the gamepad is pressed.

Unity
if (Input.GetButtonDown("[1]")) {
    Debug.Log("A button pressed");
}
Drag options to blanks, or click blank then click option'
ACancel
BJump
CSubmit
DFire1
Attempts:
3 left
💡 Hint
Common Mistakes
Using "Jump" which is usually mapped to a keyboard key.
Using "Submit" which is for UI navigation.
2fill in blank
medium

Complete the code to read the horizontal axis from the gamepad's left stick.

Unity
float horizontal = Input.GetAxis("[1]");
Drag options to blanks, or click blank then click option'
AVertical
BHorizontalRight
CHorizontal
DVerticalRight
Attempts:
3 left
💡 Hint
Common Mistakes
Using "HorizontalRight" which is for the right stick.
Using "Vertical" which is for vertical movement.
3fill in blank
hard

Fix the error in the code to detect if the gamepad's B button is pressed.

Unity
if (Input.GetButtonDown("[1]")) {
    Debug.Log("B button pressed");
}
Drag options to blanks, or click blank then click option'
AFire2
BFire1
CJump
DFire3
Attempts:
3 left
💡 Hint
Common Mistakes
Using "Fire1" which is for the A button.
Using "Jump" which is usually keyboard spacebar.
4fill in blank
hard

Fill both blanks to create a dictionary mapping button names to their input names.

Unity
var buttonMap = new Dictionary<string, string> {
    {"A", "[1]"},
    {"B", "[2]"}
};
Drag options to blanks, or click blank then click option'
AFire1
BFire2
CJump
DCancel
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the input names for A and B.
Using "Jump" or "Cancel" which are unrelated.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension filtering axes with positive values.

Unity
var positiveAxes = new Dictionary<string, float> {
    {"Horizontal", Input.GetAxis("[1]")},
    {"Vertical", Input.GetAxis("[2]")},
    {"RightStickHorizontal", Input.GetAxis("[3]")}
}.Where(kv => kv.Value > 0).ToDictionary(kv => kv.Key, kv => kv.Value);
Drag options to blanks, or click blank then click option'
AHorizontal
BVertical
CHorizontalRight
DVerticalRight
Attempts:
3 left
💡 Hint
Common Mistakes
Using "HorizontalRight" for left stick axes.
Mixing vertical and horizontal axis names.