76 lines
1.4 KiB
C#
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;
|
|
}
|
|
}
|