I am trying to have dialogue triggered by the player entering a box collider. When I attach my script the game freezes in playing and my text moves across the screen.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
[RequireComponent(typeof(BoxCollider))]
public class Dialogue : MonoBehaviour {
public List<string> dialogueList = new List<string>();
public string convoOverText = "HAHAHAHHAHAHHAHAHahahahahaaaa";
int currentDialogueLine = 0;
bool alreadyTriggerEntered = false;
Text dialogueText;
// Use this for initialization
void Start () {
dialogueText = GameObject.Find("DialogueTextBox").GetComponent<Text>();
}
void Converse ()
{
if (dialogueList.Count > currentDialogueLine)
{
dialogueText.text = dialogueList[currentDialogueLine];
Debug.Log(dialogueList[currentDialogueLine]);
currentDialogueLine++;
}
else if (dialogueList.Count <= currentDialogueLine)
{
dialogueText.text = convoOverText;
Debug.Log(convoOverText);
}
}
void OnTriggerEnter (Collider other)
{
if (!alreadyTriggerEntered)
{
alreadyTriggerEntered = true;
Converse();
}
}
void OnTriggerStay (Collider other)
{
if (other.tag == "Player")
{
if (Input.GetMouseButtonDown(0))
{
Converse();
}
}
}
}`