Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var weapons : GameObject[];
- var selectedWeapon : int;
- function Awake () {
- // Select the first weapon
- SelectWeapon(0);
- }
- function selectWeaponByIndex(i:int):void
- {
- if(!weapons[i].gameObject.GetComponent("weaponLockout").isLocked) {
- SelectWeapon(i);
- selectedWeapon = i;
- }
- }
- function Update () {
- // Did the user press fire?
- if (Input.GetButton ("Fire1"))
- BroadcastMessage("Fire");
- if (Input.GetKeyDown("1") && weapons.length >= 1) {
- selectWeaponByIndex(0);
- } else if (Input.GetKeyDown("2") && weapons.length >= 2) {
- selectWeaponByIndex(1);
- } else if (Input.GetKeyDown("3") && weapons.length >= 3) {
- selectWeaponByIndex(2);
- } else if (Input.GetKeyDown("4") && weapons.length >= 4) {
- selectWeaponByIndex(3);
- } else if (Input.GetKeyDown("5") && weapons.length >= 5) {
- selectWeaponByIndex(4);
- }
- }
- function SelectWeapon (index : int) {
- for (var i=0;i<transform.childCount;i++) {
- // Activate the selected weapon
- if (i == index)
- transform.GetChild(i).gameObject.SetActiveRecursively(true);
- // Deactivate all other weapons
- else
- transform.GetChild(i).gameObject.SetActiveRecursively(false);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement