Guest User

Untitled

a guest
Feb 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.87 KB | None | 0 0
  1. using System.Collections;
  2. using UnityEngine.UI;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5.  
  6. public class TextController : MonoBehaviour
  7. {
  8.  
  9. public Text currentText;
  10.  
  11. private enum States { start, h_1, h_2, h_3, c_1, c_2, c_22, c_23, c_3, c_4, r_1, r_12, r_2, r_22, r_3, ld, w, bh, e, r, end };
  12. private States currentState;
  13. private States previousState;
  14. private States nextState;
  15. private string rightKey;
  16.  
  17. public GameObject neonLogo;
  18. public GameObject stormSound;
  19. public GameObject thunderSound;
  20.  
  21. public GameObject entranceDoorSound;
  22. public GameObject doorChimeSound;
  23.  
  24.  
  25. // Use this for initialization
  26. void Start()
  27. {
  28. currentState = States.start;
  29. }
  30.  
  31. // Update is called once per frame
  32. void Update()
  33. {
  34. if (currentState == States.start)
  35. {
  36. state_start();
  37. }
  38. else if (currentState == States.h_1)
  39. {
  40. state_hall_1();
  41. }
  42. else if (currentState == States.h_2)
  43. {
  44. state_hall_2();
  45. }
  46. else if (currentState == States.h_3)
  47. {
  48. state_hall_3();
  49. }
  50. else if (currentState == States.c_1)
  51. {
  52. state_corridor_1();
  53. }
  54. else if (currentState == States.c_2)
  55. {
  56. state_corridor_2();
  57. }
  58. else if (currentState == States.c_22)
  59. {
  60. state_corridor_22();
  61. }
  62. else if (currentState == States.c_23)
  63. {
  64. state_corridor_23();
  65. }
  66. else if (currentState == States.c_3)
  67. {
  68. state_corridor_3();
  69. }
  70. else if (currentState == States.c_4)
  71. {
  72. state_corridor_4();
  73. }
  74. else if (currentState == States.r_1)
  75. {
  76. state_room_1();
  77. }
  78. else if (currentState == States.r_12)
  79. {
  80. state_room_12();
  81. }
  82. else if (currentState == States.r_2)
  83. {
  84. state_room_2();
  85. }
  86. else if (currentState == States.r_22)
  87. {
  88. state_room_22();
  89. }
  90. else if (currentState == States.r_3)
  91. {
  92. state_room_3();
  93. }
  94. else if (currentState == States.ld)
  95. {
  96. state_lockeddoor();
  97. }
  98. else if (currentState == States.w)
  99. {
  100. state_woman();
  101. }
  102. else if (currentState == States.bh)
  103. {
  104. state_bathroom();
  105. }
  106. else if (currentState == States.e)
  107. {
  108. state_empty();
  109. }
  110. else if (currentState == States.r)
  111. {
  112. state_red();
  113. }
  114. else if (currentState == States.end)
  115. {
  116. state_end();
  117. }
  118. }
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125. // Start Method
  126. void state_start()
  127. {
  128. neonLogo.SetActive(true);
  129. stormSound.SetActive(true);
  130. thunderSound.SetActive(true);
  131. currentText.text = "The storm finally catches up as you approach the inn. \n\nHolding your bag above your head to shield your eyes from the heavy drops, you glance at a neon sign steaming and runs for the [E]ntrance. \n\nYour wet clothes weighting a ton, you shake a bit off as you step on the wooden porch, trying to peak through the frosted glass next to the door.";
  132.  
  133. if (Input.GetKeyDown(KeyCode.E))
  134. {
  135. currentState = States.h_1;
  136. }
  137.  
  138. }
  139.  
  140. // First Hall Method
  141. //int index = 0; // Change here ( Essa variavel nao servia para nada, entao comentei )
  142. public int i = 0;
  143. public string[] texts = new string[] { "text1", "text2", "text3" };
  144. void state_hall_1()
  145. {
  146.  
  147. neonLogo.SetActive(false);
  148. stormSound.SetActive(false);
  149. thunderSound.SetActive(false);
  150.  
  151. entranceDoorSound.SetActive(true);
  152. doorChimeSound.SetActive(true);
  153.  
  154. //currentText.text = "Closing the door behind you, your dripping clothes darken the busted carpet that crosses the hall.\n\nSeveral old lamps tint yellow the dark wooden walls, while a single white light sits on the [D]esk.\n\nThe whole place creaks under the storm.\n\n" + "A shaded figure reads a large book by the light.";
  155.  
  156. if (i < texts.Length) // Change here ( Coloquei essa codição para alterar o texto somente se ainda estiver mais texto )
  157. {
  158. currentText.text = texts[i];
  159. }
  160.  
  161. if (Input.GetKeyDown(KeyCode.Space))
  162. {
  163. if (i < texts.Length)
  164. {
  165. i++;
  166. //currentText.text = texts[i]; // Change here ( Apos iterar o 'i' nao precisa mudar o texto novamente, pois vc ja muda no codigo acima, pois esse metodo roda no update )
  167. }
  168. }
  169.  
  170. if (Input.GetKeyDown(KeyCode.C) && i >= texts.Length - 1) // // Change here ( Aqui verifica se ja esta no ultimo texto, e a pessoa apertou o C )
  171. {
  172. currentState = States.c_1;
  173. }
  174.  
  175.  
  176.  
  177. }
  178.  
  179. // Second Hall Method
  180. void state_hall_2()
  181. {
  182. currentText.text = "Welcome to Hall_2.\n\n" + "Press C for " + previousState;
  183.  
  184. if (Input.GetKeyDown(KeyCode.C))
  185. {
  186. currentState = previousState;
  187. }
  188. }
  189.  
  190. // Third Hall Method
  191. void state_hall_3()
  192. {
  193. currentText.text = "Welcome to Hall_3.\n\n" + "This is the End. Press Enter to go back to Start or Space to End.";
  194. if (Input.GetKeyDown(KeyCode.Return))
  195. {
  196. currentState = States.start;
  197. }
  198. else if (Input.GetKeyDown(KeyCode.Space))
  199. {
  200. currentState = States.end;
  201. }
  202. }
  203.  
  204. // First Corridor Method, after first hall, before everything else
  205. void state_corridor_1()
  206. {
  207. currentText.text = "Welcome to Corridor_1.\n\n" + "Press H for H_2 or L for LD.";
  208. if (Input.GetKeyDown(KeyCode.H))
  209. {
  210. previousState = currentState;
  211. currentState = States.h_2;
  212. }
  213. else if (Input.GetKeyDown(KeyCode.L))
  214. {
  215. currentState = States.ld;
  216. }
  217. }
  218.  
  219. // Second Corridor Method, after first room, before woman.
  220. void state_corridor_2()
  221. {
  222. currentText.text = "Welcome to Corridor_2.\n\n" + "Press H for H_2, W for Woman, B for BH or R for R_1.2.";
  223. if (Input.GetKeyDown(KeyCode.H))
  224. {
  225. previousState = currentState;
  226. currentState = States.h_2;
  227. }
  228. else if (Input.GetKeyDown(KeyCode.W))
  229. {
  230. previousState = currentState;
  231. currentState = States.w;
  232. }
  233. else if (Input.GetKeyDown(KeyCode.B))
  234. {
  235. previousState = currentState;
  236. currentState = States.bh;
  237. }
  238. else if (Input.GetKeyDown(KeyCode.R))
  239. {
  240. currentState = States.r_12;
  241. }
  242. }
  243.  
  244. // 2.2 Corridor Method, after Room 1.2, before woman.
  245. void state_corridor_22()
  246. {
  247. currentText.text = "Welcome to Corridor_2.2.\n\n" + "Press H for H_2 or W for Woman.";
  248. if (Input.GetKeyDown(KeyCode.H))
  249. {
  250. previousState = currentState;
  251. currentState = States.h_2;
  252. }
  253. else if (Input.GetKeyDown(KeyCode.W))
  254. {
  255. previousState = currentState;
  256. currentState = States.w;
  257. }
  258.  
  259. }
  260.  
  261. // 2.3 Corridor Method, after woman, before second room.
  262. void state_corridor_23()
  263. {
  264. currentText.text = "Welcome to Corridor_2.3.\n\n" + "Press H for H_2, B for BH or R for R_2";
  265. if (Input.GetKeyDown(KeyCode.H))
  266. {
  267. previousState = currentState;
  268. currentState = States.h_2;
  269. }
  270. else if (Input.GetKeyDown(KeyCode.B))
  271. {
  272. previousState = currentState;
  273. currentState = States.bh;
  274. }
  275. else if (Input.GetKeyDown(KeyCode.R))
  276. {
  277. currentState = States.r_2;
  278. }
  279. }
  280.  
  281. // Third Corridor Method, after room 2.2, before third room.
  282. void state_corridor_3()
  283. {
  284. currentText.text = "Welcome to Corridor_3.\n\n" + "Press H for H_2, B for BH, E for Empty or R for R_3";
  285. if (Input.GetKeyDown(KeyCode.H))
  286. {
  287. previousState = currentState;
  288. currentState = States.h_2;
  289. }
  290. else if (Input.GetKeyDown(KeyCode.B))
  291. {
  292. previousState = currentState;
  293. currentState = States.bh;
  294. }
  295. else if (Input.GetKeyDown(KeyCode.E))
  296. {
  297. currentState = States.e;
  298. }
  299. else if (Input.GetKeyDown(KeyCode.R))
  300. {
  301. currentState = States.r_3;
  302. }
  303. }
  304.  
  305. // Fourth Corridor Method, after third room, before red.
  306. void state_corridor_4()
  307. {
  308. currentText.text = "Welcome to Corridor_4.\n\n" + "Press H for H_2 or R for Red.";
  309. if (Input.GetKeyDown(KeyCode.H))
  310. {
  311. previousState = currentState;
  312. currentState = States.h_2;
  313. }
  314. else if (Input.GetKeyDown(KeyCode.R))
  315. {
  316. currentState = States.r;
  317. }
  318.  
  319. }
  320.  
  321. // First Room, after locked door, before second corridor.
  322. void state_room_1()
  323. {
  324. currentText.text = "Welcome to Room_1.\n\n" + "Press C for C_2.";
  325. if (Input.GetKeyDown(KeyCode.C))
  326. {
  327. currentState = States.c_2;
  328. }
  329.  
  330. }
  331.  
  332. // Room 1.2, after second corridor, before corridor 2.2.
  333. void state_room_12()
  334. {
  335. currentText.text = "Welcome to Room_1.2.\n\n" + "Press C for C_2.2.";
  336. if (Input.GetKeyDown(KeyCode.C))
  337. {
  338. currentState = States.c_22;
  339. }
  340.  
  341. }
  342.  
  343. // Second Room, after woman, before room 2.2.
  344. void state_room_2()
  345. {
  346. currentText.text = "Welcome to Room_2.\n\n" + "Press R for R_2.2.";
  347. if (Input.GetKeyDown(KeyCode.R))
  348. {
  349. currentState = States.r_22;
  350. }
  351.  
  352. }
  353.  
  354. // Room 2.2, after second room, before third corridor.
  355. void state_room_22()
  356. {
  357. currentText.text = "Welcome to Room_2.2.\n\n" + "Press C for C_3.";
  358. if (Input.GetKeyDown(KeyCode.C))
  359. {
  360. currentState = States.c_3;
  361. }
  362.  
  363. }
  364.  
  365. // Room 3, after third corridor, before fourth corridor.
  366. void state_room_3()
  367. {
  368. currentText.text = "Welcome to Room_3.\n\n" + "Press C for C_4.";
  369. if (Input.GetKeyDown(KeyCode.C))
  370. {
  371. currentState = States.c_4;
  372. }
  373.  
  374. }
  375.  
  376. // Locked door, after first corridor, before first room.
  377. void state_lockeddoor()
  378. {
  379. currentText.text = "Welcome to Locked_Door.\n\n" + "Press R for R_1.";
  380. if (Input.GetKeyDown(KeyCode.R))
  381. {
  382. currentState = States.r_1;
  383. }
  384.  
  385. }
  386.  
  387. // Woman, after second corridor or corridor 2.2, before second room.
  388. void state_woman()
  389. {
  390. if (previousState == States.c_2)
  391. {
  392. nextState = States.c_23;
  393. rightKey = "C";
  394. }
  395. else if (previousState == States.c_22)
  396. {
  397. nextState = States.r_2;
  398. rightKey = "R";
  399. }
  400.  
  401. currentText.text = "Welcome to Woman.\n\n" + "Press " + rightKey + " for " + nextState;
  402.  
  403. if (Input.GetKeyDown(KeyCode.R))
  404. {
  405. currentState = nextState;
  406. }
  407. else if (Input.GetKeyDown(KeyCode.C))
  408. {
  409. currentState = nextState;
  410. }
  411. }
  412.  
  413. // Bathroom.
  414. void state_bathroom()
  415. {
  416.  
  417. currentText.text = "Welcome to Bathroom.\n\n" + "Press C for " + previousState;
  418. if (Input.GetKeyDown(KeyCode.C))
  419. {
  420. currentState = previousState;
  421. }
  422.  
  423. }
  424.  
  425. // Empty.
  426. void state_empty()
  427. {
  428.  
  429. currentText.text = "Welcome to Empty.\n\n" + "Press C for C_3";
  430. if (Input.GetKeyDown(KeyCode.C))
  431. {
  432. currentState = States.c_3;
  433. }
  434.  
  435. }
  436.  
  437. // Red.
  438. void state_red()
  439. {
  440.  
  441. currentText.text = "Welcome to Red.\n\n" + "Press H for H_3";
  442. if (Input.GetKeyDown(KeyCode.H))
  443. {
  444. currentState = States.h_3;
  445. }
  446.  
  447. }
  448.  
  449. // End.
  450. void state_end()
  451. {
  452.  
  453. currentText.text = "This is the End.\n\n" + "Press ESC to stop.";
  454.  
  455.  
  456. }
  457.  
  458. }
Add Comment
Please, Sign In to add comment