x


How to Script Character Dialogue

Hey all, I am working on a game project for school. I need to know the basics of scripting dialogue between characters in Unity. Simple Dialog boxes would be great. Are there any tutorials or resources for this? And I do not want to pay $100 for the Unity Dialogue Engine. Any help is appreciated. Thank you!

more ▼

asked Dec 06 '10 at 12:43 AM

katie88 gravatar image

katie88
36 3 4 5

Suggest ColdGUI, add an image, add a text box, script the text to change with the image...

Can be mildly easy...

Dec 06 '10 at 12:56 AM Justin Warner

You could use Questit. It is available at http://www.svenparoth.com, but it costs 50$. You can do dialogues between a NPC and the player if that is what you are searching for.

Dec 06 '10 at 01:16 AM orphea
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Have a trigger with this in

var images:Texture2D[];
var voices:AudioClip[];
var subtitles:String[];
var maxDialogue:int;

function OnTriggerEnter (other:Collider) {
if(other.gameObject.tag =="Player"){
other.gameObject.GetComponent("DialogueScript").images=images;
other.gameObject.GetComponent("DialogueScript").voices=voices;
other.gameObject.GetComponent("DialogueScript").subtitles=subtitles;
other.gameObject.GetComponent("DialogueScript").maxDialogue=maxDialogue;
other.gameObject.GetComponent("DialogueScript").enableSpeech=true;
other.gameObject.GetComponent("DialogueScript").StartDialogue();
Destroy(gameObject);
}
}

then have this in your character controller gameobject

var images:Texture2D[];
var voices:AudioClip[];
var subtitles:String[];
var enableSpeech:boolean=false;
var comboPointer:int=0;
var maxDialogue:int;
function OnGUI () {
if(enableSpeech){
GUI.Box(Rect(140,Screen.height-130,Screen.width-300,120),"");
GUI.DrawTexture(Rect(150,Screen.height-120,60,60),images[comboPointer], ScaleMode.StretchToFill, true, 10.0f);
GUI.Label(Rect(220,Screen.height-120,Screen.width-230,110),subtitles[comboPointer]);

}
}

function StartDialogue(){
audio.PlayOneShot(voices[comboPointer]);
yield WaitForSeconds(voices[comboPointer].length+0.4);
if(comboPointer==maxDialogue-1){
enableSpeech=false;
images=null;
voices=null;
subtitles=null;
comboPointer=0;
maxDialogue=0;
}
else{
comboPointer++;
RestartDialogue();
}
}

function RestartDialogue(){
StartDialogue();
}

You could easily edit it to support the player saying stuff but if you want simple radiochatter with HQ this is your best bet. Just put the images , voices and subtitles you want by the same order (e.g Smith says hello , images[1] should be smith's face , voices[1] should be smith's voice saying hello and sybtitles[1] should be "Hello") And put the maxDialogue variable to be equal to the array sizes (say you have 4 sounds to play one after another , maxdialogue should be 4)

more ▼

answered Apr 03 '11 at 04:03 PM

YeOldeSnake 2 gravatar image

YeOldeSnake 2
1 2

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x141
x52
x41

asked: Dec 06 '10 at 12:43 AM

Seen: 2824 times

Last Updated: Dec 06 '10 at 12:43 AM