Version: 5.3 (switch to 5.4b)
言語English
  • C#
  • JS

スクリプト言語

好きな言語を選択してください。選択した言語でスクリプトコードが表示されます。

Input.GetKey

マニュアルに切り替える
public static bool GetKey(string name);

パラメーター

説明

name によって識別されるキーを押している間、true を返します。オート射撃のようなものと考えてください

キーの識別リストは Input Manager を参照してください。 ユーザーが自由にキー設定を変更できるようにするために Input.GetAxis と Input.GetButton を 使用することをお勧めします。

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void Update() { if (Input.GetKey("up")) print("up arrow key is held down"); if (Input.GetKey("down")) print("down arrow key is held down"); } }

public static bool GetKey(KeyCode key);

パラメーター

説明

KeyCode 列挙体パラメーターによる key によって識別されるキーを押している間、true を返します。

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void Update() { if (Input.GetKey(KeyCode.UpArrow)) print("up arrow key is held down"); if (Input.GetKey(KeyCode.DownArrow)) print("down arrow key is held down"); } }