So this is my script:
public class DialogManager : MonoBehaviour
public GameObject Battle;
public Text nameText;
public Text dialogText;
public Animator animator;
private Queue<string> sentences;
sentences = new Queue<string>();
public void StartDialog(ObjectDialog dialog)
nameText.text = dialog.name;
foreach (string sentence in dialog.sentences)
public void DisplayNextSentece()
if (sentences.Count == 0)
string sentence = sentences.Dequeue();
dialogText.text = sentence;
Debug.Log("End of conversation.");
It depends what kind of game you are playing. In essence, there are two types.
- The first is where your player has to go through each level, rather like a puzzle game. Level 5 always follows level 4 and they go up sequentially.
- The second is where you are in a room with multiple doors. Each door takes you to a different level. They are not sequential and you can take any scene in any order, depending on the path you choose.
In either case, you have to go to File > Build Settings and add all the scenes that are in your game to the “Scenes in Build” panel. For the puzzle game, you put the levels in strict ascending order. As you do so, you will see that the number on the right hand side is the level number, starting at zero. For the free-flowing game, you can add the scenes in any order you wish but make sure that you know all the scene names and that there are no duplicates.
To change to the next sequential scene, you use
SceneManager.GetActiveScene().buildIndex to get the current scene number, store it in an Integer and increment it. Then use
To change to a named scene you use:
Not surprisingly, there is a lot more to it than that. You might use a Static class to manage all of this, rather than have it in every scene. You might use DontDestroyOnLoad to keep an object between scenes. You might want to preload a scene or have multiple scenes open. For all these and more, check the documentation.