public void AttachMagazine(Collider magazine) { gunMag = magazine.gameObject; //gunMagVar = magazine.GetComponent<GunMagazine>(); gunMag.gameObject.tag = "NonGrabable"; gunMag.GetComponent <Transform>().parent = null; // setting null to detach from controller gun_magazine = magazine.GetComponent <GunMagazine>(); gunMag.GetComponent <Transform>().parent = GameObject.FindGameObjectWithTag("Gun").transform; //this needs to change to have mag go to correct gun if multiple guns exist gunMag.GetComponent <Transform>().GetComponent <Transform>().localPosition = new Vector3(10.193f, -0.404f, -6.474f); gunMag.GetComponent <Transform>().GetComponent <Transform>().localRotation = Quaternion.Euler(0, 0, 0); gunMag.GetComponent <BoxCollider>().enabled = false; gunMag.GetComponent <Rigidbody>().isKinematic = true; reloadSfx.Play(); if (gun_magazine.AmmunitionCheck(gun_magazine.CURRENT_MAG_SIZE) && chamberedRound == false) { chamberedRound = true; gun_magazine.CURRENT_MAG_SIZE = gun_magazine.CURRENT_MAG_SIZE - 1; if (gun_magazine.CURRENT_MAG_SIZE > 0) { gun_magazine.cartridgeHeight.gameObject.SetActive(true); } else { gun_magazine.cartridgeHeight.gameObject.SetActive(false); } } }
public void OnUpdateMagAmmo() { if (GameManager.Inst.PlayerControl.SelectedPC.MyReference.CurrentWeapon != null) { Weapon myWeapon = GameManager.Inst.PlayerControl.SelectedPC.MyReference.CurrentWeapon.GetComponent <Weapon>(); if (myWeapon != null && myWeapon.IsRanged) { GunMagazine mag = myWeapon.GetComponent <GunMagazine>(); string ammoCount = ""; if (mag.MaxCapacity > 45) { int numberOfSymbols = Mathf.FloorToInt((mag.AmmoLeft * 1f) / mag.MaxCapacity * 10f); for (int i = 0; i < numberOfSymbols; i++) { ammoCount = ammoCount + _magAmmoSymbol; } } else { for (int i = 0; i < mag.AmmoLeft; i++) { ammoCount = ammoCount + _magAmmoSymbol; } } MagAmmo.text = ammoCount; } } else { MagAmmo.text = ""; } }
void Awake() { if (instance != null) { Debug.LogWarning("Multiple inventory instances."); return; } instance = this; }
private bool shooting = false; // if the gun is automatic, see if the player is holding the shoot button private void Awake() { magazine = GetComponent <GunMagazine>(); switch (gunType) { case GunEquiped.Shotgun: currentGun = gameObject.AddComponent <Shotgun>(); magazine.CurrentAmmo = bulletCount[0]; break; case GunEquiped.M4: currentGun = gameObject.AddComponent <M4>(); magazine.CurrentAmmo = bulletCount[1]; break; case GunEquiped.Ak47: currentGun = gameObject.AddComponent <Ak47>(); magazine.CurrentAmmo = bulletCount[2]; break; case GunEquiped.M9: currentGun = gameObject.AddComponent <M9>(); magazine.CurrentAmmo = bulletCount[3]; break; default: break; } currentGun.GetGunTip = gunTip; currentGun.GetBackspinDrag = backspinDrag; delayToShoot = currentGun.GetDelayToShoot; if (UpdateHopUpCount.instance) { UpdateHopUpCount.instance.SetHopUp(backspinDrag); } if (UpdateManualAutomatic.instance) { UpdateManualAutomatic.instance.SetText(automatic); } if (UpdateTypeOfGun.instance) { UpdateTypeOfGun.instance.SetText(gunType.ToString()); } }
public void EjectMagazine() { if (disableBulletHeightRenderer) { Debug.Log("Removing Child Render"); gun_magazine.cartridgeHeight.gameObject.SetActive(false); } if (gun_magazine != null) { magEjectSfx.Play(); } //gunMagVar = null; gunMag.gameObject.tag = "Grabable"; gunMag.GetComponent <Transform>().parent = null; // setting null to detach from Gun gun_magazine = null; gunMag.GetComponent <BoxCollider>().enabled = true; gunMag.GetComponent <Rigidbody>().isKinematic = false; gunMag.GetComponent <Rigidbody>().useGravity = true; StartCoroutine(waiting(gunMag)); // waiting to set tag back to normal for use StartCoroutine(destroyMag(gunMag)); }
void Start() { gunMagazine = GunMagazine.instance; weaponHolder = GameObject.FindGameObjectWithTag("weaponController").GetComponent <weaponSwitching>(); bullets = magCapacity; }
public override void Rebuild(WeaponCallBack callBack, Item weaponItem) { Receiver = GetComponent <GunReceiver>(); Barrel = GetComponent <GunBarrel>(); Stock = GetComponent <GunStock>(); Magazine = GetComponent <GunMagazine>(); this.WeaponItem = weaponItem; _isCooledDown = true; _onSuccessfulShot = callBack; _sparks = MuzzleFlash.Find("Sparks").GetComponent <ParticleSystem>(); _flame = MuzzleFlash.GetComponent <ParticleSystem>(); _bulletOrigin = MuzzleFlash.Find("BulletOrigin").gameObject; //_bulletTrail.ParentWeapon = this; _light = MuzzleFlash.Find("Light").GetComponent <Light>(); _foreGripPos = this.ForeGrip.localPosition; _isEquipped = true; float _npcRecoilReduction = 1; if (Attacker.MyAI.ControlType == AIControlType.NPC) { _npcRecoilReduction = 0f; Barrel.Accuracy = 1; } else { Barrel.Accuracy = (float)weaponItem.GetAttributeByName("Accuracy").Value; } Barrel.Impact = (float)weaponItem.GetAttributeByName("Impact").Value; Barrel.MuzzleVelocity = (float)weaponItem.GetAttributeByName("_Muzzle Velocity").Value; Barrel.Range = (float)weaponItem.GetAttributeByName("Range").Value; Barrel.Handling = (float)weaponItem.GetAttributeByName("Handling").Value; Magazine.MaxCapacity = (int)weaponItem.GetAttributeByName("Magazine Size").Value; Receiver.Recoil = (float)weaponItem.GetAttributeByName("Recoil").Value *_npcRecoilReduction; GunshotSoundName = weaponItem.GetAttributeByName("_GunshotSound").Value.ToString(); _reloadToUnjam = (bool)weaponItem.GetAttributeByName("_ReloadToUnjam").Value; switch (Receiver.FireModes[0]) { case GunFireModes.Semi: Receiver.SemiFireRate = (float)weaponItem.GetAttributeByName("Rate of Fire").Value; break; case GunFireModes.Full: Receiver.AutoFireRate = (float)weaponItem.GetAttributeByName("Rate of Fire").Value; break; case GunFireModes.Burst: Receiver.BurstFireRate = (float)weaponItem.GetAttributeByName("Rate of Fire").Value; break; case GunFireModes.Pump: Receiver.ManualFireRate = (float)weaponItem.GetAttributeByName("Rate of Fire").Value; break; } _pumpStarted = false; Refresh(); }
void Start() { gunMagazine = GunMagazine.instance; SelectWeapon(); rb = player.GetComponent <Rigidbody2D>(); }
public void UpdatePerFrame() { if (_parentCharacter.MyReference.CurrentWeapon == null) { return; } if (!_parentCharacter.MyReference.CurrentWeapon.GetComponent <Weapon>().IsRanged) { return; } //check if there's ammo in the magazine. if low then reload. When there are no enemies in sight, //reload even when not empty; don't do this on player controlled character GunMagazine magazine = _parentCharacter.MyReference.CurrentWeapon.GetComponent <GunMagazine>(); if (magazine.AmmoLeft <= 0 && _parentCharacter.MyAI.ControlType != AIControlType.Player) { StopFiringRangedWeapon(); if (_parentCharacter.ActionState == HumanActionStates.None) { _parentCharacter.SendCommand(CharacterCommands.Reload); _parentCharacter.PlayVocal(VocalType.Coverfire); } } else if (_parentCharacter.MyAI.BlackBoard.TargetEnemy == null && magazine.AmmoLeft <= magazine.MaxCapacity * 0.6f && _parentCharacter.MyAI.ControlType != AIControlType.Player) { StopFiringRangedWeapon(); if (_parentCharacter.ActionState == HumanActionStates.None) { _parentCharacter.SendCommand(CharacterCommands.Reload); _parentCharacter.PlayVocal(VocalType.Coverfire); } } else if (AIWeaponState == AIWeaponStates.FiringRangedWeapon && _parentCharacter.ActionState == HumanActionStates.None) { HandleFiringRangedWeapon(); } //calculate turn/moving scatter float scatterRestore = 3; //TODO: later the restore speed will be based on player skill float aimLerpAngle = 0; if (_parentCharacter.MyAI.ControlType == AIControlType.Player) { aimLerpAngle = GameManager.Inst.PlayerControl.AimLerpAngle; } if (((HumanCharacter)_parentCharacter).CurrentAnimState.IsRotatingBody()) { //increase scatter _turnMoveScatter = Mathf.Lerp(_turnMoveScatter, 1, Time.deltaTime * 6); } else if (_parentCharacter.GetCharacterVelocity().magnitude > 0.1f) { //increase scatter based on velocity _turnMoveScatter = Mathf.Lerp(_turnMoveScatter, Mathf.Clamp01(_parentCharacter.GetCharacterVelocity().magnitude / 6), Time.deltaTime * 6); } else if (aimLerpAngle > 10) { _turnMoveScatter = Mathf.Clamp01((aimLerpAngle - 10) / 50) * 2; } else { //decrease scatter _turnMoveScatter = Mathf.Lerp(_turnMoveScatter, 0, Time.deltaTime * scatterRestore); } }
public void OnUpdateTotalAmmo() { GameObject currentWeapon = GameManager.Inst.PlayerControl.SelectedPC.MyReference.CurrentWeapon; Item equippedWeapon = GameManager.Inst.PlayerControl.SelectedPC.MyAI.BlackBoard.EquippedWeapon; if (currentWeapon == null && equippedWeapon != null) { //Item throwItem = GameManager.Inst.PlayerControl.SelectedPC.Inventory.ThrowSlot; if (equippedWeapon.Type == ItemType.Thrown) { int ammoInBackpack = GameManager.Inst.PlayerControl.SelectedPC.Inventory.CountItemsInBackpack(equippedWeapon.ID) + 1; TotalAmmo.text = ammoInBackpack.ToString(); } else { AmmoType.text = ""; TotalAmmo.text = ""; MagAmmo.text = ""; } } else if (currentWeapon != null) { Weapon myWeapon = GameManager.Inst.PlayerControl.SelectedPC.MyReference.CurrentWeapon.GetComponent <Weapon>(); if (myWeapon != null && myWeapon.IsRanged) { GunMagazine mag = myWeapon.GetComponent <GunMagazine>(); _magAmmoSymbol = "I"; if (mag.MaxCapacity <= 20) { MagAmmo.fontSize = 25; } else if (mag.MaxCapacity <= 30) { MagAmmo.fontSize = 22; } else if (mag.MaxCapacity <= 45) { MagAmmo.fontSize = 16; } else { MagAmmo.fontSize = 25; _magAmmoSymbol = "="; } Item ammo = myWeapon.GetComponent <Gun>().GetAmmoItem(); int ammoInBackpack = GameManager.Inst.PlayerControl.SelectedPC.Inventory.CountItemsInBackpack(ammo.ID); TotalAmmo.text = ammoInBackpack.ToString(); AmmoType.text = ammo.Name; } else if (myWeapon != null && !myWeapon.IsRanged) { AmmoType.text = ""; TotalAmmo.text = ""; MagAmmo.text = ""; } OnUpdateMagAmmo(); } else { OnPutAway(); } }