public bool HasAmmoLeft() { int numberOfAmmunition = ammunition; if (ammunitionLeft != GunsConstants.InfinityAmmunition()) { numberOfAmmunition += ammunitionLeft; } return numberOfAmmunition == GunsConstants.EmptyMagazine() ? false : true; }
private bool CanShoot() { int numberOfAmmunition = ammunition; if (ammunitionLeft != GunsConstants.InfinityAmmunition()) { numberOfAmmunition += ammunitionLeft; } return Time.time - lastShootTime > shootTimeInterval && numberOfAmmunition != GunsConstants.EmptyMagazine(); }
private void CreateGuns() { Gun Pistol = new Gun(); Pistol.Type = GunType.Pistol; Pistol.AmmunitionLeft = GunsConstants.InfinityAmmunition();; Pistol.Ammunition = 7; Gun Submachinegun = new Gun(); Submachinegun.Type = GunType.SubMachinegun; Submachinegun.AmmunitionLeft = GunsConstants.EmptyMagazine(); Submachinegun.Ammunition = GunsConstants.EmptyMagazine(); Gun Machinegun = new Gun(); Machinegun.Type = GunType.Machinegun; Machinegun.AmmunitionLeft = GunsConstants.EmptyMagazine(); Machinegun.Ammunition = GunsConstants.EmptyMagazine(); guns = new Gun[3]; guns[GunsConstants.PistolGunType()] = Pistol; guns[GunsConstants.SubmachinegunGunType()] = Submachinegun; guns[GunsConstants.MachinegunGunType()] = Machinegun; }
public void MediumEnemyGun () { magazineCapacity = 20; ammunitionLeft = GunsConstants.InfinityAmmunition(); reloadingTime = 8; // seconds lastShootTime = 0; shootTimeInterval = 1.2f; isReloading = false; reloadingTime = 0.1f; owner = GunOwner.Enemy; }
public void BasicEnemyGun () { ammunition = 7; ammunitionLeft = GunsConstants.InfinityAmmunition(); reloadingTime = 5; // seconds lastShootTime = 0; shootTimeInterval = 1.5f; isReloading = false; reloadingTime = 0.1f; owner = GunOwner.Enemy; }
public void PistolGun () { magazineCapacity = 7; ammunition = magazineCapacity; ammunitionLeft = GunsConstants.InfinityAmmunition(); reloadingTime = 1.6f; // seconds lastShootTime = 0; shootTimeInterval = 0.7f; isReloading = false; owner = GunOwner.Player; }
public void SuperEnemyGun() { magazineCapacity = 30; ammunition = magazineCapacity; ammunitionLeft = GunsConstants.InfinityAmmunition(); reloadingTime = 5; // seconds lastShootTime = 0; shootTimeInterval = 0.9f; isReloading = false; reloadingTime = 0.1f; owner = GunOwner.Enemy; }
public void Reload() { if ( Time.time - startReloadingTime > reloadingTime) { ammunition = magazineCapacity; if (ammunitionLeft != GunsConstants.InfinityAmmunition()) { ammunitionLeft -= ammunition; } isReloading = false; if (owner == GunOwner.Player) { GameHUDManager.instance.HideReloadingText(); GameHUDManager.instance.SetAmmoText(Ammunition, AmmunitionLeft); } } }
public void AddAmmo(int ammo){ if (ammunitionLeft != GunsConstants.InfinityAmmunition()) { ammunitionLeft += ammo; } }
public void SetAmmoText(int ammo, int ammunitionLeft) { string ammoString = ammunitionLeft == GunsConstants.InfinityAmmunition() ? string.Format("{0}/∞", ammo) : string.Format("{0}/{1}", ammo, ammunitionLeft); ammoText.text = ammoString; }
void Update() { if (playerPhysics.movementStopped) { targetSpeed = 0; currentSpeed = 0; } animationSpeed = IncrementTowards(animationSpeed, Mathf.Abs(targetSpeed), accelerationSpeed); animator.SetFloat(ANIMATOR_SPEED, animationSpeed); //Input targetSpeed = Input.GetAxisRaw(HORIZONTAL_KEYS) * runSpeed; currentSpeed = IncrementTowards(currentSpeed, targetSpeed, accelerationSpeed); if (playerPhysics.grounded) { amountToMove.y = 0; //Landed if (jumping) { jumping = false; animator.SetBool(ANIMATOR_JUMPING, false); } //Jump if (Input.GetButtonDown(JUMP_KEY)) { amountToMove.y = jumpHeight; jumping = true; animator.SetBool(ANIMATOR_JUMPING, true); } } amountToMove.x = currentSpeed; amountToMove.y -= gravity * Time.deltaTime; playerPhysics.Move(amountToMove * Time.deltaTime); //Face direction float moveDirection = Input.GetAxisRaw(HORIZONTAL_KEYS); if (moveDirection != 0) { transform.eulerAngles = moveDirection > 0 ? Vector3.up * 180: Vector3.zero; direction = moveDirection > 0 ? Directions.Right() : Directions.Left(); } //Shot if (Input.GetButtonDown(FIRE_KEY)) { gunController.Shoot(direction, Tags.PlayerBulletTag()); if (!gunController.HasAmmoLeft() && gunController.AmmunitionLeft != GunsConstants.InfinityAmmunition()) { HandleNoAmmunition(); } else { Gun gun = PlayerManager.instance.CurrentGun(); gun.Ammunition = gunController.Ammunition; gun.AmmunitionLeft = gunController.AmmunitionLeft; Debug.Log(gun.Ammunition); } } GameHUDManager.instance.SetAmmoText(gunController.Ammunition, gunController.AmmunitionLeft); }