private void OnTriggerEnter(Collider other) { if (other.CompareTag("Player")) { // get the weapons of the player, even if they are inactive Pistol pistol = player.GetComponentInChildren(typeof(Pistol), true) as Pistol; AssaultRifle rifle = player.GetComponentInChildren(typeof(AssaultRifle), true) as AssaultRifle; Shotgun shotgun = player.GetComponentInChildren(typeof(Shotgun), true) as Shotgun; if (ammoSprite == sprites[0]) { WeaponAmmo ammo = pistol.GetComponent <WeaponAmmo>(); if (ammo.currentReserveAmmo != ammo.maxReserveAmmo) { pickUpSound.Play(); ammo.currentReserveAmmo = ammo.currentReserveAmmo + (ammoMultiplier * ammo.maxMag); if (ammo.currentReserveAmmo > ammo.maxReserveAmmo) { ammo.currentReserveAmmo = ammo.maxReserveAmmo; } StartCoroutine(DeleteObject()); } } else if (ammoSprite == sprites[1]) { WeaponAmmo ammo = rifle.GetComponent <WeaponAmmo>(); if (ammo.currentReserveAmmo != ammo.maxReserveAmmo) { pickUpSound.Play(); ammo.currentReserveAmmo = ammo.currentReserveAmmo + (ammoMultiplier * ammo.maxMag); if (ammo.currentReserveAmmo > ammo.maxReserveAmmo) { ammo.currentReserveAmmo = ammo.maxReserveAmmo; } StartCoroutine(DeleteObject()); } } else if (ammoSprite == sprites[2]) { WeaponAmmo ammo = shotgun.GetComponent <WeaponAmmo>(); if (ammo.currentReserveAmmo != ammo.maxReserveAmmo) { pickUpSound.Play(); ammo.currentReserveAmmo = ammo.currentReserveAmmo + (ammoMultiplier * ammo.maxMag); if (ammo.currentReserveAmmo > ammo.maxReserveAmmo) { ammo.currentReserveAmmo = ammo.maxReserveAmmo; } StartCoroutine(DeleteObject()); } } } }