LoginSignup
2
1

More than 5 years have passed since last update.

[Unity] Windows/Mac/Linux共通で(たぶん)XBOXコントローラが使えるスクリプトのスケルトン

Last updated at Posted at 2019-04-04

Unity2018.3以降向けにWindows/Mac/Linux共通で(たぶん)XBOXコントローラが使えるスクリプトのスケルトンを書きました。
車輪の再発明的な気がしますが、使える部分があったら使ってやってください。
[GitHub] XBOXInputController for Unity 2018.3 or later

最初にMainScene.Unityを開いてください。
TestScript.cs が起動スクリプトだと仮定して、inputController に XBOXInputController.Instance を取得して、実際はそこを通して操作するイメージです。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestScript : MonoBehaviour
{
    [SerializeField]
    private XBOXInputController inputController;

    // Start is called before the first frame update
    IEnumerator Start()
    {
        // Wait for initialization of InputController
        do
        {
            yield return null;
        }
        while (inputController.IsReady == false);

        yield break;
    }

    // Update is called once per frame
    void Update()
    {
        // Check: Be sure to call in this order
        uint pad = inputController.Poll();              // パッド入力
        uint pad_trg = inputController.Trigger();       // パッドトリガ入力

        // Check pad operation with pad and pad_trg values


    }
}
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1