I am having trouble creating a tutorial level for my game in Unity. The first problem is efficiency. I have a script below, which displays the dialogue. And I want to know the best way to create goals that the player can meet without excessive amounts of script.
using UnityEngine;
using System.Collections;
using System.IO;
using System;
using UnityEngine.UI;
public class TutorialSystem : MonoBehaviour
{
bool canSpeak = true;
protected StreamReader reader;
public Text Dialogue;
string sLine = " ";
public string SourceName;
string[] lines;
ArrayList arrText = new ArrayList();
int i = 0;
void Start()
{
reader = new StreamReader("Assets/Resources/" + SourceName + ".txt");
while(sLine != null)
{
sLine = reader.ReadLine();
if(sLine != null)
{
arrText.Add(sLine);
}
}
reader.Close();
sLine = arrText[i].ToString();
StartCoroutine(Typewrite(sLine));
i++;
}
void Update()
{
if(Input.GetButtonDown("Submit") && canSpeak)
{
sLine = arrText[i].ToString();
StartCoroutine(Typewrite(sLine));
i++;
}
if (Input.GetButtonDown("Submit") && !canSpeak && i == arrText.Count)
{
Dialogue.text = null;
}
}
IEnumerator Typewrite(string message)
{
canSpeak = false;
Dialogue.text = null;
foreach (char letter in message.ToCharArray())
{
Dialogue.text = Dialogue.text + letter;
yield return new WaitForSeconds(0.01f);
}
canSpeak = true;
if (i == arrText.Count)
{
canSpeak = false;
}
}
}
The second problem is how to I make it expandable, currently the text reads a .txt file line by line. Does anyone have a suggestion on how I can change this to be used in situations such as character interaction or should I just make another script entirely for that?
Many thanks in advance.