private void EnablePickup() { switch (_thisItem) { case _itemType.Handgun: Handgun playerHandgun = weaponManager.GetComponentInChildren <Handgun>(true); if (playerHandgun.CurrentAmmo < playerHandgun.MagazineCapacity + 1) // Check if we have less than 1 clip left, if so then respawn ammo, add +1 in case user is running around with one magazine left in ammo reserve { GetComponent <ParticleSystem>().Play(); GetComponent <Collider>().enabled = true; _pickupMesh.SetActive(true); CancelInvoke("EnablePickup"); // Make sure to cancel the invoke } break; case _itemType.Shotgun: Shotgun playerShotgun = weaponManager.GetComponentInChildren <Shotgun>(true); if (playerShotgun.CurrentAmmo < playerShotgun.MagazineCapacity * 2) // Check if we have less than 1 clip left, if so then respawn ammo { GetComponent <ParticleSystem>().Play(); GetComponent <Collider>().enabled = true; _pickupMesh.SetActive(true); CancelInvoke("EnablePickup"); } break; case _itemType.PlasmaRifle: PlasmaRifle playerPlasmaRifle = weaponManager.GetComponentInChildren <PlasmaRifle>(true); if (playerPlasmaRifle.CurrentAmmo < playerPlasmaRifle.MagazineCapacity) // Check if we have less than 1 clip left, if so then respawn ammo { GetComponent <ParticleSystem>().Play(); GetComponent <Collider>().enabled = true; _pickupMesh.SetActive(true); CancelInvoke("EnablePickup"); } break; case _itemType.HealthPickup: if (PlayerStats.PlayerHealth <= 30.0f) { GetComponent <ParticleSystem>().Play(); GetComponent <Collider>().enabled = true; _pickupMesh.SetActive(true); } break; case _itemType.AmmoPickup: break; default: break; } }
public void ChangeWeapon() { var world = new World(11, 11); var player = new Character(new Stats(8, 5, 10), world) { Position = new Point(0, 0) }; var gun = new PlasmaRifle(); world.PlaceItem(gun, player.Position); player.PickUpItem(gun); player.ChangeWeapon(gun); Assert.AreEqual(player.CurrentWeapon, gun); }
void Start() { resetHurtTimer = hurtTimer; CheckpointBox = GameObject.Find("/Player/LookAt/"); WarpPortal.SetActive(false); GameEnd = false; AmmoShot = true; originalPos = camTransform.localPosition; lives = 9; health = 100; SetCountHealth(); SetCountLives(); BossFireBallDam = false; PickupText.text = ""; // Set Timer variables and Speed redScreenFlashTimerStart = redScreenFlashTimer; whiteScreenFlashTimerStart = whiteScreenFlashTimer; FadeTime = 0.0f; FadeSpeed = 1.0f; Lava = false; // Set all guns to be off or on Assault = 1; flak = 1; plasma = 1; rail = 1; rocket = 1; bfgproton = 1; LastCheckPoint = CheckpointBox.transform.position; // Access all weapon scripts PistolScript = GetComponent <Pistol>(); AssaultRifleScript = GetComponent <AssaultRifle>(); FlakCannonScript = GetComponent <FlakCannon>(); PlasmaRifleScript = GetComponent <PlasmaRifle>(); BFGProtonScript = GetComponent <BFGProton>(); RailGunScript = GetComponent <RailGun>(); RocketLauncherScript = GetComponent <RocketLauncher>(); // Set all weapon scripts to true or false ShutOffAllWeapons(); SetupPistol(); }
private PlayerMeleeAttack _meleeAttackScript; // Script for melee Attacking // ------------------------------------------------------------------------------------------ // METHOD: Awake() // DESCRIPTION: Cache global variables and convert layer names to their integer values // ------------------------------------------------------------------------------------------ void Awake() { TagsHashIDs = FindObjectOfType <TagsHashIDs>(); _weaponManagerScript = GetComponent <WeaponManager>(); _fpsAnimator = GetComponent <Animator>(); _noWeaponLayer = _fpsAnimator.GetLayerIndex("NoWeaponLayer"); _handgunLayer = _fpsAnimator.GetLayerIndex("HandgunLayer"); _macheteLayer = _fpsAnimator.GetLayerIndex("MacheteLayer"); _shotgunLayer = _fpsAnimator.GetLayerIndex("ShotgunLayer"); _plasmaRifleLayer = _fpsAnimator.GetLayerIndex("PlasmaRifleLayer"); //_pickupReloadLayer = _fpsAnimator.GetLayerIndex("PickupAndReload"); _handgun = GetComponentInChildren <Handgun>(true); _shotgun = GetComponentInChildren <Shotgun>(true); _plasmaRifle = GetComponentInChildren <PlasmaRifle>(true); }
// ------------------------------------------------------------------------ // Method: OnTriggerEnter // Description: Change a value in the player's script depending on which // item this script is attached to // ------------------------------------------------------------------------ private void OnTriggerEnter(Collider other) { // TODO Add pickup noise if (other.CompareTag(TagsHashIDs.Player)) { weaponManager = other.GetComponentInChildren <WeaponManager>(); switch (_thisItem) { case _itemType.Handgun: if (weaponManager.HasHandgun) { Handgun playerHandgun = weaponManager.GetComponentInChildren <Handgun>(true); // Check if we have maximum ammo before updating the ammo count and disabling the pickup: if (playerHandgun.CurrentAmmo < playerHandgun.MaximumAmmo) { for (int i = 0; i < playerHandgun.MagazineCapacity * 4; i++) // We gain 4 handgun clips from a pickup: { if (playerHandgun.CurrentAmmo < playerHandgun.MaximumAmmo) { playerHandgun.CurrentAmmo++; } } weaponManager.GetComponent <FPSRigAnimator>().UpdateAmmoDisplay(); if (playerHandgun.shotCount >= playerHandgun.MagazineCapacity && weaponManager.CurrentWeapon == WeaponSet.Handgun) { weaponManager.GetComponent <FPSRigAnimator>().TriggerReload(WeaponSet.Handgun); } DisablePickup(); } } else { weaponManager.HasHandgun = true; Handgun playerHandgun = weaponManager.GetComponentInChildren <Handgun>(true); if (weaponManager.GetComponent <FPSRigAnimator>().CanFire) // Only switch to the weapon automatically if we are not in reload animation { weaponManager.SwitchWeapon(WeaponSet.Handgun); } playerHandgun.CurrentAmmo = playerHandgun.MagazineCapacity * 4; if (weaponManager.CurrentWeapon == WeaponSet.Handgun) { // Only update the ammo display if that weapon is selected weaponManager.GetComponent <FPSRigAnimator>().UpdateAmmoDisplay(); } DisablePickup(); } break; case _itemType.Shotgun: if (weaponManager.HasShotgun) { Shotgun playerShotgun = weaponManager.GetComponentInChildren <Shotgun>(true); if (playerShotgun.CurrentAmmo < playerShotgun.MaximumAmmo) { for (int i = 0; i < playerShotgun.MagazineCapacity * 4; i++) { if (playerShotgun.CurrentAmmo < playerShotgun.MaximumAmmo) { playerShotgun.CurrentAmmo++; } } weaponManager.GetComponent <FPSRigAnimator>().UpdateAmmoDisplay(); if (playerShotgun.shotCount >= playerShotgun.MagazineCapacity && weaponManager.CurrentWeapon == WeaponSet.Shotgun) { weaponManager.GetComponent <FPSRigAnimator>().TriggerReload(WeaponSet.Shotgun); } DisablePickup(); } } else { weaponManager.HasShotgun = true; Shotgun playerShotgun = weaponManager.GetComponentInChildren <Shotgun>(true); if (weaponManager.GetComponent <FPSRigAnimator>().CanFire) // Only switch to the weapon automatically if we are not in reload animation { weaponManager.SwitchWeapon(WeaponSet.Shotgun); } playerShotgun.CurrentAmmo = playerShotgun.MagazineCapacity * 4; if (weaponManager.CurrentWeapon == WeaponSet.Shotgun) { weaponManager.GetComponent <FPSRigAnimator>().UpdateAmmoDisplay(); } DisablePickup(); } break; case _itemType.PlasmaRifle: if (weaponManager.HasPlasmaRifle) { PlasmaRifle playerPlasmaRifle = weaponManager.GetComponentInChildren <PlasmaRifle>(true); if (playerPlasmaRifle.CurrentAmmo < playerPlasmaRifle.MaximumAmmo) { for (int i = 0; i < playerPlasmaRifle.MagazineCapacity * 2; i++) { if (playerPlasmaRifle.CurrentAmmo < playerPlasmaRifle.MaximumAmmo) { playerPlasmaRifle.CurrentAmmo++; } } weaponManager.GetComponent <FPSRigAnimator>().UpdateAmmoDisplay(); if (playerPlasmaRifle.shotCount >= playerPlasmaRifle.MagazineCapacity && weaponManager.CurrentWeapon == WeaponSet.PlasmaRifle) { weaponManager.GetComponent <FPSRigAnimator>().TriggerReload(WeaponSet.PlasmaRifle); } DisablePickup(); } } else { weaponManager.HasPlasmaRifle = true; PlasmaRifle playerPlasmaRifle = weaponManager.GetComponentInChildren <PlasmaRifle>(true); if (weaponManager.GetComponent <FPSRigAnimator>().CanFire) // Only switch to the weapon automatically if we are not in reload animation { weaponManager.SwitchWeapon(WeaponSet.PlasmaRifle); } playerPlasmaRifle.CurrentAmmo = playerPlasmaRifle.MagazineCapacity * 2; if (weaponManager.CurrentWeapon == WeaponSet.PlasmaRifle) { weaponManager.GetComponent <FPSRigAnimator>().UpdateAmmoDisplay(); } DisablePickup(); } break; case _itemType.HealthPickup: // Check if the player can gain health if (PlayerStats.PlayerHealth < 100.0f) { other.GetComponent <PlayerLifecycle>().GainHealth(15f); DisablePickup(); } break; case _itemType.AmmoPickup: // Ammo pickup is handled if player picks up a weapon type but already has it gameObject.SetActive(false); break; default: break; } } }