- Home /
How to continue a dialog (GUI.Label) with answering Buttons?
Hi Guys,
I need help again, but this time, it is about scripting a dialog between my Player and a Cube (very cool, isn't it?)
Here is the Behaviour I would like to see:
The Player approaches to the Cube and gets in its Trigger.
The Player then presses "E" to start a conversation with that Cube.
The GUI.Area with the conversation text appears like this:
Now I would like to press the Button to continue the dialog, you know? It would just be like in The Elder Scrolls - Morrowind.
The Cube would tell me something like: "The Quest-NPC is behind that house" and I would Click on the appearing OK-Button to Close the whole Dialog.
Basically I would like to see the second Part of the text only if I clicked on the button in the dialog.
But if I click this Button, nothing happens.
Here is my Script:
if (other.gameObject.tag == "NPC"){
NPCtalk = true;
if(Input.GetKeyUp(KeyCode.E)){
startdialog = true;
item_name = other.gameObject.name;
playername = "Ark";
}
}
}
void OnTriggerExit(Collider other){
NPCtalk = false;
WeaponPickup = false;
}
void OnGUI(){
if (WeaponPickup){
GUI.Label (new Rect (500,500,1000,1000), "[E] Waffe aufnehmen");
}
if (NPCtalk){
GUI.Label (new Rect (500,500,1000,1000), "[E] Reden");
}
if (startdialog){
NPCtalk = false;
if (item_name == "Cube"){
GUILayout.BeginArea(new Rect(100,100,200,200));
GUILayout.Label(item_name + ": Alter...du redest mit einem Wuerfel...");
if (GUILayout.Button(playername + ": Ich geh dann mal weiter")){
GUILayout.Label(item_name + ":...den Questgeber findest du hinter dem Haus.");
if (GUILayout.Button("OK")){
}
}
}
GUILayout.EndArea();
}
}
}
Answer by Berenger · Nov 23, 2012 at 11:01 PM
Dialogue in a RPG is quite a tricky thing, and there is a lot of stuff to think before you start coding. First, note that I'm not an expert, I'm just giving you my not professional experiences.
I see your dialogue is in your script, that doesn't feel right. It's going to be hard to translate, to add new stuff, and the more characters, the more stuff to compile. I suggest you store your dialogs into a file (xml, for instance), and load them on the run.
Then you need a way to go from sentence A to sentence B. If it's linear (A, then B, C, D, etc) it's no big deal, just a counter and go through the array. But if you can go from one sentence to any another depending of some input (keywords ?), that's a bit more difficult.
So you see, I think your going too fast into this, better think it through first.
PS : Be careful with that cube, those guys can be quite obtuse when you press them :p
Thx for the hints. I wrote that little dialogue only for testing purposes. When the game gets bigger, I'll put the dialogues in a X$$anonymous$$L file.
Hmm I didn't expect it to be that hard to script a Dialogue with buttons.
Here is the dialoguebox of TES $$anonymous$$orrowind:
http://img69.imageshack.us/img69/2374/screenshot42fally5lr.jpg
As far as I can understand this, the Buttons on the right lead to an if or case statement wich then delivers the right sentence in the dialog-box. The two sentences in the Dialog Box are alternatives. If "Yes" then sentence "Oh I'm glad to hear that", if "No" "Oh Ok then..."
And a similar but much smaller dialogue-system is my target for now. :)