You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
2.2 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using TMPro;
  6. using System;
  7. public class Recipe : MonoBehaviour {
  8. public Player localPlayer;
  9. int PlayerCount;
  10. public Vegetable[] Veggies;
  11. public Frame[] Frames;
  12. public int[] Qtys;
  13. public int[] heldQtys;
  14. public GameObject RecipeCanvas;
  15. public Image Inventory;
  16. // Use this for initialization
  17. void Start () {
  18. for (int i = 0; i < PlayerCount; i++)
  19. {
  20. int rand = UnityEngine.Random.Range(0, Qtys.Length - 1);
  21. Qtys[rand] += 1;
  22. }
  23. for (int i = 0; i < 4; i++) //Set the recipe UI
  24. {
  25. Frames[i].VegetableSpot.sprite = Veggies[i].Image;
  26. Frames[i].Qty.text = Qtys[i] + "";
  27. }
  28. }
  29. //Button calls
  30. public void OpenRecipe()
  31. {
  32. RecipeCanvas.SetActive(true);
  33. }
  34. public void CloseRecipe()
  35. {
  36. RecipeCanvas.SetActive(false);
  37. }
  38. //Veggie interactions
  39. public void pickupItem(Vegetable newVeggie)
  40. {
  41. localPlayer.heldVeggie = newVeggie;
  42. Inventory.gameObject.SetActive(true);
  43. Inventory.sprite = newVeggie.Image;
  44. }
  45. public void dropItem()
  46. {
  47. localPlayer.heldVeggie = null;
  48. Inventory.gameObject.SetActive(false);
  49. }
  50. public void friendlyPickup(string VeggieName, int change)
  51. {
  52. StartCoroutine(ItemLookup(VeggieName, change));
  53. }
  54. IEnumerator ItemLookup(string VeggieName, int change)
  55. {
  56. for (int i = 0; i < Veggies.Length; i++)
  57. {
  58. if(Veggies[i].Name == VeggieName)
  59. {
  60. heldQtys[i] += change;
  61. }
  62. }
  63. yield return new WaitForEndOfFrame();
  64. }
  65. public bool CheckVictory()
  66. {
  67. bool winning = true;
  68. for (int i = 0; i < Veggies.Length; i++)
  69. {
  70. if (Qtys[i] != heldQtys[i])
  71. {
  72. winning = false;
  73. }
  74. }
  75. return winning;
  76. }
  77. }
  78. [Serializable]
  79. public class Vegetable
  80. {
  81. public string Name;
  82. public Sprite Image;
  83. }
  84. [Serializable]
  85. public class Frame
  86. {
  87. public Image VegetableSpot;
  88. public TextMeshProUGUI Qty;
  89. }