Keyboard commands

From ETC Public Wiki
Jump to: navigation, search
 function Update () {
 
   if (Input.GetKey(KeyCode.DownArrow)) transform.Translate(0, 0, -1);
 
   if (Input.GetKey(KeyCode.UpArrow)) transform.Translate(0, 0, 1);
 
   if (Input.GetKey(KeyCode.RightArrow)) transform.Rotate(0, 1, 0);
 
   if (Input.GetKey(KeyCode.LeftArrow)) transform.Rotate(0, -1, 0);
 
 }


 function Update () {    
   if (Input.GetKey ("up"))        
     print ("up arrow key is held down");    
   if (Input.GetKey ("down"))        
     print ("down arrow key is held down");
 }


 // Instantiates a projectile every 0.5 seconds,
 // if the Fire1 button (default is Ctrl) is pressed.
 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;    
   }
 }


 // Instantiates a projectile whenever the user hits the Fire1 Button.
 var projectile : GameObject;
 
 function Update () {    
   if (Input.GetButtonDown ("Fire1")) {        
     Instantiate (projectile, transform.position, transform.rotation);    
   }
 }


Use Edit=>Project Settings=>Input to see what button strings are set up