void weaponPickUp() { // Dropping Previous weapon of that type if we have one if (pStats.meleWeaponSlot != null && weaponPrefab.GetComponent <MeleWeapon>()) { GameObject newDrop = Instantiate(pStats.meleWeaponSlot.GetComponent <MeleWeapon>().pickUp, transform.position, transform.rotation); } else if ((pStats.rangedWeaponSlot != null && weaponPrefab.GetComponent <RangedWeapon>())) { GameObject newDrop = Instantiate(pStats.rangedWeaponSlot.GetComponent <RangedWeapon>().pickUp, transform.position, transform.rotation); PickUpScript pScript = newDrop.GetComponent <PickUpScript>(); pScript.Value = pStats.rangedWeaponSlot.GetComponent <RangedWeapon>().ammo; } if (weaponPrefab.GetComponent <MeleWeapon>()) { if (pStats.selectedWeapon.GetComponent <MeleWeapon>()) { Destroy(pStats.meleWeaponSlot); GameObject weap = Instantiate(weaponPrefab, pStats.equippedWeaponPos); weap.transform.position = pStats.equippedWeaponPos.position; MeleWeapon meleWeaponScript = weap.GetComponent <MeleWeapon>(); pStats.meleWeaponSlot = weap; pStats.selectedWeapon = pStats.meleWeaponSlot; meleWeaponScript.pickedUp(player, this); } else { Destroy(pStats.meleWeaponSlot); GameObject weap = Instantiate(weaponPrefab, pStats.unequippedMeleWeaponPos); weap.transform.position = pStats.unequippedMeleWeaponPos.position; MeleWeapon meleWeaponScript = weap.GetComponent <MeleWeapon>(); meleWeaponScript.pickedUp(player, this); pStats.meleWeaponSlot = weap; } } else { if (pStats.selectedWeapon.GetComponent <RangedWeapon>()) { Destroy(pStats.rangedWeaponSlot); GameObject weap = Instantiate(weaponPrefab, pStats.equippedWeaponPos); weap.transform.position = pStats.equippedWeaponPos.position; RangedWeapon rangedWeaponScript = weap.GetComponent <RangedWeapon>(); rangedWeaponScript.pickedUp(player, this); rangedWeaponScript.ammo = Value; pStats.rangedWeaponSlot = weap; pStats.selectedWeapon = pStats.rangedWeaponSlot; } else { Destroy(pStats.rangedWeaponSlot); GameObject weap = Instantiate(weaponPrefab, pStats.unequippedRangedWeaponPos); weap.transform.position = pStats.unequippedRangedWeaponPos.position; RangedWeapon rangedWeaponScript = weap.GetComponent <RangedWeapon>(); rangedWeaponScript.pickedUp(player, this); rangedWeaponScript.ammo = Value; pStats.rangedWeaponSlot = weap; } } Destroy(gameObject); }