Game Development
Dialogue runner
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.
Exercise Dialogue runner progression
Define a Start method. Inside, declare int aktifIndex = 1; and print "Aktif replik sirasi: " + aktifIndex to the console.
Show example solution
using UnityEngine;
public class RunnerTester : MonoBehaviour
{
void Start()
{
int aktifIndex = 1;
Debug.Log("Aktif replik sirasi: " + aktifIndex);
}
}
Test yourself
-
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
Show answer
Incrementing the active dialogue index by 1 and dispatching the next line to UI — The dialogue runner increments the active index by one to display the subsequent line on screen.
-
Dialogue termination check
if (currentIndex >= lines.____) { EndDialogue(); }
Show answer
if (currentIndex >= lines.Count) { EndDialogue(); }
-
Dialogue running concepts
- 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
Next lesson: Choice branches