public void EjectMagazine() { if (!hasMagazine) { return; } // TODO: Alter gun appearance to reflect unloaded mag // Spawns a magazine and sets the mags stored ammo and capacity, if the gun can chamber a round then the stored ammo does not count the chambered round // TODO: Eject magazine from eject transform, add slight force based on ejection direction MagazineObject magazine = Instantiate(ammoStats.magazinePrefab, transform.position, Quaternion.identity).GetComponent <MagazineObject>(); magazine.ammoCapacity = ammoStats.magazineCapacity; magazine.StoredAmmo = canChamber ? currentAmmo-- : currentAmmo; magazine.ammoType = ammoStats.ammoType; hasMagazine = false; // Empties gun, if a round is chambered then the current ammo contains only that chambered round. if (currentAmmo > 0) { currentAmmo = canChamber ? 1 : 0; } else { currentAmmo = 0; } UpdateAmmoCounter(); }
private void OnTriggerExit(Collider other) { if (other.GetComponent <MagazineObject>() != null) { MagazineObject magObj = other.GetComponent <MagazineObject>(); magObj.IsInAmmoBag(null); } }
public void OnTriggerEnter(Collider other) { if (other.GetComponent <MagazineObject>() != null) { MagazineObject magObj = other.GetComponent <MagazineObject>(); magObj.IsInAmmoBag(this); } }
public void AddAmmo(MagazineObject a_mag) { if (ammoCountDictionary.ContainsKey(a_mag.ammoType)) { ammoCountDictionary[a_mag.ammoType] += a_mag.StoredAmmo; } else { ammoCountDictionary.Add(a_mag.ammoType, a_mag.StoredAmmo); } a_mag.QueueDestroy(); UpdateAmmoCounter(); }
public bool TryReload(MagazineObject a_mag) { if (hasMagazine) { return(false); } currentAmmo += a_mag.StoredAmmo; hasMagazine = true; UpdateAmmoCounter(); a_mag.QueueDestroy(); // TODO: Alter gun appearance to reflect loaded mag return(true); }
public void SpawnAmmo(XRBaseInteractor a_interactor) { if (infiniteAmmo) { MagazineObject mag = Instantiate(activeAmmo.magazinePrefab, transform.position, Quaternion.identity).GetComponent <MagazineObject>(); mag.StoredAmmo = activeAmmo.magazineCapacity; interactionManager.ForceSelectObject(a_interactor, mag); } // If the player has ammo of the active ammo type else if (ammoCountDictionary.ContainsKey(activeAmmo.ammoType)) { if (ammoCountDictionary[activeAmmo.ammoType] > 0) { MagazineObject mag = Instantiate(activeAmmo.magazinePrefab, transform.position, Quaternion.identity).GetComponent <MagazineObject>(); // If the player has enough ammo for a mag, spawn a mag and decrement the stored ammo. if (ammoCountDictionary[activeAmmo.ammoType] >= activeAmmo.magazineCapacity) { mag.StoredAmmo = activeAmmo.magazineCapacity; ammoCountDictionary[activeAmmo.ammoType] -= activeAmmo.magazineCapacity; } // If the player has ammo of the type but not enough for a full mag, spawn a mag containing that ammo. else { mag.StoredAmmo = ammoCountDictionary[activeAmmo.ammoType]; ammoCountDictionary[activeAmmo.ammoType] = 0; } UpdateAmmoCounter(); interactionManager.ForceSelectObject(a_interactor, mag); } } else { // TODO: Out of ammo indicator Debug.Log("Out of Ammo!"); } }
public void FixedUpdate() { fireCooldown -= Time.fixedDeltaTime; if (fireCooldown < 0) { fireCooldown = 0; } Transform magTransform = magazineTransform.transform; magTransform.rotation = transform.rotation; magTransform.position = transform.position + magazineLocationOffset.z * transform.forward + magazineLocationOffset.y * transform.up + magazineLocationOffset.x * transform.right; // magazine logics if (loadedMagazine != null) { loadedMagazine.OnHolding(magTransform); } else { Vector3 halfSize = magazineLocationSize * 0.5f; Collider[] colliders = Physics.OverlapBox(magTransform.position, halfSize, Quaternion.Euler(transform.forward), magazineLayer); foreach (Collider collider in colliders) { MagazineObject magazine = collider.GetComponent <MagazineObject>(); // if we find legal magazine that isn't already picked up if (magazine != null && magazine.MagazineKey == magazineKey && !magazine.isPickedUp) { // TODO: require a relative velocity for the gun to reload & play a sound on reload loadedMagazine = magazine; loadedMagazine.OnLoaded(magTransform, this); } } } // two hand logic if (triggerHand == null) { offhand = null; } if (offhandArea != null && offhand != null) { Vector3 handsVector = offhand.transform.position - triggerHand.transform.position; //transform.rotation = Quaternion.LookRotation(handsVector, transform.up); Quaternion newRotation = Quaternion.LookRotation(handsVector, transform.up); Vector3 euler = transform.rotation.eulerAngles; float zRotaion = triggerHand.transform.rotation.eulerAngles.z - euler.z; transform.rotation = newRotation * Quaternion.AngleAxis(zRotaion, Vector3.forward); if (!offhandArea.bounds.Contains(offhand.transform.position)) { offhand = null; } } else if (triggerHand != null) { //TODO loook into optimizing? if (triggerHand.transform.tag != PlayerString) { transform.rotation = triggerHand.transform.rotation; } else { transform.rotation = triggerHand.transform.rotation * Quaternion.Euler(triggerHeldRotationOffset); } } }