- Home /
Simple inventory
I try to implement simple inventory system. And stuck on pickup functionality. Example of taking the Potion:
Collide with Potion object.
Add it to the Inventory
List item Remove it from the scene
How to implement this? At the step 2, i must take reference to asset or prefab? Inventory must store a GameObject's ?
Any idea, resource or tutorial will be helpfull. *I need to implement exactly this algorithm. Thanks.
Are your items or inventory created with a class? You need to give us a little more information about the content of your potion and inventory scripts.
You should not have posted this comment as an answer. You just asked him a question about his question. Now the question has been taken off of the unanswered question's list, which will lower his/her chances of having someone answer it.
Please click the more button under your answer and choose convert to comment. $$anonymous$$aybe that makes it an unanswered again.
It is a comment. Notice that it is directly under the original post and there are 0 answers.
Notice that I just moved it as a comment since it was posted as an answer
Thanks fafase. I don't have the authority to do so yet. haha
Answer by Pemu · Dec 19, 2013 at 07:39 PM
So...
You must create a Potion.
Create for example 3 slots Inventory.
When you collide with Potion, his script must SendMessage to 3 slots. When 1 is free, potion comes to 1, when 2 is free, potion comes to 2, etc...
Script Potion must have information:
var ob : GameObject; var ob2 : GameObject; var ob3 : GameObject; function OnTriggerEnter(other : Collider){ if(other.tag=="Player"){ ob.SendMessage("Slot"); ob2.SendMessage("Slot"); //Call function "Slot" (he place your potion to inventory) ob3.SendMessage("Slot"); Destroy(gameObject); //Destroy Potion } }
So - you already know how to do it?
Sorry for my English ;d