Question by
Prmetheus · Dec 26, 2017 at 03:16 PM ·
c#unity 5programminginventory
Delete item in inventory
So i collect my inventory data with
ivent.inventory.Add (database.items [WeaponTypeID]);
which just works fine function gets called by a trigger.
Now, inside my inventory script, i display the inventory storage with:
void OnGUI(){
for (int i = 0; i < inventory.Count; i++) { GUI.Label(new Rect(10, i * 20, 200, 50), inventory[i].Item); } }
which also works great.
To remove an item, i tried the following method, but i don't think this is the best solution for it. Any ideas how to improve this without going to complex here?
void Update () {
var dropsItem = Input.GetKeyDown (KeyCode.F);
foreach (var item in inventory) {
if (dropsItem) {
inventory.Remove (item);
}
}
Thanks in advance!
Comment
Your answer
Follow this Question
Related Questions
Why is my script not working 1 Answer
Horizontal Input showing random decimal when it should be 0 0 Answers
Need help with c# 1 Answer
Lerping Camera Between Two Points 0 Answers
Google play services won't start. 0 Answers