void ShowRecipes() { GameObject RecipesListed = Instantiate(RecipePopup, new Vector3(), Quaternion.identity); // For 28 recipes, two columns of 14 GameObject column1 = RecipesListed.transform.GetChild(1).gameObject; GameObject column2 = RecipesListed.transform.GetChild(2).gameObject; // Marks complete as 2, white, 1 for beside a complete but not itself complete in red List <int> col1 = new List <int>(); List <int> col2 = new List <int>(); for (int i = 0; i < column1.transform.childCount; i++) { if (IC.CheckRecipe(i)) { col1.Add(2); } else if ((i - 1 >= 0 && IC.CheckRecipe(i - 1)) || (i + 1 < column1.transform.childCount && IC.CheckRecipe(i + 1))) { col1.Add(1); } else { col1.Add(0); } } for (int i = 0; i < column2.transform.childCount; i++) { int j = i + 14; if (IC.CheckRecipe(j)) { col2.Add(2); } else if ((i - 1 >= 0 && IC.CheckRecipe(j - 1)) || (i + 1 < column2.transform.childCount && IC.CheckRecipe(j + 1))) { col2.Add(1); } else { col2.Add(0); } } // Go through col1 and col2 for (int i = 0; i < col1.Count; i++) { if (col1 [i] == 2) { // White column1.transform.GetChild(i).GetComponent <TextMesh> ().text = i + " " + RDC.getRecipeName(i); } else if (col1 [i] == 1) { column1.transform.GetChild(i).GetComponent <TextMesh> ().color = new Color(1, 0, 0); // red column1.transform.GetChild(i).GetComponent <TextMesh> ().text = i + " " + RDC.getRecipeName(i); } else { column1.transform.GetChild(i).GetComponent <TextMesh> ().text = i + " " + "???"; } } for (int i = 0; i < col2.Count; i++) { if (col2 [i] == 2) { // White int j = i + 14; column2.transform.GetChild(i).GetComponent <TextMesh> ().text = j + " " + RDC.getRecipeName(i); } else if (col2 [i] == 1) { int j = i + 14; column2.transform.GetChild(i).GetComponent <TextMesh> ().color = new Color(1, 0, 0); // red column2.transform.GetChild(i).GetComponent <TextMesh> ().text = j + " " + RDC.getRecipeName(i); } else { int j = i + 14; column2.transform.GetChild(i).GetComponent <TextMesh> ().text = j + " " + "???"; } } }
void Merge() { // call RDC to check the slots int i1 = SlotOne.transform.GetChild(1).GetComponent <LabPageItemSlotClick> ().getItemID(); int i2 = SlotTwo.transform.GetChild(1).GetComponent <LabPageItemSlotClick> ().getItemID(); Debug.Log("got " + i1 + " " + i2); // Checks if it is a valid recipe int check = RDC.CheckRecipes(i1, i2); if (check != -1) { int id = check; // Checks if the recipe is already made if (!IC.CheckNewRecipe(id)) { // Not a new recipe Debug.Log("Already made recipe"); GameObject obj = Instantiate(Popup, new Vector3(), Quaternion.identity); // Popup.transform.GetChild (1).GetComponent<SpriteRenderer> ().sprite = RDC.getSprite (check); // Description obj.transform.GetChild(0).GetComponent <TextMesh> ().text = "ERROR"; obj.transform.GetChild(2).GetComponent <TextMesh> ().text = "Recipe already found"; obj.transform.GetChild(3).GetComponent <TextMesh> ().text = "You got 0 coins"; return; } else { Debug.Log("valid recipe"); // call recipe done in inventory IC.AddToRecipes(id); // valid recipe, create popup textbox of recipe GameObject obj = Instantiate(Popup, new Vector3(), Quaternion.identity); // Update with sprite obj.transform.GetChild(1).GetComponent <SpriteRenderer> ().sprite = RDC.getSprite(id); // Description obj.transform.GetChild(2).GetComponent <TextMesh> ().text = RDC.getRecipeName(id); // Currency int gain = Random.Range(75, 125); obj.transform.GetChild(3).GetComponent <TextMesh> ().text = "You got " + gain.ToString() + " coins"; // Add the currency amount IC.IncreaseCurrency(gain); // Update the Currency counter in corner SC.UpdateText(); } } else { // invalid recipe // valid recipe, create popup textbox of recipe GameObject obj = Instantiate(Popup, new Vector3(), Quaternion.identity); // Description // Title obj.transform.GetChild(0).GetComponent <TextMesh> ().text = "ERROR"; // Description obj.transform.GetChild(2).GetComponent <TextMesh> ().text = "Failed recipe"; // obj.transform.GetChild(3).GetComponent <TextMesh> ().text = "RIP"; Debug.Log("invalid recipe"); } // decrement the amounts in the inventory IC.RemoveFromInventory(i1); IC.RemoveFromInventory(i2); // Update the text on the LabInventory LC.UpdateCountText(i1); LC.UpdateCountText(i2); // Need to reset SlotOne and SlotTwo itemID SlotOne.transform.GetChild(1).GetComponent <LabPageItemSlotClick> ().ResetItemID(); SlotTwo.transform.GetChild(1).GetComponent <LabPageItemSlotClick> ().ResetItemID(); // Reset the sprites SlotOne.transform.GetChild(1).GetComponent <Image>().sprite = Locked; SlotTwo.transform.GetChild(1).GetComponent <Image>().sprite = Locked; // Reset the names SlotOne.transform.GetChild(0).GetComponent <Text>().text = "Locked"; SlotTwo.transform.GetChild(0).GetComponent <Text>().text = "Locked"; }