Skip to content

Instantly share code, notes, and snippets.

@Avonexile
Created November 13, 2018 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Avonexile/3dc563b946ab1d9d8a8761ded3fbd40f to your computer and use it in GitHub Desktop.
Save Avonexile/3dc563b946ab1d9d8a8761ded3fbd40f to your computer and use it in GitHub Desktop.
The crafting manager shows if the crafting slots have items in them and what happens
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace CraftingSystemRework
{
public class CraftManager : MonoBehaviour {
public int item1ID;
public int item2ID;
public bool slot1;
public bool slot2;
public bool ready;
public Button craftButton;
public Image resultImage;
public CraftingRecipes craftingRecipes;
public CraftResult craftResult;
public Inventory inventory;
GameObject item1, item2;
public int itemResultID;
void Awake ()
{
craftResult = GameObject.Find("Item Result").GetComponent<CraftResult>();
craftingRecipes = GetComponent<CraftingRecipes>();
inventory = GameObject.Find("_Inventory").GetComponent<Inventory>();
}
//updates the craft button
void FixedUpdate ()
{
if(!ready)
{
craftButton.interactable = false;
}
else
{
craftButton.interactable = true;
}
}
//receives info about what is in the crafting slots
public void ReceiveItemsInfo (int slotID, GameObject item)
{
if(slotID == 0)
{
if(item == null)
{
slot1 = false;
}
else
{
slot1 = true;
item1 = item.GetComponent<Item>().gameObject;
item1ID = item.GetComponent<Item>().id;
}
}
if(slotID == 1)
{
if(item == null)
{
slot2 = false;
}
else
{
slot2 = true;
item2 = item.GetComponent<Item>().gameObject;
item2ID = item.GetComponent<Item>().id;
}
}
if(slot1 & slot2)
{
craftingRecipes.CheckRecipes(item1ID, item2ID);
}
else
{
craftingRecipes.BrokeRecipe();
}
}
//button craft calls this and this makes it look like something was crafted
public void Craft ()
{
GiveItem(item2);//Reuses this item as the item you receive
Destroy(item1);
craftingRecipes.BrokeRecipe();
}
//receives the result id so you actually get the item you wanted
public void ReceiveResultInfo (int id)
{
itemResultID = id;
}
//calls inventory to check for a place in your inventory
void GiveItem (GameObject item)
{
inventory.CheckForSpace(item, itemResultID);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment