I would suggest simply implementing a trigger collider for each section of the game in which you want to initiate dialogue. You can do this by simply setting up an empty GameObject with a Box Collider with IsTrigger set to true.
For your situation, in order to allow for the correct dialogue to appear on-screen relative to the point in game, on each individual trigger object, add this script:
var dialogue : String[];
var output : GUIText;
private var curLine : int = 0;
function OnTriggerEnter (collider : Collider) {
if (collider.CompareTag("Player")) {
output.enabled = true;
output.text = dialogue[0];
}
}
function OnGUI () {
if (output.enabled && Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Return) { //I used the [Return] key here but you can choose whatever key you want
curLine++;
if (curLine < dialogue.Length) {
output.text = dialogue[curLine];
} else {
curLine = 0;
output.enabled = false;
}
}
}
You will need to add a GUIText object (you should only need one for all of your trigger objects) and all of your individual lines of dialogue *for that specific trigger* to the Dialogue array in the Inspector.
If you have any questions, just ask ;)
Hope that helps,
Klep :)
___
Edit:
Oh, and also I forgot to mention that you must tag your player as "Player", so that the triggers can pick which colliders to respond to. :)
↧