Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using UnityEngine.UI;
- using System.Collections.Generic;
- using UnityEngine;
- public class TextController : MonoBehaviour
- {
- public Text currentText;
- 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 };
- private States currentState;
- private States previousState;
- private States nextState;
- private string rightKey;
- public GameObject neonLogo;
- public GameObject stormSound;
- public GameObject thunderSound;
- public GameObject entranceDoorSound;
- public GameObject doorChimeSound;
- // Use this for initialization
- void Start()
- {
- currentState = States.start;
- }
- // Update is called once per frame
- void Update()
- {
- if (currentState == States.start)
- {
- state_start();
- }
- else if (currentState == States.h_1)
- {
- state_hall_1();
- }
- else if (currentState == States.h_2)
- {
- state_hall_2();
- }
- else if (currentState == States.h_3)
- {
- state_hall_3();
- }
- else if (currentState == States.c_1)
- {
- state_corridor_1();
- }
- else if (currentState == States.c_2)
- {
- state_corridor_2();
- }
- else if (currentState == States.c_22)
- {
- state_corridor_22();
- }
- else if (currentState == States.c_23)
- {
- state_corridor_23();
- }
- else if (currentState == States.c_3)
- {
- state_corridor_3();
- }
- else if (currentState == States.c_4)
- {
- state_corridor_4();
- }
- else if (currentState == States.r_1)
- {
- state_room_1();
- }
- else if (currentState == States.r_12)
- {
- state_room_12();
- }
- else if (currentState == States.r_2)
- {
- state_room_2();
- }
- else if (currentState == States.r_22)
- {
- state_room_22();
- }
- else if (currentState == States.r_3)
- {
- state_room_3();
- }
- else if (currentState == States.ld)
- {
- state_lockeddoor();
- }
- else if (currentState == States.w)
- {
- state_woman();
- }
- else if (currentState == States.bh)
- {
- state_bathroom();
- }
- else if (currentState == States.e)
- {
- state_empty();
- }
- else if (currentState == States.r)
- {
- state_red();
- }
- else if (currentState == States.end)
- {
- state_end();
- }
- }
- // Start Method
- void state_start()
- {
- neonLogo.SetActive(true);
- stormSound.SetActive(true);
- thunderSound.SetActive(true);
- 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.";
- if (Input.GetKeyDown(KeyCode.E))
- {
- currentState = States.h_1;
- }
- }
- // First Hall Method
- //int index = 0; // Change here ( Essa variavel nao servia para nada, entao comentei )
- public int i = 0;
- public string[] texts = new string[] { "text1", "text2", "text3" };
- void state_hall_1()
- {
- neonLogo.SetActive(false);
- stormSound.SetActive(false);
- thunderSound.SetActive(false);
- entranceDoorSound.SetActive(true);
- doorChimeSound.SetActive(true);
- //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.";
- if (i < texts.Length) // Change here ( Coloquei essa codição para alterar o texto somente se ainda estiver mais texto )
- {
- currentText.text = texts[i];
- }
- if (Input.GetKeyDown(KeyCode.Space))
- {
- if (i < texts.Length)
- {
- i++;
- //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 )
- }
- }
- 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 )
- {
- currentState = States.c_1;
- }
- }
- // Second Hall Method
- void state_hall_2()
- {
- currentText.text = "Welcome to Hall_2.\n\n" + "Press C for " + previousState;
- if (Input.GetKeyDown(KeyCode.C))
- {
- currentState = previousState;
- }
- }
- // Third Hall Method
- void state_hall_3()
- {
- currentText.text = "Welcome to Hall_3.\n\n" + "This is the End. Press Enter to go back to Start or Space to End.";
- if (Input.GetKeyDown(KeyCode.Return))
- {
- currentState = States.start;
- }
- else if (Input.GetKeyDown(KeyCode.Space))
- {
- currentState = States.end;
- }
- }
- // First Corridor Method, after first hall, before everything else
- void state_corridor_1()
- {
- currentText.text = "Welcome to Corridor_1.\n\n" + "Press H for H_2 or L for LD.";
- if (Input.GetKeyDown(KeyCode.H))
- {
- previousState = currentState;
- currentState = States.h_2;
- }
- else if (Input.GetKeyDown(KeyCode.L))
- {
- currentState = States.ld;
- }
- }
- // Second Corridor Method, after first room, before woman.
- void state_corridor_2()
- {
- 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.";
- if (Input.GetKeyDown(KeyCode.H))
- {
- previousState = currentState;
- currentState = States.h_2;
- }
- else if (Input.GetKeyDown(KeyCode.W))
- {
- previousState = currentState;
- currentState = States.w;
- }
- else if (Input.GetKeyDown(KeyCode.B))
- {
- previousState = currentState;
- currentState = States.bh;
- }
- else if (Input.GetKeyDown(KeyCode.R))
- {
- currentState = States.r_12;
- }
- }
- // 2.2 Corridor Method, after Room 1.2, before woman.
- void state_corridor_22()
- {
- currentText.text = "Welcome to Corridor_2.2.\n\n" + "Press H for H_2 or W for Woman.";
- if (Input.GetKeyDown(KeyCode.H))
- {
- previousState = currentState;
- currentState = States.h_2;
- }
- else if (Input.GetKeyDown(KeyCode.W))
- {
- previousState = currentState;
- currentState = States.w;
- }
- }
- // 2.3 Corridor Method, after woman, before second room.
- void state_corridor_23()
- {
- currentText.text = "Welcome to Corridor_2.3.\n\n" + "Press H for H_2, B for BH or R for R_2";
- if (Input.GetKeyDown(KeyCode.H))
- {
- previousState = currentState;
- currentState = States.h_2;
- }
- else if (Input.GetKeyDown(KeyCode.B))
- {
- previousState = currentState;
- currentState = States.bh;
- }
- else if (Input.GetKeyDown(KeyCode.R))
- {
- currentState = States.r_2;
- }
- }
- // Third Corridor Method, after room 2.2, before third room.
- void state_corridor_3()
- {
- currentText.text = "Welcome to Corridor_3.\n\n" + "Press H for H_2, B for BH, E for Empty or R for R_3";
- if (Input.GetKeyDown(KeyCode.H))
- {
- previousState = currentState;
- currentState = States.h_2;
- }
- else if (Input.GetKeyDown(KeyCode.B))
- {
- previousState = currentState;
- currentState = States.bh;
- }
- else if (Input.GetKeyDown(KeyCode.E))
- {
- currentState = States.e;
- }
- else if (Input.GetKeyDown(KeyCode.R))
- {
- currentState = States.r_3;
- }
- }
- // Fourth Corridor Method, after third room, before red.
- void state_corridor_4()
- {
- currentText.text = "Welcome to Corridor_4.\n\n" + "Press H for H_2 or R for Red.";
- if (Input.GetKeyDown(KeyCode.H))
- {
- previousState = currentState;
- currentState = States.h_2;
- }
- else if (Input.GetKeyDown(KeyCode.R))
- {
- currentState = States.r;
- }
- }
- // First Room, after locked door, before second corridor.
- void state_room_1()
- {
- currentText.text = "Welcome to Room_1.\n\n" + "Press C for C_2.";
- if (Input.GetKeyDown(KeyCode.C))
- {
- currentState = States.c_2;
- }
- }
- // Room 1.2, after second corridor, before corridor 2.2.
- void state_room_12()
- {
- currentText.text = "Welcome to Room_1.2.\n\n" + "Press C for C_2.2.";
- if (Input.GetKeyDown(KeyCode.C))
- {
- currentState = States.c_22;
- }
- }
- // Second Room, after woman, before room 2.2.
- void state_room_2()
- {
- currentText.text = "Welcome to Room_2.\n\n" + "Press R for R_2.2.";
- if (Input.GetKeyDown(KeyCode.R))
- {
- currentState = States.r_22;
- }
- }
- // Room 2.2, after second room, before third corridor.
- void state_room_22()
- {
- currentText.text = "Welcome to Room_2.2.\n\n" + "Press C for C_3.";
- if (Input.GetKeyDown(KeyCode.C))
- {
- currentState = States.c_3;
- }
- }
- // Room 3, after third corridor, before fourth corridor.
- void state_room_3()
- {
- currentText.text = "Welcome to Room_3.\n\n" + "Press C for C_4.";
- if (Input.GetKeyDown(KeyCode.C))
- {
- currentState = States.c_4;
- }
- }
- // Locked door, after first corridor, before first room.
- void state_lockeddoor()
- {
- currentText.text = "Welcome to Locked_Door.\n\n" + "Press R for R_1.";
- if (Input.GetKeyDown(KeyCode.R))
- {
- currentState = States.r_1;
- }
- }
- // Woman, after second corridor or corridor 2.2, before second room.
- void state_woman()
- {
- if (previousState == States.c_2)
- {
- nextState = States.c_23;
- rightKey = "C";
- }
- else if (previousState == States.c_22)
- {
- nextState = States.r_2;
- rightKey = "R";
- }
- currentText.text = "Welcome to Woman.\n\n" + "Press " + rightKey + " for " + nextState;
- if (Input.GetKeyDown(KeyCode.R))
- {
- currentState = nextState;
- }
- else if (Input.GetKeyDown(KeyCode.C))
- {
- currentState = nextState;
- }
- }
- // Bathroom.
- void state_bathroom()
- {
- currentText.text = "Welcome to Bathroom.\n\n" + "Press C for " + previousState;
- if (Input.GetKeyDown(KeyCode.C))
- {
- currentState = previousState;
- }
- }
- // Empty.
- void state_empty()
- {
- currentText.text = "Welcome to Empty.\n\n" + "Press C for C_3";
- if (Input.GetKeyDown(KeyCode.C))
- {
- currentState = States.c_3;
- }
- }
- // Red.
- void state_red()
- {
- currentText.text = "Welcome to Red.\n\n" + "Press H for H_3";
- if (Input.GetKeyDown(KeyCode.H))
- {
- currentState = States.h_3;
- }
- }
- // End.
- void state_end()
- {
- currentText.text = "This is the End.\n\n" + "Press ESC to stop.";
- }
- }
Add Comment
Please, Sign In to add comment