buttonName | The name of the button such as Jump. |
bool True when an axis has been pressed and not released.
Returns true while the virtual button identified by buttonName
is held down.
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.
The buttonName
argument will normally be one of the names in InputManager such as Jump or
Fire1. GetButton will return to false
when it is released.
Note: Use GetAxis for input that controls continuous movement.
// Instantiates a projectile every 0.5 seconds, // if the Fire1 button (default is Ctrl) is pressed.
var projectile : GameObject; var fireDelta : float = 0.5;
private var nextFire : float = 0.5; private var newProjectile : GameObject; private var myTime : float = 0.0;
function Update () {
myTime = myTime + Time.deltaTime;
if (Input.GetButton("Fire1") && (myTime > nextFire)) { nextFire = myTime + fireDelta; newProjectile = Instantiate(projectile, transform.position, transform.rotation);
// create code here that animates the newProjectile
nextFire = nextFire - myTime; myTime = 0.0; } }
// 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; } } }
Did you find this page useful? Please give it a rating: