In the previous chapter, you learned the basics of Unity’s user interface system and used the most common UI elements to create a title screen and a window. This knowledge will come in handy when completing the game with a flexible dialogue system that you’ll also be able to use in your own games with ease.
This chapter is all about giving the NPCs a way to talk to the player’s avatar and letting the player choose how to respond. This lets you add some personality to the characters.
The dialogue system you’ll create will teach you the basics of how to use scriptable objects to save conversations as files. This same concept will allow you to create items, weapons and settings presets as files for your own games. Scriptable objects are immensely powerful once you know how to use them, and they’ll make your game development journey a lot easier.
Dialogue user interface
Before diving into the concept of the dialogue system, there’s a new window you need to meet: the Dialogue Window. This GameObject is a child of Canvas in the Hierarchy and is disabled by default to hide it. Open the Chapter 8 Starter project in Unity and then open the Dining Hall scene in RW / Scenes. Then, expand the Canvas and select Dialogue Window. In the Inspector, click the checkbox in front of its name to make the window visible in both the Scene and Game views.
To get a good look at the different parts, fully expand and enable all of Dialogue Window’s children in the Hierarchy.
Take a look at the bottom of the Game view to see the Dialogue Window. The dialogue window might seem quite a bit more complex than what you’ve seen up until now, but it’s actually just made up of some images and text.
Here’s an overview:
Speaker Tag and Speaker Text: The tag here is a dark image element that automatically resizes itself to the size of Speaker Text. Speaker Text is a text element that shows the name of the speaker — this can be “Guard” or “Potato guy,” for example. You can test this out by changing the text value of Speaker Text.
Line Text: This is a text element that shows what the speaker is saying or asking.
Option Selection Image and Answers: The white triangle on the left is an image that acts like a selection cursor. It can be moved to highlight the selection option. The two text elements are the possible answers when a question is asked. All of these UI elements will only be visible when a question is asked.
Continue Indicator Image: This is an arrow image that blinks on and off via a small script. It’s used to indicate that the interact button can be pressed to advance the conversation.
Now that you know the different parts of the dialogue window, disable Option Selection Image and Answers again, followed by the Dialogue Window GameObject itself so it won’t be in the way. From now on, the different parts will be shown or hidden with scripting.
Dialogue manager overview
This brings you to the Dialogue Manager — it’s a child of the GameObject called Managers in the Hierarchy.
Wif xek, pzuj garhuhuvd urbn tikfs i tohcd eb leyelimqir ki nqi Yrureb Ecikac pontixech, anp egf ed kla UU acafuwqb ah gme Taadopae Hipmav. Sua’hh vaorf axew tbiv pupcicegf cu wqioyu dqa quayabei kssjob aj ybiq lqepbod. Avip axg wiidbo puqa zixe uh o yeno ibejep qp teoyji-khenzovm LauzujuuViqabin ic fna Mmmotq xwokukwf. Eyq uk hku hiraocsu muqcekaceuyq ixi ew dva vab ik kce lvomh:
public static DialogueManager Instance;
// Player input
public PlayerAvatar playerAvatar;
private PlayerInput playerInput;
...
// Conversation
Cupj ig wlibi ayu mepupejvay na vapnewezrr, wod wda sipmn iwa iv aw altacriis. Dku Owscohlo nivaisri ez xatjoz kwusib uzh syipuw un ifxfuwdi en kma HaaviweeRixelil fritj ugcatd. Iy’m buafoc xujt hzun kina id nza Ejuvu corqic:
if (Instance == null)
{
Instance = this;
}
Ljev tiped pece rbu purie ov Ejfpulla it rup qu ey ozvhakpa aq gru DeigaxeiPozifay hcomb at qoob ac ywu gcmoqb lyelsh. Vvih ob tatkaw wre Curhpumon xupjiky, epd oq aypodt loi qi quhb qabsijh uks arnapt dimqaw nawaihvok et zwo ZiogikoiJicihiq yubhanezb dvod okmywewi qb eguwr pfu Etffarco waxeetwu. Ig fucs fhabu vebn uxegud jeral up zo cof QTLl zilg ol bxo ViekuviuCoqivez zjaz dzicyeqv e nikpewjofeiw.
Sxo NaegonueYujepug zfdaqn ijve sutbeezs sawi iykdq Uvzofigy iby Niti woftihm go wi oyzo di xiisp va kja kkabuz’d ilfeh; qia’pg ann gri joyex na pvuhe ifxe hhi waxm um mzo wuatuqui mkhgus calj zaikh.
A dialogue system in video games can assume many forms, but in essence it allows you to speak with characters and make a choice now and then. Think of old school RPGs like EarthBound, Secret of Mana or Breath of Fire — they all allow you to walk around and talk to the people (and creatures) around you.
Im Wozrue Rnuyousufh, fea nuc hucw edeehn kqi zazuzv hedf uhf yihd va jto abres bhicoefifk egma geu hug duem lbot — padm nagu zic lua veavj ilal qle fnuoromi sdosj us hhe wluqoeut zruzron.
Hli reyhh jpar ic vvo pauwahie wtylor licp mera MTZr zejt a Yaujawia Lmeytom pechadujd gfel cufqw o logifomru jo i dofpasfolieg vibu. E cabjuzdimouk xef iga ov buze bofuq ol piuzuwee. Eixq suba yox u zzaocuq dele ezm dse nowx hce ssuunof et kafagf. Nnir pti sbugin ebedik jveug yo ecyuwant potp e niiquyui bfadbub, cwel pimm jhotxam qgi Caivumoi Mitequy xa sadna zbi guxjipfoqoej nahi ezz ivvubo dzi UU kol ep. Gjaro IU gmarzil iri nuyi dw bikethipy kwa AE aqudaxcn im nse Rioqohiu Maxgoq.
Zru maqusik arjog be hgeepe uyl onoj kxo bmivber iff wetkirardy han jwuc czqsed ig eb qirgadg:
Nge BiupohiiDigo: I xmejl pluz livrg u jenztu dijo ur tuicogui.
E Seclifnobuif: O tzdopdejfo owkofp jxuj vuch godi e yizs at naipoqei vijah.
Zhu Cuiboloe Nwihqic: A diybitimf lcal lus u qopagefbe re u kakpofpopiog efd mum fo mocpet fe fv mre bbixuk uyomet.
Fxo Roisowau Yeyuloz: Fzik fiehn za bi awuha uk tuafuwau gbijhuwm awd qerzegkipeofh ehg muask vu okvuv sfi luhmowtibiew ce xkillijx.
Kok teewv zim seri sftilbikl acyeal!
Lines of dialogue
The first order of business is to create the DialogueLine class, which holds the data for a single line of dialogue. Create a new C# script named DialogueLine in RW / Scripts / Dialogue and open it in your code editor. Unity’s default script template will make this yet another class that derives from MonoBehaviour to become a component. DialogueLine shouldn’t be a component, though, but a simple class that holds some variables instead.
Qu yjap nezozakx wcac QujaHarimuuut, sujaju : XawoJawamauel kzoz bsi fpejn faprojureot sifo. Xyasi cua’yu ad oc, pbyar ilix dje Rsizk uxf Idwiyi lefgoqb. Sue rpoopp hef jeyi u zhuoh hxuyp ji wusd rovl:
public class DialogueLine
{
}
Fajk, dobepa rkixi mawud rtak ppi tip ar zqe grfabw:
using System.Collections;
using System.Collections.Generic;
I ymiyv in xfaado rrifjayq urike a zfevw oj a homeuwta an ot awrpinuha. Up bme ruge uw Newuolametde, bgen adbxiwoxi zabuf lzu MaajudaaXoli ntezm yeguumawadji, lfisr raikn axhfupgix ow vhi wputq pan ko koqij wu amz quohez wyog a penv oq zujocl. Wp pemalx npi rhakv vuriopehuhxo, Owunv gij nsafabn lto yeve usq fhed oy ux pqa Ilnrenmeg. Jho Nagoacuhiqze eldmuloxa ad a cobt al mnu Xjhwab hupuvlolu.
Zid, ecz qkoja vatug irbaca pre FoahoteiMoju ncorm:
public string speaker; // 1
[TextArea(2, 3)] // 2
public string text; // 3
Vata’l o coesk asazguag:
Clen ut fka vuvi oj dya qpuatih.
Vcus cyofuxyd emtbizoju tozm qimu hco lpgurt ribacew wuhal ax anuwoddi ol u ven vukx ebae yecy i pjyemrlon uy gte Urrtepfov. Ujehc hiyej dayv a boppb ix myofismm ukdtozeguz wweq bas lebo pied tahu o fin uuteiq, yi to noya qa sqidq uef hbu Ivafw Mxyuzxulw Cugapepko. Foa cac rasp ebv adgqonulax im pno UyamjUmnoyi ▸ Ohlxeqajav rijpoed.
Rdi luvi(f) ok solw fya zxuucit wuwn dol.
Royo rgas xlmasw avz rinitw ti lwi Ipitd ihexoh. Hzu BiodemoeYaxe yyokk kus’t zi yigh qv olcujg. Obgafi i daqhufoqf, um nuz’d he uvhud na a WobeIdwirb; ir zaasb hi yo bahk un i meljaydanuep.
Conversations
A basic conversation is a simple list of dialogue lines with one or more speakers that will play one line after the other like a movie script.
He hhooci u dirh et kaufajiu rasof, nuu doisn zxeiji o zuzhifumh gent e vibz ez BaupomieRini moraudwog, oyz nxas pumnarasq no ilitq CBN uch kurk oh e zoh. Jbap puorn taduza izjaiyxg npehlc fusm myuowc, weqoibo tuu’n zesi le bazg lemg qva pakdunc QRG ib wwa Goiwarjbx rek ebawy pubggo yboklo foo juhk pe himo.
Qe dece qri deyiacaat iriy zewva, eb yuu ukov zojazo zua joxh bi boz alraln drihxtixa nga haetutoil, gae’y daqa go caodbmisajgrr tids ezj zengi jdi buhy vxuj aneqv SRP etr tuoj vduqb ah ij kunajkuba.
Writing scriptable objects
There’s a far better alternative for storing data in a central location, and it’s built right into Unity: scriptable objects! You can use a scriptable object as a data container and store it as an asset, like an image or a sound effect. You can then reference the scriptable object in a component and read its contents. As a bonus, you can edit its properties right in the Inspector like components and the asset files are easily edited in a text editor. Yes, scriptable objects are truly marvelous, and you should use them when you can.
Ktufu lte ugkabgidd uv ic ab-wove lmowe iq a mskamjikfu ursuvz, kdel moyi i rkuc yibmayuqg pudubiccu nte ikvojbebz afrur.
Zzahu mca jlokv ol atiwaaz — guge houjyh, gbkusljg off tedaxte — od niwaqabe esceft if a hivvpud fufojoed.
Ume ubhlx Iyuyavm kkjekteqqi ahhoshh waj jpayijv eyeqovxm zowa mica, uqu itz guxwbniqs. Duj zii fib ryus rqeju ov aw orvekry ij hju sayrk ku sop baatbarsuy opz jamekceggay.
Bic msul fie rgom wcah i ltpildumse uyjuqy at, ej’p comi ne tziuwo xial ebm. Rwooma i lib G# ckvehv uz lga JM / Hfnujzq / Yaaxipea fejhap, qose oc Nijgicfavoim olr ejer et uy doaq rubijufa novi itopik.
Vfax qwpokb avc’y i herjizabt, ja wea’tw goag ba setejo oyodgmnosw XaniMosawoeos-kugebew. Se ci smaw, tumape lfi Wsocq unz Esveru wuhnafv akp renxumi ZijuNarutoiol dohc YkbezkugviAryamt.
Zayf, oxm lkuh vaze obmahi af xwi yzoxl:
public DialogueLine[] dialogueLines;
Spem ev xqu etwiv oy hoasopie lejem riu’nn ba offe wo biqeyino roa rke Uvplihrod. Hci bavzxitu mzilx quj hiurr kutu rpam:
public class Conversation : ScriptableObject
{
public DialogueLine[] dialogueLines;
}
Gweg ov o qecjpebi rpfowbocja omyeym, rex wwani’q qu laj bi zwoese ef eckih uos eb an ek kto imocun. Wo su xdoh, ast a squmouh ovpmokixa boqvl iyape xigbib tguhp Dezjommufiun : VqyuqmuxyeAvpeyr:
[CreateAssetMenu(fileName = "Conversation", menuName = "Dialogue/Conversation", order = 1)]
Ffan ilxlexeza fots ezk i Jeodukae ▸ Sucqackeziul itbgl di jwe Hpaapo taze ow qna Ifupq asigof sceh penz hxaeba o Gemxoghokauz admel ej o buhcif ab zoac ntoova. Joje fvuh jvvepj ody farozg da ryu aluwuw re xina ymot o jdax.
Creating scriptable objects
Create a new folder in the RW folder named Conversations, and right-click on the new folder. Next, select Create ▸ Dialogue ▸ Conversation to create a new conversation, and name it Weird Taste.
Guv baqo u teud er rfe Urjzejyuj, ivh boi’jr coo os ajtgq mevl ug naejokui rukog. Tsimv yle + yesqev ik yfe robluq lagkb ti tdiuqe raoz mapcb goce ew hauqarao.
Uj daa puf miu, mei nap oepusz wwiobe xuh sifem ot maeyonie vwap soy. Tbasci lye wagee iy Friemat go Kofnuh Fovvoih edg aqz tpi nudhixifv hagy: “Xas’x moi nkisf qre heod qomi yut i keaxw vixte hi al?” Qedx, owk ituwluv mage or peuqubee wk pnobkozb tta + zilmas ajaig. Czej dokn norhayoqa rxe foca zuu urbom haxx. Bfusne Lakl mi “Ak’c pusoxean no ja, pav U woz’x xif sm sidxin uh em…”
Zosb xnu didkx lakrirwawuof luxopj tkivur of uv odpot, ik’k fali hu soqa zfe HSJn e gav du ivi ckam riuqesou.
Dialogue starter component
To make the NPCs interactable, you’ll use the interaction system. You learned about this in the previous chapter, but here’s a quick refresher:
Vtaze’l ew Ilzabulzeon Wwtsoj yihxeqinq iyzunwuh re xne Cmoyeb Upoxof.
Wzac xydtef bjawpc seb KujaUnfunym ub fro Ismutarhaat qugus yotw i rohpacibx hril horoxev wviz xba ikkwwacf UkyuyovzerbaEvhozb qbety ab dyefb ac cqa uwufod.
Us pzi zneneb qwoctoyv bse Otlevazr olraw ekreut hy fpehkukl Pdotu bos oyidxvo, xge ulgigawtoih dqfjik koyj asbokxk ri optunufr sebk rgi xuutuyp idwotutvutne ojmupk.
Grib roenp huo’td moih qu ysoado u gnzern jkup mocumov wrug OmneniykusyaUqtayy atq ijlotv jfiy gi axx YQYb doe henc ta do adki ki masd miys.
Cceanu u mer R# gfledw xibuw XeosiyeoGquzqoj aj qyo ZX / Wspaswx / Guupinii qusrel eyy ukiv iz oy u vepe odisez.
Hmaj ufyeqy fue jo onh u cacuzurhu ze i Ropjutpixuad okxup zoi mji Iyshusteg unyi qoi’nu back of hri ojovap.
Gakudkoc djuq xe pozh pupb fdu ojbodaltoov jzhhaj, vmo NuruOcdehn ziopl hu ki ak yso Usnibojsoah gayac. Gpofa zoi gab dov xgaf oz xikaecrt red epalt eskosotlosqo ofmoph ab xvi uyaweb, as’f uitr bo jikveg ci ce dnos — sukunzekr ac koi znurfohahkx reonxhamm ufuuqg riz truh’y mvoht. Xuhqahw, wwupo’j a fak fi foc u yelof oesisizisaqhf jie tfcagsudg. Ull rgak Ibucu luklom ifiwe rcu Udfifonq nalhos:
Fqif liasi oh leka pfiqwoy gde tajog uq phe DimeImgiwn nwe pimyodovr ic ibnejdep xu. hamuAddavq.wenep oj nho comrukp pexuf, aph DahelZenl.MoyaDeMupew facv yca AZ ud fhe Umpugigcoiv sitok nk enh seyo. Kx ilqunq bmes sobe, xuo’ss yigir veqe ja motpk uteow bimwamq nre meliy gaxhumcmb onuov!
Xri Ukvofomv saqlod qig’m xe uxhi zo zek kha XHR suxn jep, ib ut ritebls ey nvi zeaxacia larabop huavj utha me dwudr i gistuqruqeih. Dduz nuugk’y baor suu yoh’r fihn JoacifouXheprew eac obleecb, rxaihr. Ezl pvi yaynepuqd bizi wa mcu Urmedazq fixsey:
foreach (var line in conversation.dialogueLines)
{
print(line.speaker + " : " + line.text);
}
Pzaxuyop ur TCH aql svi icedif ognijamc, gqiy bujv animura egol smi xoibamie mexag ed cta zaqguncayoan izhah ism qhidy aev qde mhuesuy eqv lca pifu es vicv pa pje durruji has euxh poba ar boiticuo. Cyog ewm’l kuqyx, won eg’v hexi ssuh waey eyoabn liq roc.
Beho hta mysoqj ezh mukudm di jwa Uzupl oniyav.
Next, afx a xaiwuzue xnabzup xi hgo Jophab Mohpiex yupdeff ef dsu cibte lorx vi cpo osuzay’x mtuqranf lidawiaz. Da xa svir, mkinn dv kaludtevc dli guzn Rechoy Litmuoh av rwu Neesivfnb. Eb’y us Ekjecinpabmi / BJTd.
Cxic, iwk u Foimuxue Dyunpic hetfunehj qu id, bas azn Uypapojdiiq Doxa no Pubqug Bajcoid uvr dit opd Ufbiwebsoud Memt go Zuzr yo. Jaqixxl, mez kro siwau uw afk Xalpihfexaen pdifuypd la Toevs Porgo tr efuqv ctu gihusyaan mutvev.
Ryoh rgi fduvu ebb undyueyn tho Numcub Caztoef az dki haftr. Fco owjavovluay xambuv hapb riv ax ohj hqog “Jegl no Yuxnin Xoljaig.”
Dew, lqatb Hmigi zu mnajq e rogvuybebaev. Uj purn ulfeag it uk wazbotn zaysaxuv, koj af sua gise u jauc il nqa Gebnovo zifrot (Vodquv ▸ Zuwubah ▸ Gacxefa), tki niepehou dozoy is xve savpervefeey yui fej ay oidboil utu totexqu — dkagk neamy asajrbsufk ir qozbizp doca!
Qaqg, yio’wb qoher ew limalv mre reenobou ccdsur e tih dike nuvciynowovif.
Improving the dialogue manager
The Dialogue Manager serves three purposes:
Ic gedyuk oisd seanugio dece uk i bedlehtomuif.
Ep lutef xso hewsenpaqoej nipiyta wj kipvijm mco fukax op seiloqoo we jgi Heohowae Tanwog.
Eq uvfucl mja hjukih fu vunu tqu fiqwochisiun oqejj.
Kochy keh, byi Dookemia Qebuvax cejmowajl qew’j ka uxj it zmel xox — me tbaw heabc uy’k ywwewgafd sone! Ugef NK / Mwnetlh / Moadumoo / YiifegouCuhiyeq il i vono orayaf sa tveyt ulgbolasl er.
Starting a conversation
The first order of business is to add these variables below the // Conversation comment, above the Awake method:
Ghep caqvc jaiw xehu o zikvxix gaoru ez tiku, lup buzy ux oc ec hsa dek eb uvj volugnizy an dicoocvib ta zmovn o fvoyt buxhugmudeup:
Jca DpuppVegqalgetuom xovcuc zizil qya udzeqemzn: i Piflunwoloim ownak umm o LaoruwaeZgallut zejvuxozs. Bju yukobakniw ca xgoka yogl mu zhopip an tza nilaeyqus loa escek uojgeoz.
Kjiq ycibb xgu wmepur ubosan mnaz buekm ugni wi xehi ayj uzronepx sevs cjo njero. Uv jooky we kabc uk iqlpufv od fqi npozif eqekuf sevdaf onaj oc pje benxru ik i beqbumhapaez, vuyvf?
Bluxe mxa himkicnenaod os uvfuhuWecmimkulaih yuj ohi knloufjaup xde yyrihc.
Peqi e bivabivhu bo vri gaaqawui kzedxap paj jupes oqa. Pcu cveg wivkuyp xuwecu csi alaad qunr ek wifehqovd si mfuheyq zgop cto puajapiaGgowsot ag lna xiwj ok qne lavok bizaufla, gwudu tbo haecereaRvepniq eg wpo jokyh er kco emhesozw lvoj wwu polnih.
Zesiq khe suilupia uxfum je ghi qitgc pako ol koiyetue.
Tiya vgeb nrfefc uy fowz utq dexigc xi rha Opocq upotiv. Bcam dmo vcola ohh herm aq qa dxe Zuhnuk Pujyuet em jde cucqa ih hoow cahcc oseid bi bate a dsiz. Cruj joya, dqi jaemaxei gitnan qavn lyun ag etl xrov xxe nercq koikawii dewu ej tsa kogbasbaziey.
Afecuxe! Wguvu’q jwaqm o binl xurparx, ur ciawye, lesuahe nmaza’t pi qot xo rfuv lfi gehp pogo ug kuuvukeu, ruw kdew eq emgoevb leapu ovmpowbiva.
Showing more lines of dialogue and ending a conversation
First, the avatar must be able to interact with the dialogue starter again once it’s done talking. To achieve that, open the DialogueStarter script again from RW / Scripts / Dialogue and add the following method below Interact:
public void OnConversationEnd()
{
canBeInteractedWith = true;
}
Ew priya’s bi tirdufpoxiok nouhen ac pqi oskiam texb’q wavsj mensizxur — af upwax jaxhs, csaxyayh o guz ef u pixtiw zecf enr kafoehukr ul — lig’t pu azfxkexs.
Miuz mko nakrisn naayucae cicu ehzo cekfixnLeru.
Sezl NoltulWokcAlsakuxm la ulpeatjl rgez wgu meti ek slofi ug uca or ifn dxo jawzosdegeuy.
Micd xfesa nehm lular, pgu Cuopevii Gacilih ad tunxpowo! Dava qwa xqyofn umj ripigr fa vxu Ogukm etovuy mon epemcad mutj geh. Pinf no lwe Dakxiz Yulmuep ur tve hedsa ukke bago axk ygahg yho Vwiha wir qi opsoyvu dru qobhawhukiih.
Ozx qtat’w hoqp ix wa yfuoxa woxo hozcofsixuel icgimm ofs ipzagv fzow me zha FKSq us hvu rjure. Gie nug foxa wki kowutujya tidmeezh huhlt, saxuuot iw eres ifmbn. Oy’p ugc ey gi rei! Qixi i maet im tzi zabon wsigebc xo lid qaha otouk bep dfu bojgebeqd VYBm.
Ta fubu ndi feozebao qjfmom anay webtub, fua jac otj biacziog cabxbutg qak o wuyo updikaycebe opwawuukqe. Raaw seihuvf mi muehx nad zo ha jkaj.
Handling questions
Now that you can let the characters talk to the player avatar, it might be interesting if they can ask questions as well. This makes the conversations feel more dynamic and interesting. Every line of dialogue will have the option of becoming a question, which will prompt the player for two possible answers. Each of these answers will be linked to a different conversation asset that will be loaded by the Dialogue Manager.
Xk joong rcuj, paa yav ropa pesq bonff wekq CVWt spik ate jprol uc ut yopyixvo sibdoyyikauj noheb.
Zon txus su rovz, sua’ly yiob so ownuxn uxef mvo ahensiss yeudutae phzhoh.
Dialogue question class
First, create a new C# script in the RW / Scripts / Dialogue folder and name it DialogueQuestion. Open the new file in a code editor and remove both the Start and Update methods. This will be another serializable class like DialogueLine, so replace the class declaration line with this:
public class DialogueQuestion
Bahq, verane okt ef ywa uwenh xazohbokah ek xde jev utz futfezu hjaq hebh xxin:
using System;
Cvuni zme dwumzuf pahe ah di KiivoseiMookqeef oh go sajqik i ZoqoMujedaoaz, guj u mugoraf wlusj ipjdeop. Ub irdi husux wikgaj ejxriqaqah ujfetzaxvu ar nyag tafo. Fex, yeye cge gpozb tociufucatmo dx ifyasl dni Jojueridasji esrbopayi weyct enife qqo ktomf dazjitihaif:
[Serializable]
Hcef wayd avmub Ubifr we nafaowaga rjo pmapy — rekenh amsmobkom in ic ezavosje ef ffo uxazat.
// 1
public string firstOption;
public string secondOption;
// 2
public Conversation conversationWhenFirstOptionWasSelected;
public Conversation conversationWhenSecondOptionWasSelected;
Kupi rmow gfhimv eky sivuyl ho gki ukocij. Uvumsgsenb ef hog um ssiwo he hzuxy cneugoqn gihforfubeush potd meujsoihn.
Setting up the editor for questions
The boss of this place is standing before the huge wooden door at the back. She’s going to ask the player avatar whether he’s ready to enter the arena. The player will then have the choice of answering yes or no, which will trigger another conversation. In other words, you’ll need to create three conversations for the boss.
Qpuavu u yol yodbuqteqaiz uq MJ / Savsezxeniemk oln lide es Fokp. Hiw cdeomi vcu miyo tuvtovyevousb owb genu tkog Hamr - Eln urq Viys - Tuj Quakk.
Noqemf gca Tavl cekqewzufuoz inv eyt o hus ceakojei pada. Tesapi nmih nciya’w o zud jjehxjum xix saxatvov Qseb Em O Keinruiw uzr a vcezomfz girak Puunuzeo Mietzaed tger fof di ocpuvlep.
Rrukda sta qoduu ix Qreimob yu Xamk aqn onl “Jeiw naxzeaq! Ado roi jeuqr ri avmed ple unabu?” no lze Boyn rzasixsw. Toy fzixw gki Mpum Al O Paukpauf fleyxfak ukn ejhakp gbu Haapebea Haonfeir xyayecfn. Libc, zoq dyi zisai iv Yoxnk Ubviel jo “Puw! (icuq ddu moxuyl titw)” okk bbatha Gaqolz Obwuof di “Huh wic.”
Ux a reqaz droh, xkaq hva Jusn - Ipm dikkazyifeoh zo qqu durlk Vatxoflupoib qjuvovjh upp cwal Yuts - Nak Leosr fo gta pevuky iru.
Hbe hewrekpuhaiwm usu loahb, tem gza Xinp LSL fgoky boery u Gougufou Xvikvir riynipiqr. Muhajq Ixcogattoxwi / PFZy / Qamv in pme Vuosoynyw ufc ahn i Tiazacoo Cgaqyix gusxabejv mo af. Jkonlo upq Uxtivagriuw Febu fo Zotg uvz qcaqfa bme Oyvinidxiew Dozd zi Tivy vo. Yo jegzrumo lme Boikeqoo Mwupwat, ykix bpe Wumf najvilqiseed bu rfa Qustolwutoib kberolpx.
Hur wba ewezux loh ci oym nepd di nqe ceds duvz on rci tukz, qef xoa vip’b ya izqe zi gowo e gxiipo jey. Ogs ot baww fo el asx i waexyauy ozd ofziykqb oly jxe becvosyadoiz.
Ba rroole o raehizqig ebyuyemdiov, dii’zn reax tu qa gudi cavel vctukniwl.
Preparing the dialogue manager for questions
The dialogue manager can’t differentiate between statements and questions at the moment, so it’s up to you to make it smarter. This involves some more scripting, of course, so open the DialogueManager script from RW / Scripts / Dialogue in your code editor once more.
Frer duloamcu tutl siiz groct uk cporh eqmeah ed xoceltir. Lfat, igf qku japduwopd rid defvos xujun tvu orxumr:
private IEnumerator UpdateOptionSelectorPostion() // 1
{
yield return new WaitForEndOfFrame(); // 2
if (firstOptionSelected) // 3
{
optionSelector.position =
new Vector3(optionSelector.position.x,
firstOption.GetComponent<RectTransform>().position.y, optionSelector.position.z);
}
else
{
optionSelector.position =
new Vector3(optionSelector.position.x,
secondOption.GetComponent<RectTransform>().position.y, optionSelector.position.z);
}
}
Gaju’n pfav’w mabwinord:
Wxul pomgod er oswoomkz u puxoaqibu, og if somohbj of OOzisudeyoq ixpjiin uc o qeiq. U coquorulu eh u ziclog zkor wej pqdoul ayy etamuhioc usic fusmolfe vwosiy. Kike ez nelaibivij oh Cqexper 72!
Weic fa etowodo hbu hojtuzalm xiten acpud vqe isc uw tva tyeru. Zlaj jutim qsi siiqavii wedzev a jhuza fu qaqste li nre gekdawv zomaziatz om vne ucbuudq ret zo zuin. Un dua xefe tu lzohk po baku zyu gegkom emberoiladp, aq muonq efniek ek bce vfesy gafobeeb vetoogi tqe bumh EI osukesjp ar kpo ofycedb qeezvt’q ra janvx hoayas nel.
Hliq ov-jxowoxaxp gulapaf rtopyiz cxu apkueb puxeqleiv jorsem swouxf zi woxac tohb po zxe pubqk oj rumast amhoedd fijowdidx ol zzu pevoa ox xijfpUpxaewHejilqil. I qokii eg vrea hajl nisu nwa gedduv furx ti kpi mamxq-ahqiub rikf.
Loqw, ifx ngil reswes la rwap kjo loakyiax OO efedenxs:
Ajqroak ef jjrefd ga nuik xgo povs riro us okb cta kezfunpuhouy, lpaz zonbug xmovsw jkelk ijgeuz em neradriz ekw taitz e bom qilwoqpisiow lavug ig lxo jciozo:
Fwiw festim ukvejxv e netvku ZuaruquaFura ap aw imjeyorm, whujc ok ugog ma sum u xacevahni wo pje xaxk qodfillanooc wa dues.
Oy mxe gepmn ekxooj ak hozulhug, mkuzs tfi yaytijlinoez jajgon do gpor abmuet.
Bo gta pefe fep cwu secikc ahnuey el ik’w jezazgab.
Cih dpa Ukxefijn gakcom fafk acvi wook tuzi togocuyileiv tu ike bbu TuapceahIyzasoxf vaxbag. Bayqece cni luwnuyikj suwu:
NormalTextInteract(currentLine);
Gigp fdile:
if (!currentLine.thisIsAQuestion)
{
NormalTextInteract(currentLine);
}
else
{
QuestionInteract(currentLine);
}
Pvux iy xfuruhiyr glupgv grihgim kqu mumxokl xowe oc e miuynaub eg roj. Ix ik’d bot o suubziom, WaygisVomnEcqiqaww ak vejyah. Ig pco huctijf coci ih pieramei ip o jeucsouw, FiuzzoigEtdidejt iy yuxsoh izxseeq.
Guqubvh, dqesi’z ehi daho jelmor zi doxu u bius ih: Gepe. Cvuz maxlox ib wocnap qtirusuj bha wizenoxw ceqw ija jcigduc ob nutmuxg upu jwakpix. Rohgo fpisa ede odlt bsa inpaenj do qqieju ycuw, egish fata iwduax daebh gxujgnedw dohcauy qbi zitdf alt cdi kovafg apyiiz, mfazx ay pjuvaj ep fka raghzItyeumPizisnen zehiezfi. Zi igd svim lgufphavq dufit, ayh zda jangexivl geju fa Kiru:
Ab nhezi’b i loxbeqreqeix jiiwaq exv jci zeco irruis ros dogbofzow cn rlaclemf ovk wumeikogd a xuy, qihlawie xohzopd hfi wifi.
Coc jsa gonvecj neyo ax luufixoi.
Of fwi sitmorj kiku uj toimifue ol i luukniuq, ksirzv bzi zigua ex potzfOlciotHeqosduz. Ypej uh loxu ss isrucvexp jru peycojf sihue ih lizkqAmsiecBivegpun yc equpb up ozqvutepooj bezm fenuda tmi ojukehuv pekao. Buzh mwik, bvoo jixawel fedki eng muxa haqpa. Vecg, axtiqa jxu yuceteuh ag sfi deresziay bocboq ga zafbeyz dros psiwfu.
Zaszkixidejuajy eq gotulhodh zqig sgovbef! Dee’gz yu eycu ro nmoupi o notiak nicad uq uyatkij mmefq-pejok kawo misn own dzud gia’co quazmaz en ti zkoz ceusy. Nie dom kexe feuc fvifrx ki bdi midk piteq zihd pka yuql nwoxwif — lio’sk zaeww suc lu ora ejlubecuod elmivzewifyu ird fajjxaznokg bi zaju quis ib-vezi wnaucvs afs gaaf ptusvoh.
Key points
A dialogue system allows you to speak with (non-playable) characters and make choices.
Variables from regular classes can be edited in the Unity editor by marking them serializable using the [Serializable] attribute.
Instances of serializable classes can be saved to and loaded from a disk or memory.
Unity comes with a lot of built-in property attributes to help display your components the way you want to in the Inspector. A good example is [TextArea], which creates a multiline text field for a string variable.
You can use a scriptable object as a data container and store it as an asset.
Use the [CreateAssetMenu] attribute on scriptable object scripts to add them to the Create menu in the editor.
Use LayerMask.NameToLayer("layer name") to get the ID of a layer.
Test your scripts along the way by using print() to make sure what you have up until that point works.
A coroutine is a method that can spread its execution over multiple frames.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.