【Unity】GPD WINのコントローラをUnityで使う
2020-02-02
GPD WIN、コントローラが付いてるちっちゃいPCのコントローラの値をUnityで取得するためのメモ。

各アナログスティックとボタンの番号
以下のように仮に名前を置いた。
CrossKey – Up | Axis 6 positive |
CrossKey – Down | Axis 6 Negative |
CrossKey – Left | Axis 5 Negative |
CrossKey – Right | Axis 5 Positive |
Button – Y(△) | Button 0 |
Button – A(×) | Button 2 |
Button – X(□) | Button 3 |
Button – B(◯) | Button 1 |
L_Stick – Up | Axis 2 Negative |
L_Stick – Down | Axis 2 Positive |
L_Stick – Left | Axis 1 Negative |
L_Stick – Right | Axis 1 Positive |
R_Stick – Up | Axis 4 Negative |
R_Stick – Down | Axis 4 Positive |
R_Stick – Left | Axis 3 Negative |
R_Stick – Right | Axis 3 Positive |
L1 | Button 4 |
L2 | Button 6 |
L3 | Button 10 |
R1 | Button 5 |
R2 | Button 7 |
R3 | Button 11 |
ST | Button 9 |
SE | Button 8 |
サンプルコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
using UnityEngine; public class GPDControllerInput : MonoBehaviour { void Update() { //CrossKey if (Input.GetAxis("Axis 6") != 0f) Debug.Log("CrossKey - Vertical : " + Input.GetAxis("Axis 6")); if (Input.GetAxis("Axis 5") != 0f) Debug.Log("CrossKey - Horizontal : " + Input.GetAxis("Axis 5")); //Buttons if (Input.GetKey(KeyCode.JoystickButton0) == true) Debug.Log("Button Y"); if (Input.GetKey(KeyCode.JoystickButton1) == true) Debug.Log("Button B"); if (Input.GetKey(KeyCode.JoystickButton2) == true) Debug.Log("Button A"); if (Input.GetKey(KeyCode.JoystickButton3) == true) Debug.Log("Button X"); //L_Stick if (Input.GetAxis("Axis 2") != 0f) Debug.Log("L_Stick - Vertical : " + Input.GetAxis("Axis 2")); if (Input.GetAxis("Axis 1") != 0f) Debug.Log("L_Stick - Horizontal : " + Input.GetAxis("Axis 1")); //R_Stick if (Input.GetAxis("Axis 4") != 0f) Debug.Log("R_Stick - Vertical : " + Input.GetAxis("Axis 4")); if (Input.GetAxis("Axis 3") != 0f) Debug.Log("R_Stick - Horizontal : " + Input.GetAxis("Axis 3")); //L if (Input.GetKey(KeyCode.JoystickButton4) == true) Debug.Log("L1"); if (Input.GetKey(KeyCode.JoystickButton6) == true) Debug.Log("L2"); if (Input.GetKey(KeyCode.JoystickButton10) == true) Debug.Log("L3"); //R if (Input.GetKey(KeyCode.JoystickButton5) == true) Debug.Log("R1"); if (Input.GetKey(KeyCode.JoystickButton7) == true) Debug.Log("R2"); if (Input.GetKey(KeyCode.JoystickButton11) == true) Debug.Log("R3"); //ST if (Input.GetKey(KeyCode.JoystickButton9) == true) Debug.Log("START"); //SE if (Input.GetKey(KeyCode.JoystickButton8) == true) Debug.Log("SELECT"); } } |
