Hello there, I hope I’m putting this in the right place. I’m trying to create a dialogue cutscene for my game and have been having some trouble. Basically I have a dialogue system created that I found on Brackys youtube channel, and added another script to it to serve my goal. What I want is for the character portraits to appear as each character talks eventually having all the characters on screen. For example, the first cutscene has 4 characters talking. The scene starts with no one and as you click through the dialogue each character’s portrait appears on the screen. I’m using the same 4 scripts in each scene however some scenes have more or less than 4 characters. I’m dropping the scripts so you can take a look. Is there another way I can approach this? Any help would be very appreciated thank you!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class Dialogue
{
public string name;
public Sprite mugshot;
[TextArea(3, 10)]
public string[] sentences;
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DialogueTrigger : MonoBehaviour
{
public Dialogue dialogue;
public void TriggerDialogue()
{
FindObjectOfType<DialogueManager>().StartDialogue(dialogue);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DialogueManager : MonoBehaviour
{
public bool sentenceEnded = false;
public Text nameText;
public Text dialogueText;
public Image image1;
public Image image2;
public Image image3;
public Image image4;
private Queue<string> sentences;
void Start()
{
sentences = new Queue<string>();
}
public void StartDialogue(Dialogue dialogue)
{
sentenceEnded = false;
nameText.text = dialogue.name;
if(image1.sprite == null)
{
image1.gameObject.SetActive(true);
image1.sprite = dialogue.mugshot;
}
else if(image2.sprite == null)
{
image2.gameObject.SetActive(true);
image2.sprite = dialogue.mugshot;
}
else if (image3.sprite == null)
{
image3.gameObject.SetActive(true);
image3.sprite = dialogue.mugshot;
}
else if (image4.sprite == null)
{
image4.gameObject.SetActive(true);
image4.sprite = dialogue.mugshot;
}
sentences.Clear();
foreach(string sentence in dialogue.sentences)
{
sentences.Enqueue(sentence);
}
DisplayNextSentence();
}
public void DisplayNextSentence()
{
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()
{
sentenceEnded = true;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class PrologueDialogue : MonoBehaviour
{
public DialogueManager dm;
public GameObject startDialogue;
public List<GameObject> dialogue = new List<GameObject>();
public GameObject activeDialogue;
public int dialogueNumber = 1;
static int currentScene = 1;
void Start()
{
startDialogue.GetComponent<DialogueTrigger>().TriggerDialogue();
GameObject[] allDialogue = GameObject.FindGameObjectsWithTag("Dialogue");
dialogue.AddRange(allDialogue);
activeDialogue = dialogue[dialogueNumber];
}
void Update()
{
if(dialogue.Count > 0)
{
activeDialogue = dialogue[0];
}
if (dm.sentenceEnded == true)
{
activeDialogue.GetComponent<DialogueTrigger>().TriggerDialogue();
dialogue.RemoveAt(0);
}
}
public void NextScene()
{
if(dialogue.Count == 0)
{
currentScene++;
SceneManager.LoadScene("Cutscene" + (currentScene).ToString());
}
}
}