This is potentially quite a large question, so I’ll try and briefly explain how we do things:
For our RPG we use a script that is serialisable and defines an Item. In the game world a similar script ItemInstance denotes an instance of an item, contains a reference to a concrete Item and any ancillary data such as if the weapon has charges or there are 5 of 10 (considering items that stack). The Item script itself contains detail such as the item type (i.e. a Mace) and what damage or armour value the item provides.
The Item itself has GameObject members that reference prefabs. For our game we instantiate the prefab to create the 3D object in the game world. We have a backpack which displays the icon representation by copying the script from the icon prefab for that Item (we use EZGUI so we actually copy the appearance of a disabled UIButton that’s used for the icon image).
As I say this is quite a large topic, but you might have:
List<Weapon> PlayerWeapons = new List<Weapon>();
[System.Serializable]
public class Weapon
{
public string WeaponName;
public Texture WeaponIcon;
public GameObject WeaponGeom;
}
And then perhaps…
[System.Serializable]
public class WeaponInstance
{
public Weapon Weapon;
public int BulletsInClip;
public int BulletsRemaining;
}
You can either set this up as an array somewhere else i.e. on an ItemManager and copy the iterms, or you could create an ItemList that subclasses a ScriptableObject that contains a list of items in your world, i.e.:
public class ItemList : ScriptableObject
{
public List<Weapons> MasterWeaponList = new public List<Weapons>();
}
You then need to be able to create this as an assert by extending the editor and using AssetDatabase.CreateAsset(). But the former may be easier - it depends on how you wish to access the data/flexibility/number of weapons.
Sorry if this is a can of worms, but I’d definitely use a List<> or array of Weapons somewhere and I’d have a corresponding List of either copies of those weapons or an instance that references them.
In your code above, you could always find the child item by some string from a structure that defines the weapon and thereby show/hide the appropriate ones.
Naturally we have a LOT of weapons and other items in our RPG so our system needs to be a little more full featured. You could just have an array of bools for your system and skip the weapon if the bool isn’t true - to indicate the player has it. It’s not very extensible however and has no real relationship to weapons you might pick up. Also, where do you store your bullets for a given weapon?