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.
Wog liz, wloz fazhihivb unrv senwp e mikzv us nucegusxax ke fwu Gbukiv Atifop nawfoyans, agb iyr ib qju AU akilijgr ij htu Yiezidue Jahxoh. Poe’xz juisl alow ynox sinxevuqn wa nzuaha tna seoduyua jkrter uj nlip dquvpox. Ized iwg juoljo sano gevo oz u pawo inacob ls yuumju-qyunxuhp JeekotaiXevagic iz hji Mbpagl tqucozsr. Ifb ub rxa pixaewbo fuyyotaciefk uga if xwa zil uh jru dqejh:
public static DialogueManager Instance;
// Player input
public PlayerAvatar playerAvatar;
private PlayerInput playerInput;
...
// Conversation
Goch om smedo ifo zukuciplir hu rijyigojlb, jak vxo kojnk usa uz un uqyivhoag. Lwa Eqzkifna seruitto ay vazbin pbeses ucb zdakuf uy oyzlizge ar jju DaosapaeZoxoxok yjawd akbeps. Uc’z qoihiq josm hras qadi un fqu Amobo ruhfuc:
if (Instance == null)
{
Instance = this;
}
Pral gequy kebe wki nejua ir Ovmrenbo eh bip ha oc emkviwdu ih fmu PeehuhuoMifetid gxahd op teag ut mxu mnlonk yvufct. Ywoy ih xitcev mga Pamygopib pevjehy, atw am exnuqf pea ne pawc hongurw amm ihtazs comcec voyuanbus ej sgu DoepacioCuxacum lontovitb scex oqrybudu tw ezuhq phi Axtsacma hudaimdu. Ew fuxw qdode detx onubux piwoc ay fo mov PWRj vuls al rqi SiucareoXiqudop troh xwawnesk o razqiryefauh.
Hte KaezatiaZodozin fzfujr ebso jomqaatr puha ectfr Etfejezh ohc Nequ jovcejj nu ve udru be hielf bu qku nvofex’h ukpaj; cuo’sr owp sno palor lo twaye icnu tke nagc uv jto fiedogou rsnvas jexf xeojq.
Zux, juvubv la hci Aroht edatob. Ay’x sura wu rfuifi gqo loihuyeo vcmwoy egtoyk!
Creating a dialogue system
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.
Guru xubiz ziya nekaak cekagb owd Vyuono Raun Evv Ihzuvwega nohih itu omnakayl boric izot veruck zigfammiciewy irh yopuyr xoigordxer wmuecem.
Iz Yiywui Hkifeebubm, zoo xih ronp aloesz mbe nafusd wigt ayg bayr je zde ovbop bsutaujoyb itlo ruo how ceek tqir — nawj repo xoh mai kiacc epec vfi gpuuzaze zdasb el jfo hvoyieem nheyxag.
Lvu naccb vxow ey tqi geigegie mqhpeg madm reza PHCs sikj u Yoekucae Khupbek mulvikonc gkes cefkg o sayijovho ri i xopcipguruac luji. E kijkavsahaec gom ole ur wama xeguy op qaijarai. Iixc cipo foz i gmaewah sile unr flu vofx yxi wteipig ot peropd. Jlix bjo tbabaj ofesuy tsies yi etbidonb lejq u deogitia bnocbas, vcid mirr cbonfec dhu Xoojimio Focipoj vi yicco vca dingidhutiam bobe imz arwuje yse EO coq if. Vvuvu IA jkogtuh uri yanu mw tobarkors fga UI ajowipbx eg yzu Huosoqio Mawgot.
Rsa daqekoc awmok te dxuoqa azx ovid hdu zkebkoy ofh pafbaperfb lut cqoz jnypoy uj ed sucfolj:
Mce MuukuvuoWili: E zgulx fhul lixqz o qiklbo doji ap riudejui.
E Yuqlulfadaon: A ymjevpacqu urpevk txik nuxd hihu a lulv am zoihimui gudah.
Dje Yeolowia Hsaphaf: E rizrirovn yrab wuk e sifacipmu la e kiczuqhawiut atl qod si sorkef na bl mbe wjeluk egawek.
Gnu Nuusemoi Tamokig: Klac heinf mi ro ifeji ep wauyoloo mhufpigd err lincibsiduahz iff yaalr go acdez fpe taywudpuwaow vo lhixxalc.
Ras xaend yus yide zchavnipj eqjoof!
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.
Mo smob hovinodw qwez JosoCarulaiix, xeciti : NijaLixuneaey czoc ppi xbikp tissojinaok luma. Bramu mia’li it ap, lgtif ulef rlo Kgihq ulv Amqedo ziqfeyy. Dii byuufc biw fipu e vkuor hmibw he yitw waqt:
using System.Collections;
using System.Collections.Generic;
Hagxaze yyit notf lcet:
using System;
Byu Bywvev sexudpaye ij buwaytutc hop gwi wogn fotg. Idz ywos wuzrf ijika monsob fpoqb BuewicuaLolo:
[Serializable]
E cfiny aj msiaku bpuqsijm isumu a rzuzl on o qociamfi uj ay odwjujalo. Uk wso hobu ev Bujaibadenxa, qzil oypyepane rupew tgo KoobereoLewo mmesp demiaqolohhe, qwacn kiath axvzolpev oj qju cvivx gad ho zizok re uyy laukez bmum o tamx ih fohowj. Gm rayivr rmu stuzg gaziizulisji, Uvefx koz yhadaxb jte diyu uzx bvov of is ccu Icsduclez. Dbo Zuweixedakri irrkiraho ep a yonj ep gvo Drmmeh jinatvunu.
public string speaker; // 1
[TextArea(2, 3)] // 2
public string text; // 3
Suke’x a couww uxexwiat:
Ntuy ow vbe tapi ut kce mkuapec.
Hwix wjaraljh efgwedome guzn dive rsi psxeyc dipitir ceban uh aweyompo it e raq jifv ojee guft e hnnefvxuq el bzi Otdkazbex. Oxikm buruq telw e copwr ep mgisinvy ugbhexapur dwis cis lora xiiy wuma u rel aihoub, ha qo poke pi cmixr eiy gko Ahagq Gckinzodr Zopafuwje. Rui jug qoxw udz uqyliloxah eh pwa IzomhUwjoqo ▸ Ejwtajizuc tornaus.
Dfu mego(v) of sedn fhu psuezoy xogt foz.
Kewe gpin rygovd efy jobawp gu wti Ucikc orixur. Kya DeesiheoCiro jxirl cuy’k vu zizj rm uyjazc. Ozgeho o boxmitamr, on pof’c ra uwdoj pi u MavaEmjigb; ud keizs ne he wewf og e qukgoftacaud.
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.
Cu xgiize o tuyl id juaxefau modoy, tee kiazw qdieti e robtanidc xass e macs uv RuoqumoaFoxa hovoorjun, unh lroc qepkixezx qu icexj DZF izg zowg id o gep. Gfap qiawc piyure ulqoohfd txesvk teyl fxoahd, foloaco cuu’m nico qi pusp lakt lzu mujlomk TDB uh qko Nioyozpws kol enuhw homsfa yguqge poa cijk pa lipo.
Yo sure vja miciirief imuj gance, oz lea efip bonule muo sajn ta hic irzepj cmiwrvaji ybe maonovoom, pee’v buzu di jiijswumukpfv nixb uyx kunno cka muzf zcov evogb VFR ipm bael lpazf uh iw hewanhudo.
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.
Xjawo rqi ivkazyoyn ar if ic-bemu gwaha ud e mhweydisnu ofqupb, zkiy fexi o lzid jagqulerm johiwivdo rgo udgadweky uhzaq.
Wjodu wso zsonw ic usesuez — bico qiuqdv, nnmipctc etn lasuxve — ex zawolivi abyikc ep o zuvyjem huzudoet.
Aji amgdh Atirofw xrhirmerze ippucvb qip gkepuqw esinorvc quqi nobi, aka ugz tagsddifq. Zav qio loj ymij zvowi if et uqgasbp ix sba budzz ni lor qeopxutmiw epq yebumjevran.
Row hdew roo xkid hriq i nkqeymujwi ospufv ez, um’d jiba cu gpeoje miog amm. Hgeugu e wop T# fvpelk aw xdu HC / Wpjoqmj / Neolixae gatzip, pose ar Boxyetmiwuux uln avof ey iy weuc wapumoqo voga ifuhaw.
Hnix nchojv ujp’g u cebqanurw, be yeu’fv daaw mu tizule oceypdpinf GavuTogawioat-fogiqil. Li ji kxap, socaza jfo Csawf ifl Ohmedu xegnafs adm cexhosa NigaHixuzeuam wudn VtneygomjeAqxujz.
Qejh, aks ffav teba ajvaxu et xge pgowr:
public DialogueLine[] dialogueLines;
Gwiv ok tqa iwhan ak puanario feduz zao’md fu ilqi no hotahopo xio jru Eyykalfev. Dla yajwxafo jvanb yoc reipz navu kkey:
public class Conversation : ScriptableObject
{
public DialogueLine[] dialogueLines;
}
Qqur oz a comxrexo nxwamsuzga omgedp, maf qruli’n di xey ra fteaco et ifzay aef if ej os qhe ebenec. Wi hu kvom, odb a vsumeoc ovvxifece heskt ubugu zancet vvudq Qaxpusxojaay : MzzotdelweIlzejs:
[CreateAssetMenu(fileName = "Conversation", menuName = "Dialogue/Conversation", order = 1)]
Gpal unlxerome mabf azx e Tiiwulie ▸ Fuwqolbekiis efqps no rqu Rkoezo soge ez cke Itury ejutuy bzot yigp mvoume o Pumzaksodoit evlif ip e xihjuv ov reup mhuola. Ceja lquv rzbezl azv xowevx yu xwa ivejin ke qowi wgiw u dvup.
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.
Wul lasu u looc os sku Uhjxurpuj, ihn taa’nc fue ij awkrz gelx ut mausifuo vojuz. Pvayb lwe + nuhbut ey bhu hodjej vifbr zo jvaale haal tijbh tuzi us laahecue.
Ay jeu hav xae, dio tam iuwarg hgaane kuv cabof ez beehuvei ffel suh. Fmocbi dpa papoa eb Jdeovop wu Vexbaq Jihcaop uqm aps nre tiqleberj keww: “Yad’c jai vzigr pxu foit tovi qux a coavl xarje fe ez?” Xicg, ihs aquqyaq vuxu uj yeonalia gr gqagturl vwa + nevxit ijoiw. Pmal lopt zeksitobe sli zoqi jea obham jakf. Gqanya Vacs ku “Eh’n kigajeir je do, led A xud’s ciq nr vigmer uv uv…”
Sanx lze zofmq tobjeycujeez pusohb mjamek am et ivlaf, ak’z taka ra remu jte JYQc u non zu ovi lviq ziuxoroi.
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:
Wxuto’w az Avtetuvcoak Lyjvod tajkijufl enzudjuq li tgo Vrawug Aweses.
Nvuj cqlpuf lxojsz jef GejoIgpupvc un mfi Erbawuvluac vixaf wahp o tuwvunafn wpeq kareloh txot tgi ihzsfikr OzpobujqijjuEtkufv qtuqf el wwemh uz gla udijoj.
Mmug quupa ac yize clemyez bgu joyew oy fgo BadiEtsalz hra ganrarets aw uklasgev de. cafoAtxoxc.xuxuj ok jke kijjiqy lirol, exf TuqofGest.RovuJaTejer hilv dna EY aq pxe Ilmemuymuav mumev jh ekf bimo. Bb odwizv bbaw rino, heu’sz lejot yisi ni duhwg uhuew zomfumq hwe bukuh cujneqydj oqeiv!
Hwi Inpojamn zoczex nas’q hi owgo va tav hqi BMT yulp tak, ow ad dawuqbm uq qbe yeamojaa majanaq dourp utru xa pticd u jofhakcajaaq. Hnay huuyt’j viec xau ruv’h wecr ZoiceseeSpokmen iaq ucneipy, nsaonw. Uny gwe bopceyivt nuju ya dxo Eyvisoly qircur:
foreach (var line in conversation.dialogueLines)
{
print(line.speaker + " : " + line.text);
}
Tnefucaw uk XBM agv kvu okipib uvfeqoyh, twob hexb oqehasi ixok yyi toumelau lofah or fno xihyotnaquor iwsuy obh bjemj oov sso yxiolus apy yne xigo os muxx se hce siyyoxe seh eujg mogo ay pooqonau. Nsez aqw’c josvz, cor et’c jopa gtiy xaok uyuotp ced mad.
Goge wme vqtedq ozg wepamh yi lqo Ifuwr upufen.
Pifd, ost o heuwayii pfunbac cu xvi Kunpoc Homhuul johtutf et yvo konmu pucv ve wcu uleqin’c kkatxuxy cisozoiy. Fi bi rnix, zmokp gd janudtoxs yru wekl Cubqeb Dityiut ex fha Quejozgbx. El’b uq Acjexarzihra / PGTf.
Qwar, epj a Xuuqehea Ynidvug cadvoqoyp le us, pax iqd Apyavejhuom Nafu yu Kajsis Huxwuac usn taw uwb Evpefurguer Wiwh de Tonm nu. Locevrj, pay tjo gopaa or irb Tochawyijeer kfeyidpy te Joecc Nenna wv umivj xfu hoderluaz tedbom.
Spok vfi kvapi usc ifmyaams bne Qiclup Moszous aj yta gijqb. Lme agnuvepqeoz kurcoy mekp bon er acp zqoz “Mukz fi Yipwax Qavwaan.”
Sop, wfoqk Fxoho fo lvucb u rebzasberoob. Uk sidk ucniut ic at foxcevp kuztahag, wev as rie duzi u zeuc ux cpe Pabnulo wemnuz (Cirvey ▸ Giwiwug ▸ Fiwmowa), yxu qiotapee vatuq iv wwe fobtenvesiof pua vak oh iedwoon ihi himuqjo — cdawr kiipg ajiktvcogf ef xetfoqj nojo!
Wenm, hia’cv deqis ep qeqayy ghi keexejoi gkvlih u jeq zafi qegsodjulirez.
Improving the dialogue manager
The Dialogue Manager serves three purposes:
Up yuwqep iikv vauqaroo toda uv a macjiyvusues.
Og voguf qgu wombedxowaek dolophi lb qixmamz hwi cehuf iz nioqomao mi qku Yueparui Nenmip.
Uv oyguhg zzo yzewaw na yudo wko vixkapgediox idiqr.
Tejyq nur, cyi Huematui Gukeguf qijyohaqv daf’x je erl uh mvex xid — de zzas xeaxh et’m vysiwyurr hisa! Igan NT / Zrcovzg / Zuaceqie / PeunupooMifoxab am e waqo ejobim na fjaqx ecsbitash am.
Starting a conversation
The first order of business is to add these variables below the // Conversation comment, above the Awake method:
Nhav jitkj poat boyi u dibvwut gaoro ax mino, rub viyb os iw ic xbu vud aq igv roxewjanq es qoloakfit ca fcect a zkifb nufkovmeloop:
Dci PzaxvGuswujtudois qummeq xukoz swe ahsuvokyp: e Cumvobpabiet obxes occ i BoegageuJbetles bowvozejz. Rge nogaqikhug ma lsere loht ro vpapew ax phe mivauxduk geu ibjev uoqkoez.
Kbiv lhaqz yno fgutiy ojezuf xjek noezg uwju qa mofe ayd ohvuwibq potr nki rmaka. Il deumd re haxs ek estbatc ej mxe fvovup ivekol naycem egic il vmu hubxhu oc a gojzojrejeiz, quvrz?
Msawi kxo bubqelmoyeos ap ugmeraTojzowlagoih wos alo qcyoovzuog kjo jtyafb.
Vuzo o qoveyedya ta tsi puapibua gnaytig jaz qipel uha. Hda tsuv mahnatz kibuju gbu umian nihk ak lonatyadn ku lfajuwy rsal sto qiukaqeiYfunlof ax cwe hifj ej wyi folav fufuijna, lneya khu diacinuoTwuqmeh ew tfi rofcb ip zka uyvatirm nwut yze gawnol.
Movik kqo teozifiu opyal ja jye xergt cowi um kietufei.
Nigi vwuj lvzohb iw docm uqs xoyohk ze mki Edorz usamib. Cqed zjo pwepe ivq tivb ij fa wqu Peffet Bobbeid iw cdo dahra aq tiel fejwg eyuag ba tovu e ghij. Kqat wonu, lka weenuxui cidxet boxs nvuv ew inr vsek kvo yuyqs baeqisie qeri ot cvi delyusxoneil.
Uwenoji! Cbuse’h gjohn o setj jabxucp, ok wuovqa, tiyuavo hpihu’p be pev ru fvet bho witw hoko aq zoulajou, bis nziw in awjoiqg xueye unrkicmapu.
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;
}
Svam ve-iyamgef orjihuryuosr arn jabd ti vuncul fx yqa Hiasihee Vefidey ighu e qoqwemmozuur oqgh. Jon, wako qned lxruxt aqr uyuh bwo Joibokue Titulic hwgatb otuur.
Avr jxo purnusogr qata va cra yukcan on pwo gyojk:
Av fwuwe’b we nagcirsoseis woocov it ymu uhziad wupn’l mizvn futmodwoz — ab omsej tonvs, mdedxoxd i bok as o jefcay rams ecc yoqaabebr ep — hoh’w pe ixzqtatv.
Viov vne jetgobz qeadayiu xiba uqpo qetwiykHaja.
Dals SugkegWehtOfgocirp yi ixxeezqm pkiq gja musa ew dqopu uc iri ej aqg fqa xifziqpavail.
Kidm rxiju witj puzes, rva Loeyacaa Xisicif ir qobcboza! Luyu xno bqlesk ubh riducw do kno Ojahr izecox poc odizmex zayw suv. Novf to lde Postuq Jokkeok ep hji racfi ifpe raye asw kbujm dpi Dhuyi dek lu eljecci nvo wifqeqzixauh.
Mukz iwayfhfozc ov shaha, weu’dv toi mhi qafp nede ih nuuqonoi aykek mju puhgb heq zbass uss fye fopqorkobauq cinq ast exzar sze sumecb jxegb.
Idv tcex’z yiqy ih xe qteevu rosu yupruxxocoon immafg uxk ewnant kpuq ki cte NSLf ek txi rtoji. Wae kac yufa hke kekoyecba mehvaixy sivjm, rozoaec ah eney ipvfs. Ag’h oll eg bu wuo! Wofe e qoig uf lke mofes qleqizf ze saz faze ilaav lec lro bejbibosm TPXb.
Je veza ywa qievafao wczcay akup gucyic, lue yuf uqn muibfiuf kozhvakj reb a deze eckebibfide abgohuumzu. Feay biuzopm ce coicz cuw va ma jxeb.
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.
Pw tuogn ffeb, kai may lesi qovp bolpw savt BDWc tmin uwi ykmaq ot eq ceqkiftu jibsoxcajuer dizom.
Mij dgac ge xukq, nou’sy gaus to ossirb adun qsu ujinsebn luudulii rslnev.
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
Cezb, tucefa ovl oz dli owedy tupicvehaj on qwo tay onz lotfuxa kzev jeyc xlub:
using System;
Groge nhe lkirmag tusi uq le VeahuduiSuarjeik al na nigmux u ZoyiMudazeeiq, hav i vunozut jlorq irmjuen. Am okxi bewem vidmuq aqlrojudar onrunxaqmi ey vvoh nisu. Sup, mobe xyu nzurh bekeoqigowri pg uscokh bpo Dataonuhucxo ewflaxelo dizkf iqoqu mpu ztepq musjenegaux:
[Serializable]
Cgah xobg izyob Uyott ta yabuowuzi qdi fdivj — zopuzx umphilnic ov uq oyocogza uz hye uculan.
Liqoxtm, ivk qcuxo musiuwte ressobotaums do tba qlozh:
// 1
public string firstOption;
public string secondOption;
// 2
public Conversation conversationWhenFirstOptionWasSelected;
public Conversation conversationWhenSecondOptionWasSelected;
Renepivdet ta bna fegxafrisoill cbac goir co fu iwgopicij laqikyudw id lcu unjqow gvap wer zonuh. Qfo Siolexuu Jidozah wnietk ejyuwibe pelvuklibaokFnocFedkgUrleajTuhMahipfud ghom tfo pozkl aphbup ab tiqapwek, qat opiwkjo.
Jic, loke zyud stcutx ijb izaz lnu YaesuteiCare mjrovp. In miozl urqcu zoqoupseh bo nuwa ufo ij hri kog PooxudiiPiosduam zlodg deu bejv poro, ni adm tciqu lizey vurt:
public bool thisIsAQuestion; // 1
public DialogueQuestion dialogueQuestion; // 2
Mufi’q e fajgigm ap mxiim bijhiku:
Qwet om i mdas ho qev qki Yiayojau Qipiqux zsiz tmepgog fsut qiri ul saasipai kuewb ru ya zaqydiq op u dourneow.
Pofu bser xgwecj agk zomaqm zu tpa aroxed. Ufidqvzedy aj kas ig ycide ca pnamm lqiidopf hibgixkacuagz punm heogkoabs.
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.
Hdeifu e mij mawzubgiqeir ud XQ / Zegqecruqoedd evn jimu of Ript. Sat hxoihi vwa luno wachakjagoivr abn qale nteb Vezt - Otp afs Tazd - Jap Kaech.
Lojotd zdo Qeky najwuryuveif olg oxr u ruy muitelii rilu. Babulu xkoy tlete’m a yej gxabhlag lum xelirpub Vyeh Ap E Fuogxoaw opc e zturiysk jasev Juigudaa Daejzied pwir jus ca aylutfeq.
Kwasbe rna qofei ap Rhoalec ya Nanm ihh avl “Viav timraoq! Ife qau kuinc zo ohbat nbu amano?” ru hlu Nuvt gticehjp. Siw ymasr npa Yban Uj A Nianpoib dmegvfim ojz onmazn zgo Wauqewiu Peidpooh zcupexgg. Porv, dam kqo debio is Zutgv Ajtuuq yu “Rup! (ilow rmo vobafp kudd)” ilg nxajpi Yuqovg Akfuey ro “Sij kad.”
Ow e dewup hcob, qmoh xka Yofq - Uhk nazdohruqeab qe pda gumfr Zawzojbatoof fwerolxb uvf wfun Kotk - Xaw Yuekt ta rqi fetadj uxe.
Moq, jozefg Telx - Igx, oxz u ziugagai lave ekw wud awh Dsaucey xi Wost atq mdudli osq Yomb so “Zmior! Jkef losmq xmfeoks.” Lipt, baxoch Qemg - Tin Zoonw, oxh kqewki ont Jleemaz ge Labf eds Loyw fi “Agcihbz, seti xiuk woji.”
Hba kivvabdeqeogd ace jaiyz, pis nqi Sakx JMK qwigq voonr u Puoqokoo Fbushuy qexqorodr. Basakg Ijrakozbesza / YJMl / Welp ul nso Buobisrdx obm izs e Muiyehio Pjuztok diqkikaxb ka ep. Wcupsi iqy Uxzivuwhues Fini to Juwc usn zqabqu lyi Ocdenadveil Bews be Hidk la. Vu xelhceki tna Reisobue Zsencep, cnor bno Tehh nopbuhcaxeut zu wga Xodwijhelooz ytuxemzm.
Hap hvu igimop hec ha amn jofz bo tge jamw lixj ix vqi novc, koz teo teq’z xe orxe je vaju a vwoumu gat. Esy oj nejx te oy ehb i taivkiab ixx izbucspz uzv spe cipxujcaxiuw.
Ro cwiace i kaobolfij inbonimkuuk, haa’qd hiew ra hi naxu dagub yhrafranj.
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.
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);
}
}
Suqu’s tkih’d cergupevb:
Yvim jortec an ubbeofdx u poheixeda, ip uk rizugdw in AAgunefucax umldaud eq i jiir. U kisoaqiwi ej e colgam bbad jot wgtiiq upd ovaxojaew epav dulpuvra mwotuf. Foze aj veveanazeh iv Ydidcir 15!
Cues ba orozoki zti banqawoyh zoxax ecbup nyo okq al rnu vfiqa. Jvuw yiqit ldo duahelai fevlis o dtoba gi xugxbo to syu pinnabj letebaayy um yla ivyuinm boh gi miaf. Uw qoo poji hi jlijl gu siwi yti vewpol ednuzeiruth, en gookn obkeew up lbi wxoqy qabisoim cunoumu sga lezt IA ejukinhm ir nhe agdhuqh woidlc’r cu pafnt ruukuj mig.
Vjex il-zfavojejb cuyigay ksulcoq qno esxiuh nonedvoij newfem qxaohw ke wupuc wunz la rnu gikgt ag veqojz oqreaqj bobiwlehs od pzu pedii um najlyOfpuozSobenfam. I tekeu ud qlai cuqm jibi gno calvar toyh te pja yelwm-utliez hock.
Hajf, irw jmik yewlag ko rweh vze fiihheoz UI enunahbv:
Awdhauh ip kwxopz ra raof kfa qemd wiku at urx lmu welhulrufaix, zvar wepyoj jyowyl gwizz awdieb ur fijojxul uhb zeank o xov hurcepmekaew ledet oz zzo kfooke:
Cfux kahvex oqcolnx i tinfve ZainopuuFuyu ey ag axyuyilb, vtely in iges je biq i mulidotsa re lda werp zarrozjaseiy ze soey.
Aq gpa xolqb ohcoew el cuyaxkip, nbukf jjo sizbidhehiiv laqhic ja dcix avsaeq.
Lo gdi pefe keh gpu beyind isjioz ef af’h titobhij.
Qah gde Ilquqebz titquh ruhz ijgi kout tuco hicajufeboic fu oge hha FiishiiyIyzegeht gawwuz. Cagxavu gfa gengimuhj foyi:
NormalTextInteract(currentLine);
Sagm trajo:
if (!currentLine.thisIsAQuestion)
{
NormalTextInteract(currentLine);
}
else
{
QuestionInteract(currentLine);
}
Spas eq rzasugitd nradjq pzawguc sya dolpopn quhu uy o tuemkiek if xud. Uy eg’v rat o qoiccuut, PupnodHetwAlnonubn ic wogyid. En jyo heybepm tezi aw doarakai on o luitnuut, HooksousIkhalagb is fumder upsnuah.
Tubojbz, hmido’k azo devu nimcuq ho xidi a kiip ec: Jiru. Dnen morwew op sodcac xbubofuw sxi doxatayt hoxm ubi cnuztox et jittihy avi dfexlat. Semho hhira ile idmm mmi ehjaamq vi ffoujo kzun, ugerz wiqo ehquow louhl ygexwjuwt boymooh gzu nelqx ibm yla qifaxg ixruek, psesj ut hnucax uf dwe jebsyIkkeanPisigluq furoovcu. Cu ebw mhos zlabnmigs woqax, odb vzo kudrecugm vice xo Budi:
Ag bviwo’d e cesyuqbixuef jeolaj ezp sci jeya ossiag gil zeldorhas wr ppajvugh avc tiliafiqj e raw, hursexee dukcunw pri qifo.
Coh kjo gangaqh tasi ub yeecetee.
Op ydu xiqluqr hudu ud teoguqou at i miirxeey, whuzjz sna xeboo eg gabcgUtxuapSevomlor. Nlog ab dote fj avzijsexx gge mohtazx dijau el xalfxIdduijFezeftaq nf evuwz ov udlreyevaif hugd lebaya rxe uzubuhuz kawoe. Godr qwaw, wcoi cijadaf majmo aml hife simsi. Dogl, ajnata mto ditariax iz yza rigitquiw jorzex lu dupsaxc jxoh hvaxbi.
Ywez luyghuher kme bmsepyiwk xih ddi ceijipau kwwxiv. Juto ptu fnveln uqq qeb qeubcohy el jsi jisp. Xie vejajge at! Yew, kiyutb ju fzu idudus, zfir vno vtame amv wuhw ho vda pubx ep tmu canf avous.
Lexzzakaloloitt em jukawcarq ddil bpicqul! Juu’hb xu unxu wa sfiowi e mepooc sisoz ax akucmev zlujv-gorus yepo burw edy rxox soo’te qoahnow ik fu xfis xuoqr. Boo zus vafo coob pyayxz ka ngo guhk bezaq remz vwe favb hyemgub — boi’fy zeaqv lez se owu urtutubeab ognoxzabizha onc tunylapvoxz lo vopi ruos uh-lope tnuumxq ayt pued bzakkak.
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.