public void CollectWeapon(Rigidbody newBulletPrefab) { BulletTracker.CollectAmmo(newBulletPrefab.GetComponent <BulletSpec> ()); // Find through currently obtained weapons to add the ammo for (int i = 0; i < ammoTrackerList.Count; i++) { AmmoTracker ammoTracker = ammoTrackerList[i]; if (ammoTracker.AddAmmo(newBulletPrefab)) // We have this weapon already. Add ammo. { if (ammoTrackerListIndex == i) // Only update UI if currently showing this gun { ammoUI.UpdateAmmo(ammoTracker); gunAudio.clip = bulletSpec.shootAudio; // Restore shooting sound (in case ammo was empty) } return; } } { // Cannot find -> this is a new weapon, add new AmmoTracker ammoTrackerList.Add(new AmmoTracker(newBulletPrefab)); AmmoTracker ammoTracker = ammoTrackerList[ammoTrackerList.Count - 1]; // Update currentAmmoTracker and UI if this is the 1st weapon collected if (ammoTrackerListIndex == ammoTrackerList.Count - 1) { EquipWeapon(ammoTracker); } } }
private void Start() { cameraTransform = Camera.main.transform; handAnim = transform.parent.GetComponent <Animator>(); magAmmo = stats.magazineSize; AmmoUI.UpdateAmmo(magAmmo); }
public void Fire() { handAnim.Play("Fire"); for (int i = 0; i < stats.bulletCount; i++) { Vector3 forwardVector = Vector3.forward; float deviation = UnityEngine.Random.Range(0f, stats.spread); float angle = UnityEngine.Random.Range(0f, 360f); forwardVector = Quaternion.AngleAxis(deviation, Vector3.up) * forwardVector; forwardVector = Quaternion.AngleAxis(angle, Vector3.forward) * forwardVector; forwardVector = cameraTransform.transform.rotation * forwardVector; Physics.Raycast(cameraTransform.position, forwardVector, out RaycastHit hit, 200f, layerMask); // change to projectile? if (hit.transform) { IHitReceiver hittable = hit.transform.GetComponent <IHitReceiver>(); if (hittable != null) { hittable.Hit(15.0f); } else { //DrawDecals; } Transform dec = Instantiate(decal, hit.transform).transform; dec.position = hit.point; } } magAmmo--; nextFireTime = Time.time + stats.fireTime; AmmoUI.UpdateAmmo(magAmmo); recoilObject.recoil += stats.recoilTime; if (magAmmo == 0) { Reload(); } }
public void FinishReload() { weaponStatus = WeaponStatus.Normal; magAmmo = stats.magazineSize; AmmoUI.UpdateAmmo(magAmmo); }