Hi guys, please tell me or give a link to the lesson.
Hi, please tell me how to implement my ideas. I have three items and three drawers. Such an idea, I pick up one of the three items which will fall first and put it in one of the three boxes that will be empty. Check the empty box or not, I think you can do so. if( Box.transform.childCount == null )
Answer by KevRev · Apr 18, 2019 at 12:20 PM
It depends on a lot variables that are missing from the question, such as what type of objects they are, are they lists? GameObjects? So you want objects in the drawers, or just named references?
Simplest way would be just a string ref.
Public List<string> drawers new List<string>();
Start ()
{
// Initialise empty drawers
drawers.Add("empty");
drawers.Add("empty");
drawers.Add("empty");
}
public void AddToDrawer(string item, int drawer)
{
if (drawers[drawer]=="empty")
{
drawers.drawer=item;
Debug.log ("Added item to drawer");
}
else
{
Debug.log ("Item already contains "+drawers[drawer]);
}
}
public void RemoveFromDrawer(string item, int drawer)
{
if (drawers[drawer]==item)
{
drawers.drawer="empty";
Debug.log ("Removed item from drawer");
}
else
{
Debug.log ("cant remove item from drawer");
}
}
// To call the methods
AddItemToDrawer("Pencil",2);
RemoveItemFromDrawer("Carrot",3);
You'll want to modify this logic to suit your needs.
Answer by 3DRusik · Apr 18, 2019 at 12:35 PM
More thanks, this is what I was looking for.
Glad to hear it :) could you $$anonymous$$ark it as the answer please? New user here trying to build my rep ;)