Home > Blockchain >  I want to Go to another Scene after dialogue ends
I want to Go to another Scene after dialogue ends

Time:06-27

I'm making a 2D game and want to jump from a dialogue scene that is a tutorial for the beginning of the game to a scene where the game starts but I don't know how to achieve that after the dialogue ends. here is the entire script for the scene ( dialogue manager, Dialogue, and Dialogue trigger).

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


public class DialogueManager : MonoBehaviour
{

    public TextMeshProUGUI nameText;
    public TextMeshProUGUI dialogueText;


    private Queue<string> sentences;

    void Start()
    {
        sentences = new Queue<string>();
    }

    public void StartDialogue(Dialogue dialogue)
    {

        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();

        dialogueText.text = sentence;

    }

    void EndDialogue()
    {

        Debug.Log("End of conversation.");

    }


}

And this is the Dialogue Script:

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

[System.Serializable]
public class Dialogue
{

    public string name;

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


}

And this is the Dialogue Trigger:

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

public class DialogueTrigger : MonoBehaviour
{

    public Dialogue dialogue;

    public void TriggerDialogue()
    {
        FindObjectOfType<DialogueManager>().StartDialogue(dialogue);
    }
}

CodePudding user response:

Use SceneManager.LoadScene in your EndDialogue() method

    void EndDialogue()
    {
        // load new scene here
        Debug.Log("End of conversation.");

    }
  • Related