Ok. Here it goes.
Well, first off, you equip items pressing a button on a GUI. From there, depending on the button you press, it adds an entry to a hashtable, which is then checked for a certain key and depending on the key, loads a certain resource(in this case a prefab for the weapon)
private var InventoryManager : InventoryManager; InventoryManager = GetComponent("InventoryManager"); function OnGUI () { if ( GUI.Button(Rect(10,10,50,50),"Equip Platinum Gladius") ) { InventoryManager.equipWeapon.Add("Platinum Gladius", 1); InventoryManager.hasWeapon = true; InventoryManager.CheckForWeapon(); } }
From that point, it goes through to the InventoryManager Script
(rh = righthand of my character)
var equipWeapon : Hashtable; equipWeapon = new Hashtable(); var hasWeapon : boolean = false; var rh : GameObject; function CheckForWeapon () { if ( hasWeapon ) { if ( equipWeapon.ContainsKey("Copper Short Sword") ) { Debug.Log("Copper Short Sword"); mesh = Instantiate (Resources.Load("Copper Short Sword") ) as GameObject; mesh.transform.parent = rh.transform; mesh.transform.position = rh.transform.position; } ... // From here it continues on through checking for each entry possible into the Hashtable, currently // it's going through about 20 items but in the end it'll be going through about 160-200 ... ... ... // Until it reaches the one for the button if ( equipWeapon.ContainsKey("Platinum Gladius") ) { Debug.Log("Platinum Gladius"); mesh = Instantiate (Resources.Load("Platinum Gladius") ) as GameObject; mesh.transform.parent = rh.transform; mesh.transform.position = rh.transform.position; } }
And then it perform’s it’s duty.
I know, this may seem like anything but a robust system. I’m rather new to the coding of games(I’m typically just an artist). Is there a more simple, or perhaps more efficient method of accomplishing the same goal?