Skip to main content
Tweeted twitter.com/StackGameDev/status/1571423793532358657
Post Reopened by Vaillancourt
Minor formatting.
Source Link
Vaillancourt
  • 16.3k
  • 17
  • 55
  • 61

So I'm trying to make an crafting system in Unity. The problem is, I don't really know how to finish it. I already have the inventory system, (which I made using this tutorial: https://youtu.beHOW TO MAKE AN INVENTORY WITH UNITY & C# - BEGINNER TUTORIAL - 1/DLAIYSMYy2g2).

Anyways, theThe problems I'm having are:

-I don't know how to destroy the materials used for crafting an item

-And I don't really know how to check if these materials are in the inventory (or basically the scene)

  • I don't know how to destroy the materials used for crafting an item
  • And I don't really know how to check if these materials are in the inventory (or basically the scene)

Here's the code:

`

private Inventory inventory;

public GameObject CraftedItem;
public GameObject[] ReqMats; //This array is for requied materials

private void Start()
{
    inventory = GameObject.FindGameObjectWithTag("Player").GetComponent<Inventory>();
}

public void Craft()
{
    for (int i = 0; i < inventory.slots.Length; i++)
    {
        if (inventory.isFull[i] == false)
        {
            if (check if ReqMats are in inventory here)
            {
                inventory.isFull[i] = true;
                //Destroy ReqMats here
                Instantiate(CraftedItem, inventory.slots[i].transform, false);
                break;
            }
        }
    }
}

`

I also need to say that the items and itemsButtons are prefabs, and so I put needed "materials" (which are few item buttons) in the ReqMats, so I can't just use the Destroy() method cause I don't want to delete the original prefab, just the button of it's copy.

Any help will be appreciated :D

So I'm trying to make an crafting system in Unity. The problem is, I don't really know how to finish it. I already have the inventory system, (which I made using this tutorial: https://youtu.be/DLAIYSMYy2g)

Anyways, the problems I'm having are:

-I don't know how to destroy the materials used for crafting an item

-And I don't really know how to check if these materials are in the inventory (or basically the scene)

Here's the code:

`

private Inventory inventory;

public GameObject CraftedItem;
public GameObject[] ReqMats; //This array is for requied materials

private void Start()
{
    inventory = GameObject.FindGameObjectWithTag("Player").GetComponent<Inventory>();
}

public void Craft()
{
    for (int i = 0; i < inventory.slots.Length; i++)
    {
        if (inventory.isFull[i] == false)
        {
            if (check if ReqMats are in inventory here)
            {
                inventory.isFull[i] = true;
                //Destroy ReqMats here
                Instantiate(CraftedItem, inventory.slots[i].transform, false);
                break;
            }
        }
    }
}

`

I also need to say that the items and itemsButtons are prefabs, and so I put needed "materials" (which are few item buttons) in the ReqMats, so I can't just use the Destroy() method cause I don't want to delete the original prefab, just the button of it's copy.

Any help will be appreciated :D

I'm trying to make an crafting system in Unity. The problem is, I don't really know how to finish it. I already have the inventory system, (which I made using this tutorial: HOW TO MAKE AN INVENTORY WITH UNITY & C# - BEGINNER TUTORIAL - 1/2).

The problems I'm having are:

  • I don't know how to destroy the materials used for crafting an item
  • And I don't really know how to check if these materials are in the inventory (or basically the scene)

Here's the code:

private Inventory inventory;

public GameObject CraftedItem;
public GameObject[] ReqMats; //This array is for requied materials

private void Start()
{
    inventory = GameObject.FindGameObjectWithTag("Player").GetComponent<Inventory>();
}

public void Craft()
{
    for (int i = 0; i < inventory.slots.Length; i++)
    {
        if (inventory.isFull[i] == false)
        {
            if (check if ReqMats are in inventory here)
            {
                inventory.isFull[i] = true;
                //Destroy ReqMats here
                Instantiate(CraftedItem, inventory.slots[i].transform, false);
                break;
            }
        }
    }
}

I also need to say that the items and itemsButtons are prefabs, and so I put needed "materials" (which are few item buttons) in the ReqMats, so I can't just use the Destroy() method cause I don't want to delete the original prefab, just the button of it's copy.

Any help will be appreciated :D

Post Closed as "Not suitable for this site" by Vaillancourt
Source Link
Makaron
  • 35
  • 1
  • 7

How can I make a crafting system in Unity?

So I'm trying to make an crafting system in Unity. The problem is, I don't really know how to finish it. I already have the inventory system, (which I made using this tutorial: https://youtu.be/DLAIYSMYy2g)

Anyways, the problems I'm having are:

-I don't know how to destroy the materials used for crafting an item

-And I don't really know how to check if these materials are in the inventory (or basically the scene)

Here's the code:

`

private Inventory inventory;

public GameObject CraftedItem;
public GameObject[] ReqMats; //This array is for requied materials

private void Start()
{
    inventory = GameObject.FindGameObjectWithTag("Player").GetComponent<Inventory>();
}

public void Craft()
{
    for (int i = 0; i < inventory.slots.Length; i++)
    {
        if (inventory.isFull[i] == false)
        {
            if (check if ReqMats are in inventory here)
            {
                inventory.isFull[i] = true;
                //Destroy ReqMats here
                Instantiate(CraftedItem, inventory.slots[i].transform, false);
                break;
            }
        }
    }
}

`

I also need to say that the items and itemsButtons are prefabs, and so I put needed "materials" (which are few item buttons) in the ReqMats, so I can't just use the Destroy() method cause I don't want to delete the original prefab, just the button of it's copy.

Any help will be appreciated :D