Input
- accelerationEventCount
- accelerationEvents
- acceleration
- anyKeyDown
- anyKey
- compositionCursorPos
- compositionString
- deviceOrientation
- eatKeyPressOnTextFieldFocus
- GetAccelerationEvent
- GetAxisRaw
- GetAxis
- GetButtonDown
- GetButtonUp
- GetButton
- GetJoystickNames
- GetKeyDown
- GetKeyUp
- GetKey
- GetMouseButtonDown
- GetMouseButtonUp
- GetMouseButton
- GetPosition
- GetRotation
- GetTouch
- gyro
- imeCompositionMode
- inputString
- isGyroAvailable
- mousePosition
- multiTouchEnabled
- ResetInputAxes
- touchCount
- touches
Input.GetButton 获取按钮
static function GetButton (buttonName : string) : bool
Description描述
Returns true while the virtual button identified by buttonName is held down.
根据按钮名称返回true当对应的虚拟按钮被按住时。
Think auto fire - this will return true as long as the button is held down.
想象一下自动开火 - 如果按钮一直被按住此方法将永远返回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;
public float fireRate = 0.5F;
private float nextFire = 0.0F;
void Update() {
if (Input.GetButton("Fire1") && Time.time > nextFire) {
nextFire = Time.time + fireRate;
GameObject clone = Instantiate(projectile, transform.position, transform.rotation) as GameObject;
}
}
}
// Instantiates a projectile every 0.5 seconds,
// if the Fire1 button (default is Ctrl) is pressed.
//实例化一个抛射每隔0.5秒
//如果Fire1按钮(默认Ctrl)被按下
var projectile : GameObject;
var fireRate : float = 0.5;
private var nextFire : float = 0.0;
function Update () {
if (Input.GetButton ("Fire1") && Time.time > nextFire) {
nextFire = Time.time + fireRate;
var clone : GameObject =
Instantiate(projectile, transform.position, transform.rotation) as GameObject;
}
}
最后修改:2011年3月11日 Friday 21:15