Input.GetButtonUp 获取按钮弹起

static function GetButtonUp (buttonName : string) : bool

Description描述

Returns true the first frame the user releases the virtual button identified by buttonName.

在用户释放指定名称的虚拟按钮时返回true。

You need to 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.

你需要在Update方法中调用这个方法,此后每一帧重置状态时,它将不会返回true除非用户按下这个按钮然后重新释放它。

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

只有当执行像武器射击这样的事件时才可用此方法,Input.GetAxis适用于各种运动行为。

using UnityEngine;
using System.Collections;

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

	}
}
// Instantiates a projectile whenever the user hits the Fire1 Button.
//每当用户敲击Fire1按钮时实例化一个发射

var projectile : GameObject;
function Update () {
	if (Input.GetButtonUp ("Fire1")) {
		Instantiate (projectile, transform.position, transform.rotation);
	}
}
Page last updated: 2011-3-11