Muliple npc with dialogue system.
Ive just watched the brackeys tutorial for a dialogue system and it worked fine untill i had one more npc into the same scene. The npc is ok cuz i just copied him from the first one. so i dont know what the problem is but hoppefully you can help me.
code:
Blockquote
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class dialogue_manager : MonoBehaviour {
public Text nametext;
public Text dialoguetext;
public Animator anime;
public Queue<string> sentences;
void Start()
{
sentences = new Queue<string>();
}
public void startdialogue(dialogue Dialogue)
{
Debug.Log("Starting conversation with " + Dialogue.name);
nametext.text = Dialogue.name;
sentences.Clear();
foreach(string sentence in Dialogue.sentences)
{
sentences.Enqueue(sentence);
}
}
public void displaynextscentence()
{
if (sentences.Count == 0)
{
Enddialogue();
return;
}
string sentence = sentences.Dequeue();
StopAllCoroutines();
StartCoroutine(TypeSentence(sentence));
}
IEnumerator TypeSentence (string sentence)
{
dialoguetext.text = "";
foreach(char letter in sentence.ToCharArray())
{
dialoguetext.text += letter;
yield return null;
}
}
void Enddialogue()
{
Debug.Log("End of conversation");
anime.SetBool("its open", true);
}
}
Blockquote
Blockquote
using System.Collections; using System.Collections.Generic; using UnityEngine;
[System.Serializable] public class dialogue { public string name;
[TextArea(1, 10)]
public string[] sentences;
}
Blockquote
Blockquote
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class dialogue_trigger : MonoBehaviour { public dialogue Dialogue;
public Animator anime;
public GameObject dialougebox;
public bool used;
public void ontriggerdialogue()
{
FindObjectOfType<dialogue_manager>().startdialogue(Dialogue);
dialougebox.SetActive(true);
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (used == false)
{
ontriggerdialogue();
used = true;
anime.SetBool("its open", false);
}
}
}
Blockquote
Your answer
Follow this Question
Related Questions
Can someone help me? 0 Answers
Player cannot double jump 1 Answer
What are Unity3D's greatest strengths and weaknesses? 0 Answers
I want to click random position object 1 Answer
2D Collision Best Practice 0 Answers