Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.96 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Metal : MonoBehaviour
  6. {
  7. public GameObject sound;
  8. public GameObject black;
  9. public GameObject antiSound;
  10.  
  11. public GameObject na;
  12. public GameObject parts;
  13. public GameObject bags;
  14. public GameObject seat;
  15. public GameObject Wheel;
  16. public GameObject shoes;
  17.  
  18. public bool onBike;
  19. public bool canDiveBike;
  20. public float bikeStartTime = 10f;
  21. public float bikeTimer = 0;
  22. public int item;
  23.  
  24. void Update()
  25. {
  26. if (onBike)
  27. {
  28. if (Input.GetKeyDown(KeyCode.E))
  29. {
  30. digBike();
  31. }
  32. }
  33.  
  34. if (onBike && !canDiveBike)
  35. {
  36. antiSound.SetActive(true);
  37. }
  38.  
  39. if (canDiveBike == false)
  40. {
  41. bikeTimer -= Time.deltaTime;
  42. Debug.Log(bikeTimer);
  43. if (bikeTimer <= 0)
  44. {
  45. canDiveBike = true;
  46. return;
  47. }
  48. sound.SetActive(false);
  49. }
  50. }
  51.  
  52. void Start()
  53. {
  54. bikeTimer = bikeStartTime;
  55. canDiveBike = true;
  56. onBike = false;
  57. }
  58.  
  59. void OnTriggerEnter(Collider other)
  60. {
  61. if (other.gameObject.tag == "stuffBike")
  62. {
  63. onBike = true;
  64. if (canDiveBike == true)
  65. {
  66. sound.SetActive(true);
  67. antiSound.SetActive(false);
  68. }
  69. else
  70. {
  71. sound.SetActive(false);
  72. }
  73. }
  74. }
  75.  
  76. void OnTriggerStay(Collider other)
  77. {
  78. if (other.gameObject.tag == "stuffBike") {
  79.  
  80. if (canDiveBike == true)
  81. {
  82. sound.SetActive(true);
  83. antiSound.SetActive(false);
  84. }
  85. }
  86. }
  87.  
  88. void OnTriggerExit(Collider other)
  89. {
  90. if (other.gameObject.tag == "stuffBike")
  91. {
  92. StopAllCoroutines();
  93. antiSound.SetActive(false);
  94. sound.SetActive(false);
  95. black.SetActive(false);
  96. na.SetActive(false);
  97. parts.SetActive(false);
  98. bags.SetActive(false);
  99. seat.SetActive(false);
  100. Wheel.SetActive(false);
  101. shoes.SetActive(false);
  102. onBike = false;
  103. }
  104. }
  105.  
  106. void digBike()
  107. {
  108. StartCoroutine(DigItBike());
  109. }
  110.  
  111. IEnumerator DigItBike()
  112. {
  113. if (canDiveBike == true) {
  114. float time = 0;
  115. float randy = Random.Range(2.5f, 17.5f);
  116. while (time < randy)
  117. {
  118. black.SetActive(true);
  119. time += Time.deltaTime;
  120. yield return null;
  121. }
  122.  
  123. if (randy < 5) {
  124. Debug.Log("Nothing");
  125. item = 0;
  126. PlayerPrefs.SetInt("points", PlayerPrefs.GetInt("points") + 0);
  127. }
  128.  
  129. else if (randy < 7.5)
  130. {
  131. Debug.Log("Just some parts");
  132. PlayerPrefs.SetInt("parts", PlayerPrefs.GetInt("parts") + 1);
  133. item = 1;
  134. PlayerPrefs.SetInt("points", PlayerPrefs.GetInt("points") + 2);
  135. }
  136. else if (randy < 10)
  137. {
  138. Debug.Log("saddle bags");
  139. PlayerPrefs.SetInt("bags", PlayerPrefs.GetInt("bags") + 1);
  140. item = 2;
  141. PlayerPrefs.SetInt("points", PlayerPrefs.GetInt("points") + 5);
  142. }
  143. else if (randy < 12.5)
  144. {
  145. Debug.Log("Bike seat");
  146. PlayerPrefs.SetInt("seat", PlayerPrefs.GetInt("seat") + 1);
  147. item = 3;
  148. PlayerPrefs.SetInt("points", PlayerPrefs.GetInt("points") + 5);
  149. }
  150. else if (randy < 15)
  151. {
  152. Debug.Log("A Wheel");
  153. PlayerPrefs.SetInt("Wheel", PlayerPrefs.GetInt("Wheel") + 1);
  154. item = 4;
  155. PlayerPrefs.SetInt("points", PlayerPrefs.GetInt("points") + 5);
  156. }
  157. else if (randy < 17.5)
  158. {
  159. Debug.Log("Biking Shoes!");
  160. PlayerPrefs.SetInt("Shoes", PlayerPrefs.GetInt("Shoes") + 1);
  161. item = 5;
  162. PlayerPrefs.SetInt("points", PlayerPrefs.GetInt("points") + 5);
  163. }
  164. bikeTimer = bikeStartTime;
  165. canDiveBike = false;
  166. black.SetActive(false);
  167. StopAllCoroutines();
  168. StartCoroutine(bikeShowDig());
  169. }else{
  170. StopAllCoroutines();
  171. }
  172. }
  173.  
  174. IEnumerator bikeShowDig()
  175. {
  176. float time1 = 0;
  177. float randy1 = 2.0f;
  178. while (time1 < randy1)
  179. {
  180. if (item == 0)
  181. {
  182. na.SetActive(true);
  183. parts.SetActive(false);
  184. bags.SetActive(false);
  185. seat.SetActive(false);
  186. Wheel.SetActive(false);
  187. shoes.SetActive(false);
  188. antiSound.SetActive(false);
  189. }
  190. else if (item == 1)
  191. {
  192. na.SetActive(false);
  193. parts.SetActive(true);
  194. bags.SetActive(false);
  195. seat.SetActive(false);
  196. Wheel.SetActive(false);
  197. shoes.SetActive(false);
  198. antiSound.SetActive(false);
  199. }
  200. else if (item == 2)
  201. {
  202. na.SetActive(false);
  203. parts.SetActive(false);
  204. bags.SetActive(true);
  205. seat.SetActive(false);
  206. Wheel.SetActive(false);
  207. shoes.SetActive(false);
  208. antiSound.SetActive(false);
  209. }
  210. else if (item == 3)
  211. {
  212. na.SetActive(false);
  213. parts.SetActive(false);
  214. bags.SetActive(false);
  215. seat.SetActive(true);
  216. Wheel.SetActive(false);
  217. shoes.SetActive(false);
  218. antiSound.SetActive(false);
  219. }
  220. else if (item == 4)
  221. {
  222. na.SetActive(false);
  223. parts.SetActive(false);
  224. bags.SetActive(false);
  225. seat.SetActive(false);
  226. Wheel.SetActive(true);
  227. shoes.SetActive(false);
  228. antiSound.SetActive(false);
  229. }
  230. else if (item == 5)
  231. {
  232. na.SetActive(false);
  233. parts.SetActive(false);
  234. bags.SetActive(false);
  235. seat.SetActive(false);
  236. Wheel.SetActive(false);
  237. shoes.SetActive(true);
  238. antiSound.SetActive(false);
  239. }
  240. time1 += Time.deltaTime;
  241. yield return null;
  242. }
  243. na.SetActive(false);
  244. parts.SetActive(false);
  245. bags.SetActive(false);
  246. seat.SetActive(false);
  247. Wheel.SetActive(false);
  248. shoes.SetActive(false);
  249. antiSound.SetActive(true);
  250. }
  251. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement