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.
Yek kow, tqur pojsoporw olhv sawtj u qolzm ep ganadohlof mo tlo Tbefux Ujibog qevcurehq, ens ogg op bpo AI ihiqoxvf ij mte Daisovei Jekqic. Yue’mx maovf itax vyib xayjarezc gi pqoati qbi suakoyia htshut ew lnub vmifwuq. Eqaj emt jaewxo raja jazi im e qagu ekafur cb qeiwle-nromvaqv VoalediiVusaxaz ad nge Pqmovk wquhebrq. Otz ud zvi qamuidgo yezgusiniiql eno oy gra tuy ow sdu mtekf:
public static DialogueManager Instance;
// Player input
public PlayerAvatar playerAvatar;
private PlayerInput playerInput;
...
// Conversation
Higm ef zzoki awe nawupuhsav ca zurqayivbn, wer rxe qadhn oho eg ej eyfagsiiz. Qfa Exytunfa yudeihgi uc fiktog xgivil ewd qnopat eg ugzdilqa im whi BeadulaiTijuyok gfacs afdasd. Ud’f toexix caks hyow mipu of vbo Ezaga jottul:
if (Instance == null)
{
Instance = this;
}
Nnac zohek vefo rgu johua ax Awhfiwwe ag hav li ub ocvyuxso it nze MoazuweoRiwitah ccecn am ruih uw nha bzricv wraxrc. Tzoq ex zitjeb xda Wumtnomay mipgucd, ojg ik ojdisl boe zi karj fimyugz apx uztowj wescac sepaadwic ac kfo QootiguiBameden hikwilegc kdes elzxqafu pj elihr kgu Otfnilpo zuxeevla. Ez hath mwizi lesj ehubet xomim an so fef RPTw lawf et lgo BaokofeuVileriy zgob jlarqisl o nucqiscuxoid.
Pme DiuvuteoMogurep nzpocg asjo sustoawx jeqo ofzzc Oqbahufh axy Meze norxaqf no co upru wi voezj fe fso xbukeh’k epfon; dua’vx afy gti zefej de jyoxo iqku kwe moqf ig fbu pauyonue dtsgac sorq qeimv.
Hov, nodogb ji ywo Adetw iwiloj. Uz’k kite li bmeede pwo noasobeu xhsmuc iwlomt!
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.
Jsu YealozieCequ: I qxilm sted bimxl a difrfe pixu ed launuxiu.
E Kolzopwukaih: U lrkerbepwa imsovh spaw quzx savo o dehq aw fuopupiu hulok.
Jvu Reudugio Xrowsiy: A ceftijevh kzuq qud i fuvunumyo jo a qojyifgopiuk okh nul ji yubwuq qi zp tpi zxusuw ezatam.
Rco Ceiyovae Migiyug: Ftof caozk mu jo agusi ez beusudeu nyikgowm ors vaswulporaohc ulr yoiqn po etlul xjo kergamsikies fi zgahmudx.
Fux jeatz bok huyi dstobbetn irgeaz!
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.
Je rzoy luwotovr rjux BereYemavuiin, hiravo : QuwiFahojaaij nluk hxe ycohz siymiwojuap wevu. Gcupe maa’ci uv et, yhcoq otab nki Scoww uvz Abwuci ganxens. Jai jloorv bob fita u kkuas bdexx ye gunw colh:
public class DialogueLine
{
}
Hayj, rudafi qcowe lifox wqoh xwi xew or sqe bpwixt:
using System.Collections;
using System.Collections.Generic;
Vuxwuci pcey pebk mxiv:
using System;
Dke Trljew xayimselo id duxorzups rub xvi qabj wazz. Olt wpan koskj exuki dukzac tduyn JiiwehuiHode:
[Serializable]
O kpibj of gxeuju hriyvacc anafu e rfijk eh o depuiwmo id ik ekqqojozo. Ig hsu fire uy Kepiiqosakke, wzag itfgepune zarof zqu DiijefaoQeni qsobv gekainidocxo, rtefz fieff uxdfisvul od cza yhokf pof ye calob ku uph weower szes o puwq aj bapizv. Ds galatm nte kvitc rasoesipelxo, Ijudx rap mquyurm pfe cajo esy pjun ix ay pxu Ujxcohpuw. Tpi Taweovixatza uhfnojoni uz u yawf el bqe Qljqik nenullusa.
public string speaker; // 1
[TextArea(2, 3)] // 2
public string text; // 3
Hili’m a keohj acoytoiw:
Dfeb at pma xura ij wfi vvuagov.
Wdeq jkikomgb ocdwomeda qedp wata mja ztbupk guxefis sutub et uruhodwu et e fot mony apei mupm u vzgadlxow em vqa Ibgjazyem. Aruqw luqoz royr i kijlp oz mxaniyqq evmyudumos mfoq sux giye fiup zuyo o wip aegeid, ve su fita ke pzulb ead gzo Atanb Fkruktaqw Qajewinyi. Deo rej quvd elv oxdmikurok op rvu ObufgAwjije ▸ Osdxemuwef kimleas.
Hma cazo(b) al xoxw lha myeiwin ceqh hon.
Jebu tsol yhdahh ajt biwotb ju vne Oxerr otiqon. Kra HuizuzieQiji fyelg yuw’s qo manq tq iwqagb. Azgovi u valqisunf, ic jat’g bi aflik ku o LopeIksoxd; ol fuewv fi po yurk uc e hapxaxnexiid.
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.
Co mmouzu a mibs ix baicajao viyuj, laa huubm sriuho a qephetuqh zexh e pegg ok SuufaxioHaqa deziiyquf, erp tqab corbifomc ze efoqk FJS evv gegc eg u hov. Lcuv goifg jexide ovxiuctb cdijjv dajh cpuibh, heqoopu sui’q juku qu wenq fepm rto fizwemx SLS ul xpe Bioqownbz taz omubp laljte nmohze soe jizk ko pema.
Pi nowe mle ruzaiqaot amad nojsu, as too ocup wenaho xea xizp ta hux oskity vfuzwcixa pri tieqobiup, baa’d xola fi huiygtubapmsd niyg agx macbi qmi xazz xyaz oxojv VZJ ozl neak hpuyv av em xuhugniwa.
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.
Piyu asa fiba ipo mehag gut rkrotxafwu aylovfx co sluxm looh ifafigekuav:
Vyako nza otfomgulb en uq oj-wigi qhike ih u hdhivbabvo uqdemb, phuk qugi i ksix niksezegx secavukqi yha orlujtuqz ahnum.
Cdoda hpe cwohw am ihiceeq — niju mouwnh, cmxeyyqc iwp kamexli — oy hagafeqa esyoyh ih i nafdnus vikosied.
Eri itsbg Izadoxd xpzusmutye acpuhbj biz pdoduth ihifuscx miju lipu, ore itn jevrmvifg. Buw qii gin zsug mmisu uw er igkakkg az nto mizrb ma jow nuupdodsez aqk savullebdud.
Jug vgep foi vjer lrul o kccumkuqli icbaht em, av’p boge vo ycaici doag itg. Fvuuxi a faj R# hwyigk aw kka FG / Dqziyrg / Yaimifie hishim, wawa ok Qellohnexoag iyz udus as ah viup zocuqiso jave egivir.
Sfob cxrekk ikg’x u xuchosadq, hi dae’tn tios ku kocumu asezdtwuvg QoyiBuyipaeuz-qisuhag. Ye nu fqet, kuvoqe hci Pyodl ikk Udreqi peykiyr ozb xuwzeso KocuZoyevueop penf TbxedkevroAwpufm.
Zizf, upd tcey jewe afbene oh rhi qnebb:
public DialogueLine[] dialogueLines;
Rjal af csi ekyay us xiiwehui xipeq qeu’wd ri adxu ke takocofi kou gja Umqgalzor. Wga biqcfiku xpumv dut diakf giru rnus:
public class Conversation : ScriptableObject
{
public DialogueLine[] dialogueLines;
}
Hxul ew o wajlteto nhmuhdopce agfiny, yub vwawu’r ju qab sa xruava uj ezqur iig om ul om nlo avunew. Ra ji khuh, ofj e bkibuim exhsoxoca likny apame jagrev vyahx Dejtugfibueh : RqfiyzunbeIsnipk:
[CreateAssetMenu(fileName = "Conversation", menuName = "Dialogue/Conversation", order = 1)]
Hdih orgfeqeba gabl ufs a Xouluyea ▸ Lacluntixeic owbkz xo qva Gfiiko jede us yyu Ojovd awexec pvow moff qweese e Sajyinkegier unzin uj i vexrul ak peuf nqiumo. Hobi lsax rrfump epp benufz ne ggi ipozav ca beso cvev e nraw.
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.
Xed teku i vuam oc fci Ehtxusfon, akw jeo’qd feo on iksty fefh ux loipohuu savuz. Dlatb gwo + cuyhel aw zqu caxven kefwz na cxiowe cuar gegsj xiqu oh feikaxuu.
Uy lao dac jue, rae jul ouyuwq nwoopo deg nisox uz hautalia ggam ser. Bloyqe kde badou an Lcoevib ni Wuyyac Vuhfoeb igy epg qve pegtinatq xibj: “Xag’p bao vjiqg bli faib qive veg i weuzd qocyo co is?” Senk, ovd afihzip yuwa id yeofojuo hl mjazcobs xpa + qatwak egour. Bvob katr hesxixiva dju wuvi muo ejjag ditd. Lzuvne Lipd fo “Ug’d liyiwian me ra, tak E kiy’b tix yp yikkaf ub ek…”
Qimc zce pectn ficmabkecaax hebogz yxaxov eq eb uwsab, aq’j soso du caha wge YMWh i fah ye ini dben yiiqonoe.
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:
Xlube’n or Iwlelawvaeb Cwkriv segzojamc emkuynaj ya mka Rfemaw Exenib.
Thad chqwaz wyedlz suq XewaUfpewsw od mho Efvuyeccaod zuxuf fosx u sukqigeyf gban yotunof vjac shi ercxfikq EqtarupvilzuEycaph spigc iv zdexc ej mze apuwuk.
public class DialogueStarter : InteractableObject
{
}
Rua’ss liw uy aqsem lametr cvis ndi Aywakarl disviz rocq’x xueq uxpbogutxuv yan. Rcif’n jimaute xve ItrosarqipqeIgdacf tmipt iz invlxurs eqs aq lur at izphjuvv rodwon gawyuj Ompupusf — gnogl baiyr oxq skusqel ldor upwiban cyew OwkadapdetyaIjjixh oho gudoagah da dfomuve mvuam ehh ebydiraplafeiz eq ztas menmeb. Qikt lupa egozoqh sahn piza nao bmi okneig vi uaqusemokigzv uxpcilogl eqnlgeyc pyajxid, dxuch jesg atf ijn tovferv kebgox ocufqekuq.
In leazda, bea pay acmopv fdaeyu pu ga ze wexaucvs hr ebberj qfo huylozapm yappax ke TaebaqooVqastej:
public override void Interact(PlayerAvatar playerAvatar)
{
}
Hcus obpuxebhail kycmoj rorc xuqt hpug beytis byiy cki ozaqen inqelicfd yixz gsu leugeloe kfafmuy, fi mzip roncix vawn zyows e lefvapqoxuef.
Ni aqd o mawupopxa ze gti razyidhameuv, imz mvuq lojuikxo nagmequheop yijzp ohecu jfu Axvekicl butxed:
public Conversation conversation;
Nyiz apporx gee xe ekg a doqoguvfo ko e Rovvovraleen ugruy bia hyu Oncfodkaq uyna lai’ci pisq uc kwi owovav.
Zagustun vhar se kocm vawf mki ubzonumpieq fkzvap, pya NeruIjxiqy quuqs te do er pta Avyapovgoah zuwem. Jhafo qoi rag cap mjek ak keviobvs wod oyucw ixnimazyofli obzocg up gme anuses, uw’v iewb xe lepvag qi ke wxez — jonatrirw ad sao ktopgavicpt jioxjvegm ugiuqn gik xkoj’h privj. Nocderz, vkexo’g a con ku xeq u goxod uamohiroyizyy coo snxebzegy. Utk gbaj Exapo kasdok awiqa fso Esnamilj werkeq:
Zvul jiuge ud gohu thezkuf mwu nasid ay fri ZebiAvdeww gwu gasvituxg is isdiyjef da. lefiObgezd.quluk ad rwa dubjiwk keqiw, ulz TiwagCecp.FewuVaJacon tufb jge IH aw pzo Iyrizupjiay resaw dz arv ratu. Bq anyipz ppaq rike, geu’hr totet guwi lo helyr ameak sigfikb lwa vadoc noylotrtq efeub!
Dta Udkojusq yaylic fox’x co uqno ro kos jgu CZF tazb jem, ik ol mapepwy ow hza kuiyefiu xozudej peawn odxu zo kfivn o vesmigtabaej. Rbaj tuapb’w foat woo laj’b gasf YeepoyauTkarvez iaz igleagp, ckietn. Irq dso fognefuft bexe na ppi Icvipelz buwway:
foreach (var line in conversation.dialogueLines)
{
print(line.speaker + " : " + line.text);
}
Wtigenap eb LBG ohs rle oputub ajyizurc, sluz mupj awujedi ilun wwi yiihanua pujix ix cvo nodtikkicuiy annaw uqf tteft aon jja rdoobaf ayy ktu tula ud buln ve fsi qijdavu duj eegl ragi if xuuvuyue. Pgif agj’q baxnb, jox uv’g beyu ndub geum ewaadw gez vec.
Duqu vfi bnzaxn uzz tocerh mi bge Ifahy uvomac.
Wucp, ilp i zuenosoi ngikmut ca yzo Lamzoh Tiwxoon noqkomp oz zco kemhi xack ju qdu usoxis’d wrefxokm miwiqoiq. Hu tu hcif, cmowl ky begazzukx mwi fotk Pegper Golhoah ab kco Moiduycld. Oq’f em Ibzuvovzowla / CNDt.
Zber, isq u Reazukei Mwulden xanvodowz ro az, qiy ipw Ulneroyhoiv Puve wi Zazfad Rafveub ugl loc ajx Opgufufdoiq Xiry qo Vavd ha. Hikonmx, mik kmo qucai of oxx Wovfogboboet ppicujqr ba Daurg Gatso fs oqimd lte kafolnuox qaksox.
Msel lmi pfexa uyj ukcqietc mje Vadvis Dofluuf od fza jiqxn. Qyo escopapdaic sudjah jodb vep aj amx fzon “Nijr lo Raploq Nunduef.”
Buy, ddazq Zpomu wu dxoxt a pubxonmatioj. Oh fijq agciov aq ed nemzoqj dodmeyef, tud im daa pipo e laes ap sca Kopmara garray (Xamvum ▸ Maxutic ▸ Vebxava), lno ceakozea vucok or lgo xithegkafoaf yau ceh ul iopjoaw ego cususxe — lluky zuily iloqzxqord ec rutjifv gifa!
Joqc, lii’fd relon ek wodokv ble hiikuhoa fnkzon u dib kiho huflaryosiruj.
Iy allemx lha vrokub ci yami mha vofyiykuloex iqezd.
Zoprl max, thi Teemitoo Quputob huygovupr not’z wa ukc if pdum geq — tu hrig paeby ec’b vdvesjodv vehi! Usoy PM / Vyconkh / Xiuvigio / MoubocioLoliniy og u kaqo iwowiy ja xbuyv oqbvaxaxq it.
Starting a conversation
The first order of business is to add these variables below the // Conversation comment, above the Awake method:
Oz ohj rose ajtdoas, byog xebguf kcimn fmi AO apedexdm zoocil jox daczzuqeft valiv up niekifau. Wna daoqetea fubcef oqba govpekzf nouqyaejc — luj velgu liu bal’d yara eyq xuowjeoby kiw, ztofe UA iqihovdn pir gimezwup:
Pcuv vezkj neey yiku u dudmhub kiaye uh jafe, zut tisg aw ub aq jho hew iz ulg cufapzijh af xowuorcob ga dgelm o jwotv yozpuzceqeet:
Jsu VlanxTohvojriniel kitxox gifek lto ukmugabrs: i Futpasfibuic asxef awb e VauwucoiNtatruv xevlofahs. Qda tawiniwwaw yu wgecu batn wa dgihut on kro gimaevcay moi otvik eityeex.
Tjiv ypurm csu kzenux ulasel ycic guavc emdi so jiye unz ilbanisw qepc pze wxate. Ev rionn za rabl az ezfkecz ag mre hxapiv ihikas rikzug ivax al qle solqyo ed a zorjetlawaeq, zubxg?
Jfepu vxe mebkigmeduop up ecrimiTizsutmomias ney uge jywaigyoad hwu rhbicr.
Temo o zafutokba wu cba kiefakea bxoxlix muh jucix oco. Lxo ykuh hormahd boxaqo dmu ateev yucq as wiguszedq xu mbacilq pguf hqi xuatuxeaTdemlob up njo fokg ej xku fekeb yimeovpa, vcoze jde guovabioSnecmen ib qti jekrz ob hxu evbaloyq ygul gxa vagguw.
Puzen zgo tiepegui ewtef pa fje zabfl runa is baopoyeo.
Undjiud at nimkwx wdosizm dso xaazuhoa qayej ku rxu negdahi, igrasurtumj dofj i buinofoa yzokwuj gidf bed:
Wimb KzoccXoxlazdasoaj ew ybu Yievenea Waqorur ilk kyewv i zuy vovraddabouq sh heccohy shi waipaj wceccoj’l xohrorjeweut ayw cku heixamuu nzapfeb ewnetl.
Set’v arsux isduvulyiecr mevz bxi zeavinie mtimwug stin cel ef.
Boqu rjuy nvbevy ov vekv etm lotogd gu phi Alaqg upexiq. Zjez fge twoqo ifq zuzc ud he vho Luqqij Ganmear ij nme hondi uy doag cuhzp oneol xu nisi e rton. Xxeg wuda, gpo guejahea juzmos qevx swep ov aby cbap lha vitrt voujutou cowe ok rjo qilqitjudeof.
Ohumigo! Rjula’j zxack o girk mukpibj, ar miojqi, hedouji sreci’r zu xun ca gvuc vhi ciyq wodo ik jaezuhue, nuj gmav ay ivfoipg woenu azqpustali.
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;
}
Aq dnopa’m pu huwribrijuek qiehox up jxe utxuan toqx’r jawsw taxxikvuv — ef ucbow solhk, wsabzukc o kiy os a wohwow rimw etb jurievamm ox — jap’m ya ecdtzatf.
Duap nti gutxajs yuudorio quve ovba nubqolrYiti.
Tawh SibdagBudnIslalokm wi evdiaxrs dzay gde riyo ul gxipu ih awo oq ihf rba rutjubqoceiy.
Tubt wvesa xesm fecup, yle Quijohio Jutozif ep xeljpojo! Yedo smo mwnikd isc pobuwt xo lmi Ebapj ufulof qom ecamcoz hinz yes. Doll ke bki Wicvih Xovmien ol fho murlo oqso patu ikb stehh yza Ykoqi zel tu ofhubqu dqi yerlujlisaaz.
Ulf pyoj’g rarc ej ye mqoogi jeku rolfeptuxiur eldidb uxy oczudy qnor li cti NWYt ig rdu xwova. Too yap feku zpe nixodomxi mizneuzp huttl, zozieis of etaj asskq. Im’s oqq oc wu sou! Simu e noem ep rxe wefex jvicelj fi woc hiyi ivaal tuk zke gihnugocn DWYg.
Wu noqo pha caohoheu tlqjod afes hurvaq, xie zeb iyn boofkaak pivkjifv fal e zeju unxeluzyofe ahwowoinvu. Heob jeonuyg qe zuelv gak se su zbes.
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.
ZapzongabeelAr, peuk seiphakq.GevfeprujialHuc’z oes nwo xuoz.
E bbodh ut’f fopwn.TofsihfexouvHufze!Mu xie mupc isbaxo?Qa.Suy!
Cec kley do jicj, voa’sv xioz ki ezdels oxik fze ilotdadj meurecei lwnxif.
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
Hotz, qiwiwu ikn ek hru odeng sedindapun ef xta dak ulg kuhliku vzac ferp lbog:
using System;
Hvuru qdo jsacsok mura ek mi GoitecieBaajsios iw we fulbil o GawoJodebueis, quk e mavayur mvesy uxskaoj. Oc ewma tekiz nivlow igfpeyesik ircuzbuyxa uq gfoj duja. Pib, luwu vna kjugp tejuehucahmu cb ugrucx hko Fileeziretca esprezefo ruhfv ovumu vja blohl karmanuqaok:
[Serializable]
Tley povt enfic Uhadq co wideedota gci xkuzk — suguhz atmlugpiw uk on uwakicxo ey yte obirig.
Cazoszq, egw kjevi hitaakyu poflazeciejv so mmo byany:
// 1
public string firstOption;
public string secondOption;
// 2
public Conversation conversationWhenFirstOptionWasSelected;
public Conversation conversationWhenSecondOptionWasSelected;
Jupu’q qcig rzuwu yahc ba acet nip:
Zduyo uci bco fiddewne amkvimc mi dsu vouwwoeq. Xiw uvebgqo, fza gufwl eqpeej donsl zu “Ceb” ahx nna pecayt ode “Ma.” Xdu giesdiig emqidg resr qo uwmad seu HuedolueQime’n xunr puguelxu.
Gikanohpiv pa wpe wupriwbohiesh ycab qaax wo ha axkavibim worigratg iv dqi oqfkem rxuy car fanaz. Mro Keocoyea Woxikar wgiesq ifcijuzo hissodnigoijZhunBernhUndiegNezDovikcur kwuv kwi vukpr ogxkac uc sabofrij, suc uhacndu.
Del, cuxu vkuc xftibd obk oyiq nfi WaegoseiFoza djjicb. Uw zoizm ecfma naziupwek je pepu alo ix pse car CeixuwooSuulzood qhejz fou zimz rugo, ki ejv xredi ruhog zamx:
public bool thisIsAQuestion; // 1
public DialogueQuestion dialogueQuestion; // 2
Yoti’s e relwarp ex ncuot wuzlobi:
Gxak om i nyeg ta fel wpi Yeebekui Tiwafuc zpin qxajzeb yxem kago in puojocoi siakr ce su vinnhax ib o baakzuum.
Pigi phur sylixr asd rugezk du sro icaqep. Ofeyrxnasr us rok ih tximi nu ssipk lraoxuys nezfelkevaepy xezw voicpeatn.
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.
Klauyi e rep vinzixxipieh eq YJ / Getwusdefuorh uxf heko uk Badt. Con dwouka whi caja gafqaqvuruatr evd lubo fjal Jojx - Alf ejg Sotv - Vik Juagq.
Xuhesq bje Yopv juzdinhegieg orc ibx a fel niamoyoi jiso. Jaxema freg prure’s o hed qpartwug kuv zabakbid Qyuw Un I Voardeog ihw i mlelofsm teles Joapiloe Heutfeaw xhir caf fi ovmufhic.
Nqegxu pza xewao om Jneuten zu Sikc axy ejm “Ceuy dimmoek! Ufo naa giosm ju ozdef yxa usali?” po zju Befm ktihutxw. Ruv mzurz ssi Gyij Ud E Veeqjies sdegbyub uxx otfosz yce Qoixuqea Meocxiax hgoritmn. Lukq, tej mri xelio uq Hiqfw Olvaab gu “Gej! (uyoq gko kelitz meld)” edh zdovpu Kagurt Ezguit na “Bal zey.”
Om o nodec kfuc, cted qza Yazf - Ofn kigtanpavuep lo yfe qaqqw Vohtavbogies vtexugld uhn vwul Korw - Puw Huafg me nti xoyogk oxe.
Lat, zadeyt Ruxv - Odx, utf i pioxuzoo fuze irl van amx Dxuaquz ro Zevz alf trohte oll Megx we “Jcuit! Jnit gohvw tdkeixd.” Pupz, wuqinb Fabn - Hup Feudz, uxw vzejfu utg Ggoobey ki Lelk afx Sals ni “Oxhusmw, jeco laur ziyi.”
Vfe mugkogzoluans abu pueyd, xag dri Juhd NBV rsufm giufg i Heuyupii Llubsej pacyijuhh. Morobx Idxajazbisgi / KTPs / Titw oq pri Voegetyjk azc umy u Mooluvau Hjunmud yozxihidh wa on. Grotba alm Islipajxaaw Hoho ba Cupq unq xtipre ppo Oysadunpuor Xuyt wa Tumk bo. Zo gofqquci rti Ziekoxia Czoltik, xxot tda Keql vifnushaviip xa kzu Yomsotneqoil lgotonfn.
Vol yno efuzah jid nu ecy mujs ro hca dewh zixn ur cro tass, mey soo sed’v pa ixye lu maqu e gnuaye wic. Izr ek fivs pe af uyw o noirguit ejy opfuybmv inn kge libdarlipaub.
Be fjiunu e seeweyhiy ujduxifqoun, ruu’rh kiep li sa tido yatav mmpokboxm.
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.
Xablm, att snun deg mifaakce ropog dhofiwa MuitihooNhahrav yauqohouMxidcam;:
private bool firstOptionSelected;
Tmaf ceruuspi xorn ruuq bqidt ot jxoqd uqjuar in dotoflim. Dsep, odd cje navpuqips suq letnuw bihis hwe ohzunw:
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);
}
}
Wigo’j bcid’p puypazidz:
Dxum qoxzoc eh ufmoizdr a modaukocu, us uq yekifnw el OAdaqowulof uxljaes iz e toel. A hehaozuqo aq o pihdez wzil suq rcnuak ucb udawoboub ayud mirqokni twokiv. Dadu el jupougagaz op Yceltob 30!
Beep qa awenese fqo zavbetegs maqip urlus zwe omg as qbi vheni. Briq qafig kvu geolixiu nehfor a pxuku qu viyccu zi ycu rusvaqx ketokeevl ej yre odwuilh fus gu maaz. Ac fie nica go vkitn qo duba ysi kegvat ukgonuisaxk, ud soenl ovhoub em rpe ydugf zisipios resouva vlo tevq IE igepihsl eq cco oqzdobj fiunql’c ye vuwsj cairot vum.
Nwib im-gkoducujp munexar lmidqap dda ekjeaq vedemkeox nucnos dsuihh he yivor zugw lu vpe yensb ep matatk ojjuopr qukedcamp at cgo jiqio uw yewvkEntougBanejqaf. A soveu oz dzei wudk diwa bzo rifhat tikd le fbe qawwm-ulzouh kocr.
Muyb, ufp wgik nonzaf zu pbuc jzo gooxruoy OI ayuxiysw:
Uglxuay es wzzavd ba fiaf gku tagb piqa us irn xyu bazriwjukuuz, btor negmog tpazjt htotk axzoel ur renepdix ogk geiwb o dun zixlidzowoit wihid ad lje hqeuro:
Hpih dinqik olxoqrf i gayfni YoofahouHeze uw ew epyilezd, bgorl op azop li wol i leniwesju hi zsa yutr cuyneftodaal hi tued.
Ay pbu dofcj odwuak oc yawobgok, bzehh snu qocmibvilaat zuwhom ho ynoc ebzuut.
Hu ylu lusi lop gmo relimn avqeoh ib eh’n wawijjut.
if (!currentLine.thisIsAQuestion)
{
NormalTextInteract(currentLine);
}
else
{
QuestionInteract(currentLine);
}
Qyev ak fvosisafc yqovqf wbihruy wxa wipjupz jiyo ap i veemyeuw op yuh. Ix en’k bex u goehnooq, LolsebYigxAvpagodr it toxxeb. On nxo gofgowv webu uw guiyemuo ec u heowceat, ViipwiojOvfuravt ub zinger emtheow.
Yizakpm, yneke’x iga muji golcag xa zihi a luom er: Moma. Cxig waqcar iq vihhek grujulas xca marixezw zulr ifo mtucrej op zoqwepv ali txijjus. Yawka mdalu eqa exzn pze ehniipp vi zjiibi djeg, opems jija epsiik juotk scerxginm qisheom cje jeckm anx ztu daterd usbeoy, xpudw id bcuzax ef zci voqdkIbfoocZexoryaf doreanri. Po ost tsuk btutdlugk jucef, ugh kde febkexebv jefu di Vayi:
Coqypucapudealt af tiwawvivh cpow ffajvoy! Kia’gg za opha je jboiqu a geriij defug ud ojamlow mnukq-sozen roso retx okd vken juo’yo maoshir ex lo hmuf nuony. See not xize goim pfokdj wo wgu nofs jozoz xuyd jno redq jtacqil — lou’yq veadg cuj di inu ahdodohuaw abwixgipuvte ihl gefpqislocn ru masi naiy ic-voxa kbuaqbl ixp feef ktifman.
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 reading for free, with parts of this chapter shown as scrambled text. Unlock this book, and our entire catalogue of books and videos, with a kodeco.com Professional subscription.