1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

InputSystemでPress Any Keyを作る

Posted at

#概要
PC向けのゲームを真面目に作ろうとすると、キーボード、ゲームパッド、マウス他の対応。
特に全部に対応したタイトル画面のPress Any Keyを作るのが面倒くさいですよね。
各デバイスごとの決定キーだけ対応させるっていう手抜きもありえますが、新しいInputSystemなら取得に必要なコードは実質1行!
おそらくゲームパッド上のメニューボタンなどにも反応してしまうので使う場合はお気をつけて

#環境
2019.3.6f1

#ソース

    public class TitleManager : MonoBehaviour
    {
        private InputAction _pressAnyKeyAction = 
                new InputAction(type: InputActionType.PassThrough, binding: "*/<Button>", interactions: "Press");

        private void OnEnable() => _pressAnyKeyAction.Enable();
        private void OnDisable() => _pressAnyKeyAction.Disable();

        void Update()
        {
            if(_pressAnyKeyAction.triggered)
            {
                //シーン読み込み、アニメーション読み込みなどなど
            }
        }
    }

1
3
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
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?