Version: 2022.1

Input.GetButtonUp

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

描述

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

Call this function from the Update function, since the state gets reset each frame. It will not return true until the user has pressed the button and released it again.

仅在实现武器开火事件等操作时,才使用该函数。
对于任意类型的移动行为,请使用 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); } }