facebook twitter hatena line email

「Unity/Csharp/キー入力/InputSystem」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(競合プラグイン)
行12: 行12:
  
 
Unityメニュー/Edit/Project Setting/Player/Configuration
 
Unityメニュー/Edit/Project Setting/Player/Configuration
 +
 +
==サンプル==
 +
<pre>
 +
using UnityEngine;
 +
using UnityEngine.InputSystem;
 +
 +
public class SampleScene : MonoBehaviour
 +
{
 +
    void Update()
 +
    {
 +
        if (Keyboard.current.spaceKey.wasPressedThisFrame)
 +
        {
 +
            Debug.Log("space key");
 +
        }
 +
        if (Mouse.current.leftButton.wasPressedThisFrame)
 +
        {
 +
            Debug.Log("mouse down");
 +
        }
 +
        // キーボードのa
 +
        if (Keyboard.current[Key.A].wasPressedThisFrame)
 +
        {
 +
            Debug.Log("A down");
 +
        }
 +
        /*
 +
        if (Gamepad.current.buttonEast.isPressed)
 +
        {
 +
            Debug.Log("game pad o button");
 +
        }
 +
        */
 +
    }
 +
}
 +
</pre>

2021年11月9日 (火) 18:14時点における版

InputSytemとは

文字入力やマウスやゲームパッドなどのプラグイン

インストール

PackageManagerからRegistoryを選択して、InputSytemをインストール。 今回は、ver1.0.2でした。

競合プラグイン

  • InputManager(旧
  • InputSystem(新

新旧があり、どちらかを指定することができる。

Unityメニュー/Edit/Project Setting/Player/Configuration

サンプル

using UnityEngine;
using UnityEngine.InputSystem;

public class SampleScene : MonoBehaviour
{
    void Update()
    {
        if (Keyboard.current.spaceKey.wasPressedThisFrame)
        {
            Debug.Log("space key");
        }
        if (Mouse.current.leftButton.wasPressedThisFrame)
        {
            Debug.Log("mouse down");
        }
        // キーボードのa
        if (Keyboard.current[Key.A].wasPressedThisFrame)
        {
            Debug.Log("A down");
        }
        /*
        if (Gamepad.current.buttonEast.isPressed)
        {
            Debug.Log("game pad o button");
        }
        */
    }
}