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);
            }
        }
    }
Exemple #2
0
 // Use thiss for initialization
 void Start()
 {
     Instance          = this;
     ammoText          = GetComponent <Text> ();
     ammoText.text     = "45/45";
     reloading         = false;
     ammo              = 45;
     maxAmmo           = ammo;
     secondsCalc       = 0.0f;
     currentReloadTime = 0.125f;
 }
    void EquipWeapon(AmmoTracker ammoTracker)
    {
        currentAmmoTracker = ammoTracker;
        bulletPrefab       = currentAmmoTracker.bulletPrefab;
        bulletSpec         = currentAmmoTracker.bulletSpec;
        ammoUI.UpdateWeapon(currentAmmoTracker);

        if (currentAmmoTracker.AmmoAvailable())
        {
            gunAudio.clip = bulletSpec.shootAudio;
        }
        else
        {
            gunAudio.clip = noAmmoAudio;
        }
    }
 void OnTriggerStay(Collider other)
 {
     if (other.gameObject.tag == "Player")
     {
         campUI.SetActive(true);
         campUI.GetComponent <TextMeshProUGUI>().text = "Press E to Heal.";
         if (Input.GetButton("Interact"))
         {
             //Debug.Log("pressed");
             NumberTracker playerNums = other.gameObject.GetComponent <NumberTracker>();
             playerNums.heal(playerNums.healthMax);
             AmmoTracker ammo = playerNums.GetComponentInChildren <AmmoTracker>();
             ammo.reload();
         }
     }
 }
Exemple #5
0
 private void Start()
 {
     inputField  = this.gameObject.GetComponent(typeof(InputField)) as InputField;
     ammoTracker = this.gameObject.transform.parent.transform.parent.transform.parent.GetComponentInChildren <AmmoTracker>();
 }
Exemple #6
0
 public void Start()
 {
     ammoTracker = transform.parent.GetChild(2).GetComponent <AmmoTracker>();
 }
 // Start is called before the first frame update
 void Start()
 {
     ammo   = weaponHandler.GetComponent <AmmoTracker>();
     anim   = GetComponent <Animation>();
     shooty = projectileSource.GetComponent <ProjectileValues>();
 }