// add a block to your inventory public static void AddItem(InventoryItem_Block item) { for (int i = 0; i < inventoryItems.Length; i++) { if (inventoryItems[i] == null) { inventoryItems[i] = item; } else { } } }
public override void m_break(int amount) { if (breakable) { m_hardness -= 1; if (m_hardness <= 0) { Main mainscrpt = GameObject.FindObjectOfType <Main>(); mainscrpt.wg.worldBlocks[(int)index.x, (int)index.y, (int)index.z] = null; // unlocate yourself from worldblocks m_hide(); Main mainclass = GameObject.FindObjectOfType <Main>(); mainclass.wg.Draw(mainclass.transform.position); // black magic fuckery Block instance = new Block_Log(Vector3.zero); // get type of child class and make an instance InventoryItem_Block item = new InventoryItem_Block(instance); // create a new inventory item of type "block" and set its refference to the type of this class(the derived class type) Inventory.AddItem(item); // add dthe inventory item to inventory } } }