Version: 2020.1

Input.GetButtonUp

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

描述

在用户释放由 buttonName 标识的虚拟按钮的第一帧返回 true。

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

仅在实现武器开火事件等操作时,才使用该函数。
对于任意类型的移动行为,请使用 Input.GetAxis

using UnityEngine;
using System.Collections;

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