Whenever I use displaysentence() it throws a nullreferenceexeption
DialogueManager
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DialogueManager : MonoBehaviour
{
public Queue<string> sentences;
// Start is called before the first frame update
void Awake()
{
sentences = new Queue<string>();
}
public void dialoguestart (Dialogue dialogue)
{
Debug.Log(dialogue.name);
sentences.Clear();
foreach (string sentence in dialogue.sentences)
{
sentences.Enqueue(sentence);
}
displaysentence();
}
public void displaysentence()
{
if (sentences.Count == 0)
{
enddialogue();
return;
}
string sentence = sentences.Dequeue();
Debug.Log(sentence);
}
void enddialogue()
{
Debug.Log("end");
}
}
Dialogue
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class Dialogue
{
public string name;
[TextArea (3,10)]
public string[] sentences;
}
DialogueTrigger
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DialogueTrigger : MonoBehaviour
{
public Dialogue dialogue;
public GameObject cameraref;
public void triggerdialogue ()
{
FindObjectOfType<DialogueManager>().dialoguestart(dialogue);
}
private void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
Time.timeScale = 0f;
triggerdialogue();
Cursor.lockState = CursorLockMode.None;
cameraref.GetComponent<Camera>().enabled = false;
}
}
}