- Home /
Unity Isn't Detecting Button Presses on PS3 Controller
I have my PS3 controller hooked to my computer with a USB. Unity console says "Joystick Connected ("PLAYSTATION(R)3 Controller")" so I know Unity is seeing my controller. The problem now though is it doesn't register any input. I am trying the following so I can get any feedback, but no dice:
if (Input.GetKey(KeyCode.JoystickButton0) ||
Input.GetKey(KeyCode.JoystickButton1) ||
Input.GetKey(KeyCode.JoystickButton2) ||
Input.GetKey(KeyCode.JoystickButton3) ||
Input.GetKey(KeyCode.JoystickButton4) ||
Input.GetKey(KeyCode.JoystickButton5) ||
Input.GetKey(KeyCode.JoystickButton6) ||
Input.GetKey(KeyCode.JoystickButton7) ||
Input.GetKey(KeyCode.JoystickButton8) ||
Input.GetKey(KeyCode.JoystickButton9) ||
Input.GetKey(KeyCode.JoystickButton10) ||
Input.GetKey(KeyCode.JoystickButton11) ||
Input.GetKey(KeyCode.JoystickButton12) ||
Input.GetKey(KeyCode.JoystickButton13) ||
Input.GetKey(KeyCode.JoystickButton14) ||
Input.GetKey(KeyCode.JoystickButton15) ||
Input.GetKey(KeyCode.JoystickButton16) ||
Input.GetKey(KeyCode.JoystickButton17) ||
Input.GetKey(KeyCode.JoystickButton18) ||
Input.GetKey(KeyCode.JoystickButton19))
{
print("true");
}
Any idea why it isn't registering?
Thank you in advance!
I do have an additional question. I need multiple controllers working so I am curious to know how Unity would know what controllers are registered to what joystick.
Answer by YoyoMario · Nov 22, 2017 at 05:03 PM
Hey did you manage to find out the answer? I am struggling with the same issue now...
Hi, just posted an answer below https://answers.unity.com/answers/1473645/view.html
It's worth knowing that you can and should Comment, not place an Answer, when asking questions. (:
Answer by jethrogillgren · Feb 26, 2018 at 12:32 PM
Hi, I juts had to go through this process, so have an example that you can use.
It uses the InputManager, which you configure to tell Unity which controller buttons have which names.
And it shows a script which can get the state of any button by the name you gave it.
You should almost always use the InputManager over Input.GetKey KeyCode.JoystickXXX
https://github.com/jethrogillgren/PS3_Unity_TestScene
If you download that, plug in a PS3 controller, and press play, you should see all the shapes move showing which buttons are active. Look at Edit > Project Settings > Input, and the script on each shape. (: