1
1

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.

Unity Input System VRコントローラーを使う

Last updated at Posted at 2021-11-16

環境

os : windows10pro
unity : 2020.3.21f1
VR : OculusQuest2

コントローラー

image.png

image.png
参考)https://jmpelletier.com/ja/unity%E3%81%AE%E6%96%B0%E3%81%97%E3%81%84input-system%E3%81%A7oculus%E3%82%92%E4%BD%BF%E7%94%A8%E3%81%99%E3%82%8B/

手順

1)InputSystemのインストール
image.png

  1. PlayerSetting - Other Setting
    [Other Settings]-[Configuration]-[Api Compatibility Level]をNET4

[Other Settings]-[Configuration]-[Active Input Handling]をBothにする。

Unity再起動を行う。

image.png

  1. PlayerSetting- XR Plug-in Management
    インストールしてOculusにチェックを入れる。
    image.png

4)Input Actionsの作成
Input Actionsを作成して、開く。名前は”DefaultAction”とする

ファイル名

左からActionMaps,Actions,Propertiesを作成、選択をする。
image.png

  1. アクションを受ける側を作る。Cube
    Cubeを作成して、PlayerInputアタッチする。
    PlayerInputから、DefalutActionを選択する。

  2. アクションを受けとるスクリプトを作成

上記で、ActionsのインスタンスDropを作成したので、受信するハンドラはOnDrop()となる。これをCUBEにアタッチする。

public class ObjectDrop : MonoBehaviour {

    // ここにアクションに反応するメソッドを書きます。
    void OnDrop()
    {
        gameObject.AddComponent<Rigidbody>();
    }
}

7.実行
実行して、コントローラーの当該ボタンを押すとCUBEが落下する。
変化ないならキーボードの”A”を押す。落ちる場合はVR系の設定が漏れているので確認を行う。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?