Dialogue manager question

so currently have a dialogue manager that triggers a set of dialogue, however its more of a monologue system, as it can only display one name and a set of sentences, how can i go about fixing this? Here are the scripts.

public class DialogueTrigger : MonoBehaviour
{

    public Dialogue dialogue;
    public bool isTriggerArea;
    public bool isInConversation;

    public void TriggerDialogue()
    {
        DialogueManager.instance.StartDialogue(dialogue);
    }

    private void Update()
    {
        if(isTriggerArea == true && Input.GetKeyDown(KeyCode.E) && isInConversation == false)
        {
            TriggerDialogue();
            isInConversation = true;
        }
    }

    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            isTriggerArea = true;
        }
    }

    private void OnTriggerExit(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            isTriggerArea = false;
        }
    }
}
public class DialogueManager : MonoBehaviour
{

    public Text nameText;
    public Text dialogueText;
    public Animator animator;
    public Queue<string> sentences;

    public static DialogueManager instance = null;

    // Start is called before the first frame update
    void Start()
    {
        sentences = new Queue<string>();
    }

    private void Awake()
    {
        if (instance == null)

            //if not, set instance to this
            instance = this;

        //If instance already exists and it's not this:
        else if (instance != this)

            //Then destroy this. This enforces our singleton pattern, meaning there can only ever be one instance of a GameManager.
            Destroy(gameObject);

        //Sets this to not be destroyed when reloading scene
        DontDestroyOnLoad(gameObject);
    }

    public void StartDialogue(Dialogue dialogue)
    {
        FindObjectOfType<PlayerController>().enabled = false;
        FindObjectOfType<ThirdPersonCamera>().enabled = false;
        animator.SetBool("IsOpen", true);
        nameText.text = dialogue.name;

        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()
    {
        animator.SetBool("IsOpen", false);
        FindObjectOfType<PlayerController>().enabled = true;
        FindObjectOfType<ThirdPersonCamera>().enabled = true;
    }
}
[System.Serializable]
public class Dialogue
{
    public string name;

    [TextArea(3, 10)]
    public string[] sentences;

}

You need something like this.

[System.Serializable]
public class Monologue
{
    public string name;
    [TextArea(3, 10)]
    public string[] sentences;

   public Monologue[] responses;
}

After that, you may let player choose from sences in one of possible responses to this machine monologue and then choose next monologue (or action) for machine from choosen player response.

Im trying to simply make characters talk back and forth, so after a character gets done speaking, the other character speaks (and changes the name text depending on character speaking)

Okay so a quick update, i managed to get it to where i can use multiple dialogues to do what i want by using a foreach loop. However this isn’t working with the characters name text to display who is speaking, what am i doing wrong?

Updated code that made it work:

    public void StartDialogue(Dialogue[] dialogue)
    {
        FindObjectOfType<PlayerController>().enabled = false;
        FindObjectOfType<ThirdPersonCamera>().enabled = false;
        animator.SetBool("IsOpen", true);
        //if(dialogue.isObject == true)
        //{
            //nameText.text = "";
            //nameBox.SetActive(false);
        //}
        //else
        //{
            //nameText.text = dialogue.name;
            //nameBox.SetActive(true);
        //}
        sentences.Clear();

        foreach (Dialogue item in dialogue)
        {
            nameText.text = item.name;
            foreach (string sentence in item.sentences)
            {
                sentences.Enqueue(sentence);
            }
        }

        DisplayNextSentence();
    }

Edit: just to clarify whats not working, the nameText.text is always turning out to be the very last element in the dialogue array for character names, Where as i need it to display each name per dialogue sequence, any ideas would be helpful!

I’ve managed to get everything working, but I can’t seem to find a way to swap out the name string between each dialogue. I don’t really want to add an array of strings to the dialogue class because i only need one name per class used. I’m pretty much stumped, have no idea how i’m suppose to access the name data of each dialogue and i have no idea how to display it with the ui text either.

The closest thing i could come up with is this bit of code here, but i keep getting an error in the foreach line called Assets\Scripts\DialogueManager.cs(70,13): error CS0030: Cannot convert type ‘char’ to ‘string’.

        for (int i = 0; i < dialogue.Length; i++)
        {
            foreach (string namesin in dialogue[i].name)
            {
                nameText.text = namesin;
            }
        }

strings are also treated as char arrays. in your foreach loop, you are looping through dialogue_.name. Maybe you meant to loop through something else in dialogue*?*_
On another note, how sophisticated are you intending to make this? Are you intending to eventually allow the player to make story altering choices through this system?

Not at the moment, i only plan to have the characters talk back and forth at the moment, and i use this for quest text. Otherwise not super sophisticated. The idea was to loop through dialogue to access dialogue.name so i could display the name but its not working and if i did loop through it, i notice its just showing the final name of the dialogue class list

For a free solution, use Ink!

There is a $20 asset called Dialogue Manager with an excellent in-game nodes and lines editor. But writers hate that interface, so really, use Ink.

That’s because you wrote

nameText.text = item.name;

nameText.text can only have one value so all you are doing in your loop is replacing that value over and over again.

Thanks for the response! Yeah, what would you do to get all of the names but still display them when they need to be? I know i could use a list to get all the name strings but i dont really know where to go from there