Skip to content

Instantly share code, notes, and snippets.

@Avonexile
Last active November 13, 2018 16:26
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/6abaf25da3283907a2d92dddd2c9062c to your computer and use it in GitHub Desktop.
Save Avonexile/6abaf25da3283907a2d92dddd2c9062c to your computer and use it in GitHub Desktop.
The crafting recipes and the recipe class
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace CraftingSystemRework
{
[System.Serializable]
public class Recipes
{
//this is so i can make a list of crafting recipes
public int item1, item2, resultID;
}
public class CraftingRecipes : MonoBehaviour {
public List<Recipes> recipes = new List<Recipes>();
public int itemResultID;
public CraftManager craftManager;
public CraftResult craftResult;
bool recipeFound;
//sets up some references
void Awake ()
{
craftResult = GameObject.Find("Item Result").GetComponent<CraftResult>();
craftManager = GetComponent<CraftManager>();
}
//checks the list of recipes if there is a recipe
public void CheckRecipes (int itemID1, int itemID2)
{
for (int i = 0; i < recipes.Count; i++)
{
if(itemID1 == recipes[i].item1 && itemID2 == recipes[i].item2 || itemID2 == recipes[i].item1 && itemID1 == recipes[i].item2)
{
recipeFound = true;
itemResultID = recipes[i].resultID;
print("Succes!" + itemResultID);
craftManager.ReceiveResultInfo(itemResultID);
craftResult.ShowResult(itemResultID);
}
if(i == recipes.Count - 1 && !recipeFound)
{
craftManager.ready = false;
}
}
}
//this makes the result dissapear and turn the craft button off so you cant interact with it
public void BrokeRecipe ()
{
recipeFound = false;
craftResult.HideResult();
craftManager.ready = false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment