Dialogue runner
- Game Development course
- Advanced
- Lesson 33/71
- 4 min
Learn a runner that reads dialogues in order.
Dialogue Runner
The controller class that steps through dialogue data sequentially and advances to the next sentence upon player input is called the Dialogue Runner. It tracks the active line index in memory.
public class DialogueRunner : MonoBehaviour {
private int currentIndex = 0;
public List<string> lines;
public void NextLine() {
currentIndex++;
}
}When the player clicks or presses the interaction key, NextLine() is executed to advance dialogue progression.
Checking Dialogue Completion
At each step, currentIndex is compared against the total lines count (lines.Count). If the end of the collection is reached, the dialogue terminates and the UI is dismissed.
if (currentIndex >= lines.Count) {
EndDialogue();
} else {
DisplayLine(lines[currentIndex]);
}Upon dialogue completion, player movement inputs are re-enabled to restore regular gameplay.
Practice Dialogue runner progression
Define a Start method. Inside, declare int aktifIndex = 1; and print "Aktif replik sirasi: " + aktifIndex to the console.
Starter code
using UnityEngine;
public class RunnerTester : MonoBehaviour
{
// Start icinde aktifIndex tanimla ve yazdir
}Sample solution
using UnityEngine;
public class RunnerTester : MonoBehaviour
{
void Start()
{
int aktifIndex = 1;
Debug.Log("Aktif replik sirasi: " + aktifIndex);
}
}Expected output
Aktif replik sirasi: 1
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which logic enables advancing to the next dialogue sentence when a player presses an interaction key in a Dialogue Runner?
- Exiting and restarting the game immediately
- Deleting all UI components in the scene
- Hiding all 3D models on screen
- Incrementing the active dialogue index by 1 and dispatching the next line to UI Correct answer
Explanation: The dialogue runner increments the active index by one to display the subsequent line on screen.
2 Dialogue termination check
if (currentIndex >= lines.____) { EndDialogue(); }
if (currentIndex >= lines.Count) { EndDialogue(); }
Explanation: The 'Count' property is used to inspect the element count of a C# List.
3 Dialogue running concepts
| Term | Meaning |
|---|---|
Dialogue Runner |
Controller running dialogue flow |
currentIndex |
Index of the actively displayed line |
NextLine |
Method progressing to the next line |
EndDialogue |
Ends conversation and closes UI |