Advertisement
Internetslive

Untitled

Feb 11th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.50 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class recipe : MonoBehaviour
  5. {
  6.  
  7. public int itemCountWorth;//set value worth
  8. public int itemCount;//item counter total set public for debugging
  9. public int MaxItemCount;//set value in editor to determine recipe requirements
  10. public bool inBox;
  11. public string RecipeItemTagName1;//first item needed for recipe
  12.  
  13. //TODO PLACE IN OWN COIN RECIPE SCRIPT
  14. public bool forCoins;
  15.  
  16. public string RecipeResultName;
  17.  
  18. void coinValUpdater(Collider2D item)//call this when coin update
  19. {
  20. item.transform.parent = transform;
  21. item.GetComponent<Rigidbody2D>().isKinematic = true;
  22. GameObject.FindWithTag("Player").GetComponent<coinPickUp>().screenCoinUpdate();//run screenCoinUpdate() which is located in coinPickUp.cs
  23. Destroy(item.gameObject);
  24.  
  25. }
  26. //TODO
  27.  
  28. void destroyChilds(Collider2D item)//destroy childs in collider2d
  29. {
  30. foreach (Transform child in transform)
  31. {
  32. GameObject.Destroy(child.gameObject);
  33. }
  34.  
  35. }
  36.  
  37. void doRecipeResult()
  38. {
  39.  
  40. GameObject.FindWithTag("House").transform.position = new Vector3(0, 0, 0);
  41. }
  42.  
  43. void OnTriggerStay2D(Collider2D item)
  44. {
  45.  
  46. if (item.gameObject.tag == RecipeItemTagName1 && item.gameObject.layer == 8)
  47. {
  48. item.gameObject.layer = LayerMask.NameToLayer("recipeReady");//set item to layer called recipeReady
  49. if (item.gameObject.layer == 11 && forCoins == false)
  50. {//once in layer and this is true exec this line recipeReady(11))
  51. item.transform.parent = transform;//set object to its own parent
  52. item.GetComponent<Rigidbody2D>().isKinematic = true;//enable kinematic so it does not move
  53. itemCount = itemCount + itemCountWorth;//add up values to determine recipe status
  54. inBox = true;
  55. }
  56.  
  57.  
  58. //TODO PLACE IN OWN COIN RECIPE SCRIPT
  59. if (item.gameObject.layer == 11 && forCoins == true)
  60. {//only runs if this is for coins
  61. coinValUpdater(item);
  62. }
  63. //TODO
  64.  
  65. if (itemCount == MaxItemCount && forCoins == false)
  66. {//code if not for coins todo, setup system
  67. destroyChilds(item);
  68. doRecipeResult();
  69. }
  70. }
  71. }
  72.  
  73.  
  74. void OnTriggerExit2D(Collider2D item)
  75. {
  76. //Debug.Log ("Log exit:" + item.gameObject.tag);
  77.  
  78. if (item.gameObject.tag == "Crate" && inBox == true)
  79. {
  80. //item.gameObject.layer = LayerMask.NameToLayer ("pickedUp");
  81. inBox = false;
  82. itemCount = itemCount - itemCountWorth;
  83. }
  84. }
  85.  
  86.  
  87. }
  88. using UnityEngine;
  89. using System.Collections;
  90.  
  91. public class recipe : MonoBehaviour
  92. {
  93.  
  94. public int itemCountWorth;//set value worth
  95. public int itemCount;//item counter total set public for debugging
  96. public int MaxItemCount;//set value in editor to determine recipe requirements
  97. public bool inBox;
  98. public string RecipeItemTagName1;//first item needed for recipe
  99.  
  100. //TODO PLACE IN OWN COIN RECIPE SCRIPT
  101. public bool forCoins;
  102.  
  103. public string RecipeResultName;
  104.  
  105. void coinValUpdater(Collider2D item)//call this when coin update
  106. {
  107. item.transform.parent = transform;
  108. item.GetComponent<Rigidbody2D>().isKinematic = true;
  109. GameObject.FindWithTag("Player").GetComponent<coinPickUp>().screenCoinUpdate();//run screenCoinUpdate() which is located in coinPickUp.cs
  110. Destroy(item.gameObject);
  111.  
  112. }
  113. //TODO
  114.  
  115. void destroyChilds(Collider2D item)//destroy childs in collider2d
  116. {
  117. foreach (Transform child in transform)
  118. {
  119. GameObject.Destroy(child.gameObject);
  120. }
  121.  
  122. }
  123.  
  124. void doRecipeResult()
  125. {
  126.  
  127. GameObject.FindWithTag("House").transform.position = new Vector3(0, 0, 0);
  128. }
  129.  
  130. void OnTriggerStay2D(Collider2D item)
  131. {
  132.  
  133. if (item.gameObject.tag == RecipeItemTagName1 && item.gameObject.layer == 8)
  134. {
  135. item.gameObject.layer = LayerMask.NameToLayer("recipeReady");//set item to layer called recipeReady
  136. if (item.gameObject.layer == 11 && forCoins == false)
  137. {//once in layer and this is true exec this line recipeReady(11))
  138. item.transform.parent = transform;//set object to its own parent
  139. item.GetComponent<Rigidbody2D>().isKinematic = true;//enable kinematic so it does not move
  140. itemCount = itemCount + itemCountWorth;//add up values to determine recipe status
  141. inBox = true;
  142. }
  143.  
  144.  
  145. //TODO PLACE IN OWN COIN RECIPE SCRIPT
  146. if (item.gameObject.layer == 11 && forCoins == true)
  147. {//only runs if this is for coins
  148. coinValUpdater(item);
  149. }
  150. //TODO
  151.  
  152. if (itemCount == MaxItemCount && forCoins == false)
  153. {//code if not for coins todo, setup system
  154. destroyChilds(item);
  155. doRecipeResult();
  156. }
  157. }
  158. }
  159.  
  160.  
  161. void OnTriggerExit2D(Collider2D item)
  162. {
  163. //Debug.Log ("Log exit:" + item.gameObject.tag);
  164.  
  165. if (item.gameObject.tag == "Crate" && inBox == true)
  166. {
  167. //item.gameObject.layer = LayerMask.NameToLayer ("pickedUp");
  168. inBox = false;
  169. itemCount = itemCount - itemCountWorth;
  170. }
  171. }
  172.  
  173.  
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement