Trying to get several character icons to display during dialogue

Hey everyone!

I am really new to Unity and just messing around, hoping that I can make something fun.
My code is probably also rather messy since I’ve only started to learn it myself recently.
Hopefully I’ve at least posted the thread in the right section Lol.

As of now, I have got 3 scripts that handle most of my dialogue.

This is the script I use for triggering dialogue:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DialogueTrigger : MonoBehaviour
{

//    [SerializeField] private Collider2D playerCollider;
    public Dialogue dialogue;
    private bool insideCollider;
    [SerializeField] private bool forcedDialogue = true;

    private bool startDialogue = false;
    private bool endedDialogue = false;
    private PlayerController thePlayer;

    private void Update()
    {
        if (startDialogue && Input.GetKeyDown("down") && insideCollider)
        {
            endedDialogue = !FindObjectOfType<DialogueManager>().DisplayNextSentence(dialogue);
        }

        else if (Input.GetKeyDown("down") && insideCollider && !forcedDialogue)
        {
            FindObjectOfType<DialogueManager>().StartDialogue(dialogue);
            startDialogue = true;
            Debug.Log("startOptionalDialogue");
        }

        if (!startDialogue && insideCollider && forcedDialogue)
        {
            FindObjectOfType<DialogueManager>().StartDialogue(dialogue);
            startDialogue = true;
            Debug.Log("startForcedDialogue");

        }
    }

    public void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.name == "Player")
        {
            insideCollider = true;
        }
    }

    public void OnTriggerExit2D(Collider2D other)
    {
        if (other.gameObject.name == "Player")
        {
            insideCollider = false;
            startDialogue = false;
            FindObjectOfType<DialogueManager>().EndDialogue();
        }
    }

    public bool getEndedDialogue()
    {
        return endedDialogue;
    }

}

I’ve got a dialogue script

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

[System.Serializable]
public class Dialogue
{
    public int letterDelay;
    [TextArea(3, 10)] public string[] sentences;
    public Sprite actor;
    public Sprite background;
    public string name;
}

And got a dialogue manager, the place that handles all of the magic.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class DialogueManager : MonoBehaviour
{
    public Canvas dialogueCanvas;
//    [SerializeField] private Movement playerMovement;

    private Queue<string> sentences;
    public Text nameText;
    public Text dialogueText;
    public Image actorImage;
    public Image backgroundImage;

    void Start()
    {
        sentences = new Queue<string>();
        dialogueCanvas.enabled = false;
    }

    public void StartDialogue(Dialogue dialogue)
    {
        dialogueCanvas.enabled = true;
//        playerMovement.Freeze();

        nameText.text = dialogue.name;
        actorImage.sprite = dialogue.actor;
        backgroundImage.sprite = dialogue.background;

        sentences.Clear();
        foreach (string sentence in dialogue.sentences)
        {
            sentences.Enqueue(sentence);
        }
        DisplayNextSentence(dialogue);
    }

    //returns false when the dialogue ends, otherwise true
    public bool DisplayNextSentence(Dialogue dialogue)
    {
        if (sentences.Count == 0)
        {
            EndDialogue();
            return false;
        }
        string sentence = sentences.Dequeue();
        StopAllCoroutines();
        StartCoroutine(TypeSentence(sentence, dialogue));
        return true;
        //dialogueText.text = sentence;
    }

    IEnumerator TypeSentence (string sentence, Dialogue dialogue)
    {
        dialogueText.text = "";
        foreach (char letter in sentence.ToCharArray())
        {
            dialogueText.text += letter;
            for(int i = 0; i < dialogue.letterDelay; i++)
            {
                yield return 0;
            }
        }
    }

    public void EndDialogue()
    {
        dialogueCanvas.enabled = false;
        Debug.Log("closeDialogue");
        //playerMovement.StopFreeze();
    }
}

All of this works (at the time of writing).

This is how the dialogue looks before anything happens in play mode. The textures for the background and icon are all tied to the trigger, so they can be unique for each scenario!
(Same for the dialogue but you probably figured that out already lol)

Unfortunately, it still doesn’t allow me to express things the way I hoped to. The dialogue appears in several “parts” which the player has to press a continue button for to display the rest. I wanna do something similar for the faces that I’ll put next to the dialogue. As of now, it’s only one, but it’d be cool if I can add a unique face for each piece of dialogue! (Undertale also has characters changing their expression in dialogue boxes for example)
I’d also love to implement a unique background for each part of the dialogue. That shouldn’t be too difficult to add if the character icons work since the system I used too far for both is pretty similar.

I have tried to make it myself but couldn’t figure a way to make it work.
Could anyone help me out with this one?

Thanks in advance!
AnimalMace

Your dialogue sentence is a string, this is what is limiting you… A simple way to overcome this limit is to use rich text, while a more elaborated would be to use json.

Also you are not using UI Toolkit here, just a simple Text. To use rich text you will need to use either UI Toolkit or TextMeshPro, the difference between the two is that TMP can have sprites, while UI Toolkit uses quads and materials.

https://docs.unity3d.com/Packages/com.unity.ugui@1.0/manual/StyledText.html