SHARE
TWEET

Untitled

a guest Mar 20th, 2017 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.SceneManagement;
  6.  
  7. public class DialogueParser : MonoBehaviour {
  8.  
  9.     //to keep dialogue from advancing when the record is open
  10.     private InvestigationManager investigationManager;
  11.  
  12.     //to change the scene after the dialogue is read
  13.     public string nextScene;
  14.  
  15.     //for fade in/out
  16.     public Animator anim;
  17.     public GameObject fader;
  18.  
  19.     //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
  20.  
  21.     public TextAsset dialogue;
  22.     public Text characterName, dialogueContent;
  23.  
  24.     public string[] wholeDoc;
  25.     public string[] reading;
  26.     private string readingName, readingDialogue;
  27.  
  28.     //used to keep track of the line the player is still reading
  29.     public int currentLine;
  30.     public int endLine;
  31.    
  32.  
  33.     void Awake()
  34.     {
  35.         wholeDoc = dialogue.text.Split('\n');
  36.         fader.SetActive(true);
  37.         investigationManager = GameObject.Find("Canvas").GetComponent<InvestigationManager>();
  38.  
  39.         currentLine = PlayerPrefs.GetInt("CurrentLine");
  40.  
  41.         if (currentLine == 0)
  42.         {
  43.             currentLine = 2;
  44.         }
  45.     }
  46.  
  47.     void Update()
  48.     {
  49.         reading = wholeDoc[currentLine].Split('#');
  50.  
  51.         characterName.text = reading[0];
  52.         dialogueContent.text = reading[1];
  53.  
  54.         if (Input.GetKeyUp("e") && !investigationManager.recordOpen)
  55.         {
  56.             currentLine++;
  57.         }
  58.  
  59.         if (currentLine >= endLine)
  60.         {
  61.             currentLine = 1;
  62.             //fade out and change the scene
  63.             anim.SetTrigger("LeavingScene");
  64.             StartCoroutine(LoadLevel());
  65.         }
  66.     }
  67.  
  68.     IEnumerator LoadLevel()
  69.     {
  70.         yield return new WaitForSeconds(.3f);
  71.         SceneManager.LoadScene(nextScene);
  72.     }
  73.  
  74. }
RAW Paste Data
Top