0
0
Unityframework~20 mins

Controller/gamepad support in Unity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Gamepad Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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");
    }
}
AAlways prints Jump pressed
BThrows a runtime error
CAlways prints No jump
DJump pressed (when button pressed), No jump (otherwise)
Attempts:
2 left
💡 Hint
Think about how Input.GetButtonDown works only on the frame the button is pressed.
🧠 Conceptual
intermediate
1:30remaining
Understanding Axis Input from Gamepad
Which statement correctly describes the behavior of Input.GetAxis("Horizontal") when using a gamepad's left stick?
AReturns a float between -1 and 1 representing left/right stick movement
BReturns true if the stick is moved right, false otherwise
CReturns an integer 0 or 1 depending on stick position
DReturns the stick's position as a Vector2
Attempts:
2 left
💡 Hint
Think about how axis input works as a range of values.
🔧 Debug
advanced
2: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);
A0.1
BThrows a NullReferenceException
C0.0
D0.2
Attempts:
2 left
💡 Hint
Check the condition for deadzone carefully.
Predict Output
advanced
2: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]); }
ANo gamepad connected
BGamepad connected:
CThrows IndexOutOfRangeException
DGamepad connected: Unknown
Attempts:
2 left
💡 Hint
Check what Input.GetJoystickNames returns when no device is connected.
🚀 Application
expert
3: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?
A
if (Gamepad.current != null &amp;&amp; Gamepad.current.fireButton.wasPressedThisFrame) {
    Gamepad.current.SetMotorSpeeds(0.5f, 0.5f);
}
B
if (Gamepad.current != null &amp;&amp; Gamepad.current.buttonSouth.wasPressedThisFrame) {
    Gamepad.current.SetMotorSpeeds(0.5f, 0.5f);
}
C
if (Gamepad.current != null &amp;&amp; Input.GetButtonDown("Fire")) {
    Gamepad.current.SetMotorSpeeds(0.5f, 0.5f);
}
D
if (Gamepad.current != null &amp;&amp; Gamepad.current.buttonEast.isPressed) {
    Gamepad.current.SetMotorSpeeds(0.5f, 0.5f);
}
Attempts:
2 left
💡 Hint
Use the new Input System's Gamepad class and check the correct button for "Fire" (usually buttonSouth).