Challenge - 5 Problems
Gamepad Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Reading Gamepad Button Press
What is the output of this Unity C# code snippet when the player presses the "Jump" button on a gamepad?
Unity
void Update() {
if (Input.GetButtonDown("Jump")) {
Debug.Log("Jump pressed");
} else {
Debug.Log("No jump");
}
}Attempts:
2 left
💡 Hint
Think about how Input.GetButtonDown works only on the frame the button is pressed.
✗ Incorrect
Input.GetButtonDown returns true only on the exact frame the button is pressed, so the code prints "Jump pressed" only then, otherwise "No jump".
🧠 Conceptual
intermediate1:30remaining
Understanding Axis Input from Gamepad
Which statement correctly describes the behavior of Input.GetAxis("Horizontal") when using a gamepad's left stick?
Attempts:
2 left
💡 Hint
Think about how axis input works as a range of values.
✗ Incorrect
Input.GetAxis returns a float value between -1 and 1 indicating the stick's horizontal position, where -1 is full left and 1 is full right.
🔧 Debug
advanced2:00remaining
Fixing Deadzone Handling for Gamepad Axis
This code tries to ignore small stick movements (deadzone) but does not work correctly. What is the output when the stick is slightly moved to 0.1 on the X axis?
float x = Input.GetAxis("Horizontal");
if (x < 0.2f) {
x = 0f;
}
Debug.Log(x);
Attempts:
2 left
💡 Hint
Check the condition for deadzone carefully.
✗ Incorrect
The condition x < 0.2f is true for 0.1, so x is set to 0.0. But the code incorrectly uses less than instead of absolute value check, so negative values are not handled.
❓ Predict Output
advanced2:00remaining
Detecting Gamepad Connection Status
What does this Unity C# code print if no gamepad is connected?
string[] names = Input.GetJoystickNames();
if (names.Length == 0 || string.IsNullOrEmpty(names[0])) {
Debug.Log("No gamepad connected");
} else {
Debug.Log("Gamepad connected: " + names[0]);
}
Attempts:
2 left
💡 Hint
Check what Input.GetJoystickNames returns when no device is connected.
✗ Incorrect
If no gamepad is connected, Input.GetJoystickNames returns an empty array or array with empty strings, so the code prints "No gamepad connected".
🚀 Application
expert3:00remaining
Implementing Vibration Feedback on Gamepad
Which code snippet correctly triggers a vibration on a gamepad using Unity's new Input System when the player presses the "Fire" button?
Attempts:
2 left
💡 Hint
Use the new Input System's Gamepad class and check the correct button for "Fire" (usually buttonSouth).
✗ Incorrect
In Unity's new Input System, buttonSouth usually maps to the bottom face button (like A on Xbox), commonly used for "Fire". The code checks if it was pressed this frame and sets vibration.