- Home /
How to make things in my inventory able to drop and use?
Hello, in my game I want my inventory to have food and stuff that you can drop and its out of the inventory. Also i want it that you can eat food and drink liquid. I tried once but it didn't work, heres my code:(Also slot1Item-slot8Item are strings and so is weapon 2 and 1, and this is not the full script)
public void InventoryGUI(){
if(isInventoryUp){
inventoryRect = GUI.Window(0, inventoryRect, InventoryWindow, "Gear");
}
}
void InventoryWindow(int windowID) {
if(GUI.Button(new Rect(10,30,200,60),"Weapon 1: " + Weapon1)){
GearWeaponDesc = Weapon1Desc;
}
if(GUI.Button(new Rect(10,100,200,60),"Weapon 2: " + Weapon2)){
GearWeaponDesc = Weapon2Desc;
}
if(GUI.Button(new Rect(220,30,60,60),"" + slot1Item)){
SelectedItem = slot1Item;
SelectedItemSlot = "1";
DisplayEatDrop = true;
}
if(GUI.Button(new Rect(290,30,60,60),"" + slot2Item)){
SelectedItem = slot2Item;
SelectedItemSlot = "2";
DisplayEatDrop = true;
}
if(GUI.Button(new Rect(360,30,60,60),"" + slot3Item)){
SelectedItem = slot3Item;
SelectedItemSlot = "3";
DisplayEatDrop = true;
}
if(GUI.Button(new Rect(430,30,60,60),"" + slot4Item)){
SelectedItem = slot4Item;
SelectedItemSlot = "4";
DisplayEatDrop = true;
}
if(GUI.Button(new Rect(220,100,60,60),"" + slot5Item)){
SelectedItem = slot5Item;
SelectedItemSlot = "5";
DisplayEatDrop = true;
}
if(GUI.Button(new Rect(290,100,60,60),"" + slot6Item)){
SelectedItem = slot6Item;
SelectedItemSlot = "6";
DisplayEatDrop = true;
}
if(GUI.Button(new Rect(360,100,60,60),"" + slot7Item)){
SelectedItem = slot7Item;
SelectedItemSlot = "7";
DisplayEatDrop = true;
}
if(GUI.Button(new Rect(430,100,60,60),"" + slot8Item)){
SelectedItem = slot8Item;
SelectedItemSlot = "8";
DisplayEatDrop = true;
}
GUI.Box(new Rect(220,170,120,120),"Binoculars");
GUI.Box(new Rect(370,170,120,120),"Head Gear");
GUI.Label(new Rect(10,170,200,100),GearWeaponDesc);
if(DisplayEatDrop){
if(SelectedItem != ""){
if(GUI.Button(new Rect(220,300,270,30),"Use")){}
if(GUI.Button(new Rect(220,340,270,30),"Drop")){
SelectedItem = "";
PlayerPrefs.SetString(SelectedItemSlot,SelectedItem);
}
}
}
GUI.DragWindow();
}
Answer by iwaldrop · Apr 10, 2013 at 02:06 AM
You haven't really asked much of a question aside from how do you drop and use things from an inventory.
You should have a List of inventory items (a List, not an array). When you want to drop an item, simply remove it from the List and spawn it's Prefab by your player to drop it on the ground. In order to consume it, you remove it from your array and apply it's effects to your player. Awesomely easy!
I would like it with strings to save it easier here is a better explanation the drop button does not drop and item like it should. I could easily add consume but i need the drop in order to work for the making of consume.
I don't see your code for dropping anything, and if you haven't implemented it yet I gave you a workable description of both operations in my answer. Post some code with a specific question and we'll work it out.
Your answer
Follow this Question
Related Questions
FPS picking up items 2 Answers
c# Weapon Pickup Script 1 Answer
FPS Weapon inventory script help 0 Answers
ufps package freezes when adding inventory system 0 Answers
Fairly Simple FPS Inventory HELP? 1 Answer