IEnumerator SwapGun() { Gun.GunType previousGunType = equippedGunType; int totalGuns = gunHolder.childCount; for (int i = 1; i < totalGuns; i++) { if (PlayerManager.Instance.HasGunOfType((Gun.GunType)(((int)equippedGunType + i) % totalGuns))) { equippedGunType = (Gun.GunType)((int)(equippedGunType + i) % totalGuns); } } if (equippedGunType != previousGunType) { isSwappingGun = true; onGunSwapStart.Invoke(); yield return(new WaitForSeconds(equippedGun.SwapGunOutAnimation.length)); SetEquippedGun(); yield return(new WaitForSeconds(equippedGun.SwapGunInAnimation.length)); isSwappingGun = false; } }
public void Equip(Gun.GunType type) { switch (type) { case Gun.GunType.LaserGun: GameObject o = GameObject.Instantiate(LaserGunPrefab); o.GetComponent <LaserGun>().setButtonSprite(buttonSprite); o.transform.SetParent(GunManager.singleton.transform); o.transform.localPosition = new Vector3(0, 0, 0); GunManager.singleton.Equipped = o.GetComponent <LaserGun>(); break; default: GunManager.singleton.Equipped = null; break; } if (Application.isMobilePlatform && GunManager.singleton.Equipped != null) { fireButton.GetComponentInChildren <Button>(true).interactable = true; } else if (Application.isMobilePlatform) { fireButton.GetComponentInChildren <Button>(true).interactable = false; } }
private void Update() { if (Input.GetKeyDown(key)) { index = (index + 1) % bulletPrefabs.Length; currentGun = (Gun.GunType)(index % 4); gun.currentGun = gunFire.currentGun = currentGun; gun.bulletPrefab = bulletPrefabs[index]; } }
public bool HasGunOfType(Gun.GunType type) { bool hasGunOfType = false; foreach (Gun gun in activeGuns) { if (gun.TypeOfGun == type) { hasGunOfType = true; break; } } return(hasGunOfType); }
void Awake() { equippedGunType = initialGun; equippedConsumableIndex = 0; SetEquippedGun(); SetEquippedConsumable(); if (!equippedConsumable) { foreach (Transform consumable in consumableHolder) { SwapConsumable(); if (equippedConsumable) { break; } } } }