Version: 2017.2
public static bool GetButton (string buttonName);

描述

当按住 buttonName 标识的虚拟按钮时,返回 true。

Think auto fire - this will return true as long as the button is held down.

Use this only when implementing events that trigger an action, eg, shooting a weapon. Use GetAxis for input that controls continuous movement.

// Instantiates a projectile every 0.5 seconds,
// if the Fire1 button (default is Ctrl) is pressed.

using UnityEngine; using System.Collections;

public class ExampleClass : MonoBehaviour { public GameObject projectile; public float fireDelta = 0.5F;

private float nextFire = 0.5F; private GameObject newProjectile; private float myTime = 0.0F;

void Update() { myTime = myTime + Time.deltaTime;

if (Input.GetButton("Fire1") && myTime > nextFire) { nextFire = myTime + fireDelta; newProjectile = Instantiate(projectile, transform.position, transform.rotation) as GameObject;

// create code here that animates the newProjectile

nextFire = nextFire - myTime; myTime = 0.0F; } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961