Version: 2017.2

Input.GetButtonDown

切换到手册
public static bool GetButtonDown (string buttonName);

描述

在用户按下由 buttonName 标识的虚拟按钮的帧期间返回 true。

您需要从 Update 函数调用该函数(因为每帧都会重置状态)。 在用户释放键并再次按键之前,它不会返回 true。

Use this only when implementing action like events IE: shooting a weapon.
Use Input.GetAxis for any kind of movement behaviour.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public GameObject projectile; void Update() { if (Input.GetButtonDown("Fire1")) Instantiate(projectile, transform.position, transform.rotation); } }