Skip to content

harrycarriers/dialogue-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Simple Dialogue System for Unity

Hello! I wanted to share some of my work starting today! You will learn how to create a simple dialogue system with Unity Coroutines and ScriptableObjects.

Using ScriptableObject

Create a ScriptableObject on Project folder using Create > ScriptableObjects > DialogueSystem

Scriptable Object Example

Script side

Make it single system:

// Make sure to drag the scriptable object here!
[SerializeField]
private DialogueSystem dialogueSystem;

//...

void Start()
{
   StartCoroutine(StartDialogue);
}

private IEnumerator StartDialogue()
{
    // Get first dialog
    var firstDialog = dialogueSystem.contexts[0].dialogue;

    // Or loop through
    for(int i=0;i<dialogueSystem.contexts.length;i++)
    {
        var dialogue = dialogueSystem.contexts[i].dialogue;
        yield return new WaitForSeconds(dialogueSystem.contexts[i].contextReadTime);
    }
     
    // ...
}

Or if you want to create sequences, make it an array:

[SerializeField]
private DialogueSystem[] dialogueSystems;

//...
int currentSequence=0;

void Start()
{
   StartCoroutine(StartDialogue());
}

private IEnumerator StartDialogue()
{
    // Get sprite for talking person
    var talkerSprite = dialogueSystem[currentSequence].talkerSprite;

    // Loop through
    for(int i=0;i<dialogueSystem[currentSequence].contexts.length;i++)
    {
        var dialogue = dialogueSystem[currentSequence].contexts[i].dialogue;
        yield return new WaitForSeconds(dialogueSystem[currentSequence].contexts[i].contextReadTime);
    }
     
    // ...
}

If you want to divide sprites for each dialogue, simply move public Sprite talkerSprite inside Context class.

Check out the full example here.

About

Dialogue system for Unity, using Coroutines.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages