1
0
This repository has been archived on 2024-09-03. You can view files and clone it, but cannot push or open issues or pull requests.
System-Purge/Assets/Dusty Char/TextBoxManager.cs

76 lines
1.4 KiB
C#

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class TextBoxManager : MonoBehaviour {
public GameObject textBox;
public Text theText;
public TextAsset textfile;
public string[] textLines;
public int currentLine;
public int endAtLine;
public PlayerCharacter player;
public bool isActive;
public bool stopPlayerMovement;
// Use this for initialization
void Start()
{
player = FindObjectOfType<PlayerCharacter>();
if (textfile != null)
{
textLines = (textfile.text.Split('\n'));
}
if (endAtLine == 0)
{
endAtLine = textLines.Length - 1;
}
if(isActive)
{
EnableTextBox();
}
else
{
DisableTextBox();
}
}
void Update()
{
if (!isActive)
return;
theText.text = textLines[currentLine];
if (Input.GetKeyDown(KeyCode.Space))
currentLine++;
if (currentLine > endAtLine)
DisableTextBox();
}
public void EnableTextBox()
{
textBox.SetActive(true);
if (stopPlayerMovement)
player.canMove = false;
}
public void DisableTextBox()
{
textBox.SetActive(false); //Once we get to the end of the "lines" we turn off the text block.
player.canMove = true;
}
}