Advertisement
flaviusxvii

Untitled

May 12th, 2011
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var weapons : GameObject[];
  2. var selectedWeapon : int;
  3.  
  4.  
  5. function Awake () {
  6.     // Select the first weapon
  7.     SelectWeapon(0);
  8. }
  9.  
  10. function selectWeaponByIndex(i:int):void
  11. {
  12.     if(!weapons[i].gameObject.GetComponent("weaponLockout").isLocked) {
  13.             SelectWeapon(i);
  14.             selectedWeapon = i;
  15.     }
  16. }
  17.  
  18.  
  19. function Update () {
  20.     // Did the user press fire?
  21.     if (Input.GetButton ("Fire1"))
  22.         BroadcastMessage("Fire");
  23.  
  24.  
  25.     if (Input.GetKeyDown("1") && weapons.length >= 1) {
  26.     selectWeaponByIndex(0);
  27.        
  28.     } else if (Input.GetKeyDown("2") && weapons.length >= 2) {
  29.         selectWeaponByIndex(1);
  30.  
  31.     } else if (Input.GetKeyDown("3") && weapons.length >= 3) {
  32.         selectWeaponByIndex(2);
  33.  
  34.     } else if (Input.GetKeyDown("4") && weapons.length >= 4) {
  35.         selectWeaponByIndex(3);
  36.  
  37.     } else if (Input.GetKeyDown("5") && weapons.length >= 5) {
  38.         selectWeaponByIndex(4);
  39.  
  40.     }
  41. }
  42.  
  43.  
  44.  
  45.  
  46. function SelectWeapon (index : int) {
  47.     for (var i=0;i<transform.childCount;i++)    {
  48.         // Activate the selected weapon
  49.         if (i == index)
  50.             transform.GetChild(i).gameObject.SetActiveRecursively(true);
  51.         // Deactivate all other weapons
  52.         else
  53.             transform.GetChild(i).gameObject.SetActiveRecursively(false);
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement