Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.SceneManagement;
- public class DialogueParser : MonoBehaviour {
- //to keep dialogue from advancing when the record is open
- private InvestigationManager investigationManager;
- //to change the scene after the dialogue is read
- public string nextScene;
- //for fade in/out
- public Animator anim;
- public GameObject fader;
- //read the whole file, look at the current line, split the line up with # and place them in their own arrays to be read from
- public TextAsset dialogue;
- public Text characterName, dialogueContent;
- public string[] wholeDoc;
- public string[] reading;
- private string readingName, readingDialogue;
- //used to keep track of the line the player is still reading
- public int currentLine;
- public int endLine;
- void Awake()
- {
- wholeDoc = dialogue.text.Split('\n');
- fader.SetActive(true);
- investigationManager = GameObject.Find("Canvas").GetComponent<InvestigationManager>();
- currentLine = PlayerPrefs.GetInt("CurrentLine");
- if (currentLine == 0)
- {
- currentLine = 2;
- }
- }
- void Update()
- {
- reading = wholeDoc[currentLine].Split('#');
- characterName.text = reading[0];
- dialogueContent.text = reading[1];
- if (Input.GetKeyUp("e") && !investigationManager.recordOpen)
- {
- currentLine++;
- }
- if (currentLine >= endLine)
- {
- currentLine = 1;
- //fade out and change the scene
- anim.SetTrigger("LeavingScene");
- StartCoroutine(LoadLevel());
- }
- }
- IEnumerator LoadLevel()
- {
- yield return new WaitForSeconds(.3f);
- SceneManager.LoadScene(nextScene);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement