Lets BUILD a GAME - Knights & The Castle - Full Process & Code - PLAY!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
buddy we should be live just about now and ready to get into this so today we're gonna go through a game development process building out a game for kids well for just about anybody really we're gonna put together a simple game that uses some knights and castles we're gonna have the players send the knights off to the castle work on the animation the movement the navigation all of the different systems to kind of tie it together and make it work this is something that i tried to do a little bit last week and ran into a little bit of problem and had to stop so we're just gonna restart i'm gonna take you back through from the beginning the start of the process of pulling in a little bit of the art we'll set up the animations again real quick and then we'll go through the code write it all up and hopefully you'll learn a lot along the way the game type that we're going to build is going to be relatively simple so don't expect that you'll be in love with the game specifically but all of the different things that we're going to cover which they should apply to just about any type of game that you're going to build so let's stop playing and i want to just run you through what we have in here so far and kind of delete things out so i'm going to just delete out actually let's just go in and pull in the blank demo scene so i'm going to go to my window and go to package manager and i've already grabbed the cinti knights and castles pack oh sorry my volume was low i've just cranked myself up there we go hopefully that's much much better all right so let's um we'll start again today we're going to go over building out a full night game in a castle and it's going to be a lot of fun you should really enjoy it make sure that you hit like and subscribe and all that too since we're restarting my little stream here all right so go ahead and hit the like subscribe button i'm going to open up the package manager and we're going to go to the cinti studios castle one and that's going to be under my assets instead of the unity registry option there and then i just want to search for castle i'm just going to re-import it and kind of reset my c and reset my entire project so i've got my where'd that thing go cinti castle polygon knights castle right here this is the one so i'm just going to import that package i'm going to go to my project view though first and just delete out what i had i had this polygon nights package i'm going to wipe it out because we're going to start from scratch all right we'll import in the package now and then i'll reopen the demo scene and you get a fresh view of what it looks like so anybody that wants to follow along can follow along this is just an asset pack that i already had from before it's one of the ones that i got on i think a humble bundle or maybe one of the sales because i thought it was pretty cool and we need i think it's only 20 bucks regular though so it's pretty cool pack you could use whatever you want to follow along though and just do it in whatever theme or environment you want to use if you got an asset pack you could use that if you just want to use squares or whatever um i guess you could use that like using cubes or something let's go into the scenes folder node not the scenes folder the polygon nights folder and then in the demo folder and reopen the demo scene now we're going to lose all of my beautiful work from before don't worry though we're going to recreate it all so hit don't save and now we've got our nice empty scene so the first thing that i wanted to do was kind of talk a little bit about the game design and where we're gonna set up our camera shot let's look at the cameras though because i showed this a little bit in the first one there are a couple different cameras already set up if you just search for camera in the hierarchy you see there's a castle one a church one and if you look down here you can kind of see the preview i know it's really really small but it's there so you can kind of see it i could also go to these and just hit f and get an idea of where they are and what they're looking at so this is kind of looking off in this direction of this area i mean i could just turn the camera on as well i wanted i could just hit play and then just turn on and off whichever cameras i wanted in fact let's just do that real quick take a quick peek uh stop playing uncheck that maximize on play play again go find the cameras i'll select all that's control a by the way to just select all actually let's just do a shift select i'm going to uncheck all of the cameras so uncheck all the cameras and then we'll just go through each one so the castle looks like that that's pretty much the shot that we're going to use for the game but let's see what the other ones are the church books i don't know like i guess it's a shot of a church this could be cool for like an intro of like somebody walking up or something they're just looking at these for inspiration and thoughts and things that we could use them for along the way this is uh the one that i used for the thumbnail so i actually set the guy right here made a little thumbnail to use that um i don't know if we'll use this area for anything else other than thumbnails who knows and then the town this is the one that was super busy so we're going gonna use this castle one i'm gonna go to the scene view hit f uh clear my filter and just zoom around real quick so you can see kind of the whole level the whole area the castle view is the one that i want to use that was that area and then i don't know this is the graveyard i think it was and then somewhere in the city was the other view but we'll use this castle one and what i want to do is set it up so that there are just two armies of nights to start so we'll just make like one actually start with a single night that'll give a little bit of instructions and then spawn some number of knights and then have the player send them off to the correct castle so one night one cast they'll take you know four nights one cast will take eight nights send the the group of eight off to the eight set up the thing make it all work and even go through that process real quick so let's stop playing and we're going to well first i guess we've got our camera set up let's just pull the main camera castle out i'm just going to take that out from being a child say drag it all the way down here collapse the stuff just by hitting the left arrow and then just make sure i've got my camera available and ready um i want to make sure this is the only camera on if i hit play pretty sure this is the one that's playing right nope it's not so i have other cameras on let's go find those other cameras the other cameras the town the church i want to turn off i'm just going to go uncheck those eventually we're just going to rip those out though and switch to a cinema machine setup first though let's go grab our character we'll go to the models and no maybe it's under prefabs i think prefabs characters there we go and here we've got a bunch of different knights we've got knights and soldiers and i can see the little preview down here in the bottom that you can't see so let me pop that over here and make it a little bit more visible so here you can see all of the different nights i can view them and scroll through look at the different versions uh what is the soldiers soldiers and then knights and knights okay a couple different versions of them so we're just gonna take i think the blue and the orange knight we'll just take the first two i'll take the orange knight or what did i take this must be blue right take the blue knight drag him over here hit e rotate him a little bit to face towards that camera then i'll take the orange knight and do the same actually let me get a different orange knight i'll take knight to this orange so it looks a little bit different not just differentiate on color but on the model all right now i've got two different knights let's go to the game view see what that looks like all right i've got my knights kind of in position the first thing i wanted to do or the first thing i did in the last one and i want to kind of recreate is set up some simple blending animations with the camera a little voiceover that's like an introduction so that it flows really well because i didn't mention this at the beginning the whole goal of this was i wanted to make this game for toddler make it so that they can go through and learn their numbers learn their counting and kind of figure out how to associate numbers like you know five of a thing or five perfect five of a thing with the number five or four of a thing with the number four or whatever and he really loves knights so i thought hey why not make a knight based game that does exactly that so we need to first pull in a camera system that'll allow us to do the camera animations set up a little bit of voiceovers already got some voiceovers but we're just going to delete them and we'll recreate them and then we're going to go through the spawning process of spawning a bunch of knights and making them walk into things let's start by pulling in cinema machine we'll go to window and go to package manager and then i'm going to go up here to pat my packages and switch that to unity registry this should make it so that cinemachine shows up right here on the left it's not very far down and i just need to hit install it's already installed i'm going to actually just remove it real quick and reinstall it so everybody can see it just in case you're curious what that process looks like it's very very simple though uh we just gotta wait a second anyway um i just want to say thanks by the way everybody in chat for just coming out and joining um hopefully this is really helpful and you guys learn a lot if anybody has any questions or just feedback or thoughts or ideas along the way feel free to just drop them in chat i'm going to kind of keep an eye on that while we're coding and stuff all right so i've removed this in a machine package we'll just reinstall it real quick and then we're going to set up a new camera i don't know why i removed it and reinstalled it mostly just to show that you just have to click i guess the little install button here to install it so that's pretty much it not a whole lot of value there all right once that's installed we're going to add a cinemachine camera so we're going to go to gameobject cinemachine and we're going to add a blend list camera blend list camera just blends between two different camera views so i'm going to hit enter let it name it cm blend list camera for one right now one for right now there we go i'm gonna move this preview window down here get it out of the way and then we're gonna set up these two v cams if you look here it has virtual camera children and these map down to these cmv cam children that we've got now if i look at the first one i'll go to the scene view you see that this one is kind of up close and i guess really close and the second one is and it's actually at the same exact position let's hit play though and see what happens with these cameras so we play and it does like this weird zoom in so the camera was in a weird spot and then it played and kind of went to an even weirder spot so let's take a look at these two cameras i'm going to take the cmv cam here and just hit solo on it go to the game view and see what this looks like so this first camera should be a view that kind of matches to this let's go to the second one the second one is a view that matches like this not what we want at all so first thing i want to do is start i think um zoomed in i want to start like zoomed in right on his face i'm going to take that first camera and i'm just going to move it instead of having it be where it is right there i'll just take it and move it right here so it's kind of zoomed in on this character let's get it i think maybe all the way up here ctrl shift f to lock it into my position or make it match the rotation just hold ctrl shift f while i'm over the scene view and that camera matches now if i go to the game view i can see that yeah that's pretty close to what i want i think that looks good now i'm going to go to the second v cam go to my scene view and i'm going to pull this one out so i think this one i want to give kind of an overview i'm going to start saying something and then kind of pull out and give an overview and maybe turn a little bit like this so you can see both castles so i'll hit ctrl shift f again go to the game view and let's make the second one solo mode so i can see it and notice that it's way zoomed in so if you look in the scene view it looks like it's this tiny little box here what's actually happening is the field of view here is set down really low if we compare that to the other field of view which is 60 it's obviously much much smaller i changed that back up to 60 and then go back to the game view let's see did i mess that up what did i do oh i got to make it solo mode ah there we go make it solo mode then it'll work so the one that's kind of an interesting thing with the blendless camera the default one it keeps the cameras in the same position and it just changes the field of view for the default blend here we're just doing a move for the blend instead now if i hit play it should start up close and then zoom out now we can control that zoom with this little blend list camera option here it's got a couple options or this blendless camera component has a couple options the first is right here though where we can control the blending and the wait time so if i want this to wait on this character for maybe three seconds and then zoom out over two seconds which i guess what it does let's make it three and just change those values hit play and it should do the zoom of course we can add more and more cameras to this and just make it zoom as many or blend through as many as we want so there we go that looks okay but now i want to go through and add in the audio so one of the things i did previously and i've talked about this a bit was generate some audio for our character there's this tool that i found out about not too long ago this replica studios tool it just lets you kind of generate audio by typing it in picking a voice and downloading it which i find really handy especially for things like these tutorials or just prototypes of games or things where i want to have voiceovers and i just don't have any voices i don't want to record it myself or go through a long process of getting it so what we'll do is just open it up i'll show you how it works real quick and then show you how i downloaded that file it's really really simple though you just grab their tool they give you 30 minutes for free they're giving me 10 hours and 30 minutes for free so far and i've used a couple seconds you know or only a couple minutes and it's a ridiculous amount if you aren't like just dropping in a full novel like i just drop in the words that i want to say and then it just kind of works so here's actually the one that i had from before let's uh recreate it though i'm just going to copy this text says hello commander thanks for coming to help us we need you to send the knights to their castle i'm going to copy it here and go through the process one more time so if you want to create your own text you just type it in here you say like hello i'm going to say hello yeah let's just type in the same thing commander thanks for coming to help oh i'm gonna change it a little bit let's say hello commander we're happy that you came to help us we need you to send the knights to the right castle can you count for us something like that so then we pick a speaker so you use the drop down and just go choose the character that you want and the thing that i found is the ones that have this number of styles up to like three are the ones that are kind of like the most fleshed out voices that seem to work the best for the characters and i was using which one was these and like the gray one maybe i used my doggy is so smart definitely not that one that's not gonna work i want to use a night a night sounding one hello stranger yeah this was the one i was using i'm gonna go with this one so use gray we'll hit save take actually we probably should hit play first the save take would just download or give us a file to download that's just an mp3 or i think an ogg or a wave it gives us all three options where'd my file go what did i do did i miss it save take loading okay it did oh i missed it it was right here i just recreated it i just wasted an extra six seconds there we go so i can download the mp3 right here by clicking on it and then go into my folder so where's the correct folder let's go find it we'll go into our audio folder right here hit show in explorer copy this path and then i'll paste it in over here and then we'll give this a a a better file name than just this good id this is good it ends with id so it makes sense to add id to it so just call this like hello commander there we go save that file off jump into unity and now we've got voiceovers that we can drop on our character so i'm going to go to the knight we'll take the blue knight here go to scene view real quick i'm just going to drop this onto him so that he's got an audio source he'll auto play it and hopefully we'll just hear everything right away we'll get a little zoom out animation we'll see some stuff working and then we'll go on to well character animation i guess would be next right and then we'll do gameplay logic right after that so let's hit play try it out seems really silent hmm i'm not hearing him make any noise here so what have i missed oh i know what i missed i need to go to my main camera and on this camera because i created a camera when there was already a camera here there's no audio listeners i need to go add in audio listener i know that because i've made this mistake multiple times before and this time i remembered so if you run into that mistake you're not hearing audio remember to look for an audio listener make sure that there is one you always see the error saying that there are also too many audio listeners if you look down here at the bottom of my screen this is another thing too if you have an error look down at the bottom of your screen because you might have a little message saying hey there are no audio listeners in the scene add one right then then you won't have this problem so let's clear the error one more time hit play and see if it's better hello commander we're happy that you came to help us we need you to send the knights to the right castle can you click for us okay so he doesn't say count very well so i might change that but other than that i think that it's uh looking good so let's set up um animations and then we'll go back through and maybe change up the voiceover a little bit because i'm pretty sure he's not going to know what he said there so let's do animations next we'll go into the project view and if we look here i don't believe these characters come with any animations by default so if you look at the character models and just expand it out it doesn't have any animations on it i search down here i'm pretty sure there's no animations yeah we got nothing here so what we're gonna do is go grab some animations and the normal way that i do this there are two ways one is just grab some animations off the asset store pull them in and retarget them at the characters i actually tried that with some of them and i ran into some issues that were just kind of a pain so i figured i would show the more interesting way that doesn't require anybody to go buy any specific asset pack and isn't nearly as opinionated and that's just using the free animations on mixamo.com so i'm going to pull it up right now and then i'll drag it over and show you exactly what it looks like once i get logged in logging in oh way too many accounts and we'll drag it over here so if you've never used this site before oh look i've already got my character uploaded but i'll run you through it real quick if you've never used this before it's actually really cool you can grab a whole bunch of different characters you can just pick a character that you want to use you can then go pick some animations that you want to target on it so you pick the character you pick like a sitting laughing animation i mean there's all kinds of different animations not just the normal walking talking or whatever there's a couple thousand animations on here you pick the ones that you want to use and then you download them for unity so you hit download you pick download for fbx for unity and usually without skin to grab the animation the first one you'll want to grab with skin because that's getting you your textures and materials and stuff but the animations that you're going to grab afterwards you'd get without skin so let's uh stop with this character and let's go try out our own actual character so go to the characters oh actually just hit upload character there we go and then i'll take the knight here so i'm going to drag this down just a bit here let's see if we can reposition things a little bit i'm going to take my knight model from the characters folder take this polygon knight and then drop it right on to oh so that didn't do it let's try that again let's reposition the window so i just need to get the file onto the little drop area there there we go now that that's done let's see should i mess up my entire obs layout as long as that looks good it should be good get that in position and that one so characters uploading and processing it takes usually not very long there we go looks like it's done already and then let me see we've got our character up we'll hit next and we'll hit next and then we're just going to go grab some animations so i want to get a couple animations here i want to have some sort of an idle animation something that just has them sitting there when they're not doing anything like active oh i need to go to the animations tab find an idol so thinking like um not really like a combative idol but something where they're just kind of standing there waiting like relatively chill um that could be an interesting one that's a little active though yeah see we got an old man i don't know a breathing idol this might be like kind of the one we want by the way the reason that you're seeing all of these characters here and the character looks really really weird i'm gonna talk about in just a second i realized i hadn't mentioned that and called it out because this character looks like he's all kinds of messed up it's actually five meshes in there that are all stacked up we uploaded that that's just the way that the characters set up in the pack um i'm gonna hit download though i'm gonna take this idol we're gonna do it without skin make sure it's unity fbx for unity and hit download that'll give us the first animation i'm going to drop it into our folder so i've got that path copied already so just paste it go up here we'll make an animation folder and then in here we'll drop in the file so we've got the breathing idle save that off and then let's go grab a walk i want some sort of just a walking not backwards just a walking forward let's see walk backward walk backward with a briefcase whoa stop shaking my screen walking there we go that looks good i'm gonna make this be an in-place one though and then i'm gonna expand out the character arm space a little bit so his arms just kind of go out a little bit more you can control that with this little slider right here this helps move them out so they're not kind of clipping through his body i find that it's useful when you've got characters with armor especially let's download again download and we've got a night idling and a night walking i don't know do we need any other animations for this right now oh i want one where they're kind of like cheering or talking or something like that or moving their hands or something let's do talk talking at a water cooler talking um okay yeah that one looks like me talking so i'll go with that let's expand out the arm space again a little bit more and then we'll download this one so let's download it as an fbx without skin and save let me see if there are any other ones that i want to grab here yeah let's take this one too let's move out the arm space and download it too so we got two little talking animations a walk and an idol that should be i think pretty perfect for our character so let's make this talking um one arm this is the one where he just moves one arm out while he's talking all right now i've got all my beautiful animations what do i do with them the first thing i need to do is go hook them up i need to go to my character here i need to make sure that my polygon knights rig type is set to humanoid it should be by default but if your character is not humanoid make sure that you go switch it to humanoid then we'll go to our animation folder i'm going to select all of them just hit ctrl a to select everything in the folder while i'm clicked down there by the way and then we're going to go from generic to humanoid but we're going to shortcut it by going to avatar definition and hitting copy from other avatar that'll bring up the little box here where i can select an avatar and we're going to search the avatar or search for the avatar of the night so hit the search box we'll go find our night and i'm going to click on it and it's going to say do you want to change it to humanoid damn it change that over and that's probably good but i want to click on this and make sure that this is the right avatar because when i hit the search there were two different options so let's go double check the first one is the one in models characters and the second one is in models fixed scale characters we're using the one in character so we have the top ones correct just want to double check make sure i've got the right things and then hit apply now i should be able to see my animation so i'm going to go take a look at them and go look at this breathing one i'm going to drag the preview window up here definitely like the preview window is a separate tab now and not that weird little pop-out thing it feels so much better all right so i've got the preview window here let's hit play on our animation and see what the breathing idle looks like okay seems fine let's try it with this character on it oh there we go see what it looks like with the actual character that looks not bad at all let's try the talking with one arm okay a little bit in his body but not too bad talking with two arms and the walking looks good so i've got all the animations here kind of working and i want to go set it up so that they actually work with the character next step is going to be to create an animator controller so if we go look at our knight both of these knights already have an animator on them that was automatically added it's probably probably put on by whoever made the prefab and they have a room for an animator controller i believe is there an animator controller in here oh there actually isn't even one in the project i thought maybe there was a sample one in the project but there isn't even one of those so we're gonna go create one we'll go to the animation folder right click create and choose animator controller animator controller really just controls what animations are playing on a character it's not very complicated but it can look a little overwhelming if you're new to it i'm going to call this a night or just name it night because it's going to be the animator controller for my knights select all of my night no that's like all my night animations like both of my knights and i'm going to assign this controller to it but both of these knights are selected here that's why it's got the little dot and both of them now have that animator controller you can see knights on them both now i want to go into the animator controller just double click it and it'll pop up the animator window if you don't have that you can go to or is it window animation and then animator and pop it up it may just be lost off to the side or something let's see move this preview window back down and out of the way since i don't need it and then we're going to set up our animation so the first animation like the default animation for our our character here is just going to be an idol they'll just be standing there doing nothing until we make them walk or talk or something so we'll expand out the idle animation here this is the fbx so the fbx here actually has the model in it well i thought i did it without skin i might i might have missed something there but it also has the animation here so oh no i did do it without skin i forgot to drag the character down there for the preview so what i want to do now is just take this breathing idle animation that's a child here and drag it out and if you don't see that um you could be in this weird uh icon view make sure that you just grab the slider down here or control and mouse wheel and then just expand it out grab that idle i've got my breathing idle animation here and now that should just kind of play automatically if i go to the game view and i hit play i should see him breathe at least once let's try it hello commander we're happy that you came to help us we need you to send the knights to the right castle can you click for us all right yeah they're breathing i mean they're they're wobbling a bit and they've stopped but they were breathing right so let's go change up the breathing animation a little bit a couple things that we want to do first is we want to make it loop because loop time was not on so things aren't going to loop um the next thing we could do is just bake in the position so just hit bake bake and hit apply and then hit play one more time now we should expect him to keep playing the animation commander we're happy that you came to help us we need you to send the knights to the right castle can you click for us here we go so now they're animating they should keep animating and notice they're not doing the weird wobble anymore because we baked in those positions we're not using root motion here at all so that looks good now the next thing i want to do is make it so that when he's talking he actually plays some sort of a talking animation so let's actually make him begin with a talking animation we'll go to the animator and we'll go in and take maybe the talking with two arms drag that out here and then we're gonna make this the default animation so i'll right click set layer as the default state and then i'll right click and we're going to make a transition and then i get this arrow that i can just drop i'm going to drop it onto breathing idle which will make it transition from talking into breathing idle once talking has finished i can click on the transition and see a little bit of detail about it and if i got my preview window back up here let's drag it back up so you can see it i can actually preview the transition so it goes from this and then transitions into the uh the idol again that that's kind of how it's going to look so let's hit play and just try it out they should do kind of like that oh commander we're happy that you came to help us we need you to send the knights to the right castle can you click for us so obviously that's not perfect it's a little bit um weird like the camera transitions weird you can't see the arms or anything else so i think the first thing i want to do is just go modify the transition real quick i'm going to go to the blend list camera i'm going to go to the scene view real quick and i'm going to take this first v cam i think i'm just going to pull it out a tiny bit let's go to the game view let's see i'm going to drop the game view here side by side i'll make this one solo for just a second grab it hit w move over here whether it's right mouse button and just wasd to move around and then shift to kind of sprint you're not used to unity you're just not familiar with running around the editor and then q and e go up and down too really good to get get fast with those all right let's zoom that out just a little bit i'm thinking more like this and then i'm gonna make a second camera so i'm gonna start really close and i'll do control d duplicate it let's make this one be camera two ah let's call this camera two i'm close talking and then i'll make this one camera three bar shot or far um castles there we go and then what i want to do for the second shot is just pull it out a little bit more so take select the second shot and drag it out oh let's make it solo mode drag it out just a bit so that he's talking and it's kind of uh like that maybe i even pull it down a little bit and rotate it up just a little so now let's go modify the blend i'll select the blend here we'll make sure that oh the order is already good that looks good we just want to add in another blend here so i'm going to hit plus and then we're going to go start with the first one i'll hold it for like maybe half a second then i want to do a blend to the second camera and i want to do that over maybe half a second so that it's a one second until we're at the full party says hello commander and then the arms are wiggling or whatever in fact maybe i'll just do it instantly maybe like a point one second there and then we'll do a hold here for i'm thinking the three seconds that we were doing before and then zoom out let's save and try that i think that's gonna look and feel quite a bit better without having to do much work hello commander we're happy that you came to help us we need you to send the knights to the right castle can you click for us all right that's looking a little bit better so let's see what do i want to do now thinking i've got my cameras transitioning we've got the guy animating i think the next part is going to be to i guess set up some actual gameplay let's make it so that um when once they are ready to start so they just click uh well i don't want to make them start um remember to say click on the click or click on me to start or something i don't know don't worry is there a prop that i could make them uh let me see if there's a prop maybe make like a little prop they just break or do something with real quick to start the game let's see is there a broken version of the box or anything oh whatever we'll just start it without giving them any any input so we'll just have the game start so i think the first thing we'll do is just spawn up some number of knights and a number of things that need to be in a spot and kind of link that up so the player can pick or the really the kid can pick the right one for the army of knights so let's do it oh i know how we'll do it we'll line it up like this once they start i'll have the knights kind of walk on screen we'll go bam bam bam they'll kind of walk right on up maybe we'll turn the camera view um a little bit like this they'll walk right up and then there'll be a certain number and then you can pick which castle they need to go into so let's um let's make some prefabs let's make a prefab for the knights that are gonna walk and then let's spawn some nights make them walk and then um yeah then we'll go from there i don't know we'll start there i think that seems like a fun place to to begin so i'm going to make a prefab folder create a new folder prefabs we'll go into here and i'm going to take i want to use this blue knight as the basis let's just take the orange knight and i'm going to use him as kind of my starting point i'm going to make a new prefab off of him instead of a variant i'm not going to use the cinti prefab i just want to have like my own copy of it that's my own little weird custom version so i can do whatever i want with it not worry about the asset pack so here we go i've got my knight and i want to make him walk so let's start by i guess let's just make it navigateable let's make it so that he can slide up here and play a walk animation so first thing we'll need is a nav mesh agent just drop on a nav mesh agent if you've never used nav mesh agents before they're extremely simple it's built into unity you should definitely check it out for simple navigation stuff i'll handle most problems uh let's go into the navigation window window and it's under ai and then navigation it's weird it's like the only one that's got its sub menu with only one thing under there feels like it should just be its own menu anyway let's go to the bake option and hit bake i expect nothing's going to happen yep just goes instantly to doing nothing it's because the ground here or the parts that we want to be walkable aren't barked off as walkable so if you actually select the ground pieces here actually this is kind of nicely built for this i can select this ground here and maybe this ground here just holding ctrl selecting both of those dirt pieces and then i'm thinking like this piece here this piece here and this piece and this piece so right now i'm just selecting all of the parts that i want the characters to be able to walk on holding control and just clicking on them so there we go i got that one and i want them to come all the way into here so i'll click these pieces too yeah that looks good so with all of those selected i'm going to go to the static option which oh you can't really see there let's go to the navigation window instead go to the object section and there's a navigation static button or check box here and it defaults to walkable the other way you can do it is in the inspector the static thing has a navigation static drop down option you can pick that as well the same option you can see that's why it changed there and it got picked and i've got 10 objects selected i like the the new editor updates that have been coming it's really nice let's save the scene now go to bake and hit bake again and now all those areas turn blue so what that's done is just bake out the areas or save out like calculates out saves out all of the areas where things can walk and it marks it here in blue so now the nav nav mesh agents will just be able to go along this navigation path and work kind of magically almost without us having to really write a whole lot of code we just give it a destination and it kind of figures out the rest on its own so here's our knight our orange knight i'm gonna rename this from character knight zero two to orange knight and i'm gonna hit f2 copy that and just paste that down here too so the prefab name matches my character name and it doesn't have that um interesting cinti name so let's let's see what do i want to do i'm going to duplicate the knight and just put him right over here i think yeah so that's what i'll do i'm going to have the one orange knight be like the leader there and all the other knights come to him and then he would count him up so let's duplicate him we'll hit w i'm going to move him over here and then we'll turn this guy around real quick we're going to work on spawning these guys and disabling re-enabling all that stuff afterwards first though let's just make them all exist so duplicate w duplicate w duplicate w duplicate w duplicate w duplicate w and what if we got one two three four five six seven eight and um well yeah we'll do nine do a total of nine so we can have up to ten nights come on the screen at once that seems pretty good now let's make a script for the knights to go to their positions now i kind of want to just set up positions for these knights for where they should be in fact it kind of makes me feel like maybe i should just move these knights over here set them up and figure out those positions but i guess um for now i'll just make them move to this guy let's call him the orange knight leader i'll make them move to him cluster around and then we'll clean it up so that they don't look like a weird mess of guys trying to run into him so we'll start that way so let's begin with um making the orange knights just be able to go to their leader so we'll add in some scripts we've got oh we've got a couple scripts here already i'm going to delete all three of these because we're going to restart all of our code and we're going to just begin with a simple night script we're doing this totally different direction than last time and it doesn't really matter because we're just building out a game we're gonna build out something simple we're not gonna it doesn't really matter where we started i guess it really just matters that we start so we're gonna get all the code done eventually as long as we write code and we're constantly writing stuff and adding more we'll get there so let's go to our orange nights go select them all go add in our night script that i just created and i'll open that up it's going to open up in writer and it's probably going to pop up and ask me yep do i want to open a new window i'll hit yes and bring that over here so for anybody who hasn't used ryder i've talked a lot about why i love it um there's videos out there about it and stuff so if you're curious you can go check it out um it will you can do all this stuff fine in visual studio or whatever editor you want though it's just personal preference and something that i really like to use i find it super handy all right um let me take a drink here and open this thing up and talking a lot so our knights need to go to their leader and i need to give them a reference to the leader so let's see let's um let's go into the actually let's get rid of the update method completely let's just get rid of start two and let's add an on enable let's zoom in a little bit because on enable has that neat little trick of allowing us to just click the object off and on again to make it run again so it's an easy way to just kind of quickly test something and it kind of matches with what i want because when the knights are enabled or when they spawn i want them to walk over to the um to their knight leader so when that happens i'll just say git component oh i feel like i might be losing my voice here nav mesh agent there we go so we'll get our nav mesh agent we'll set the destination we're gonna set it to our leader's position so say leader dot position we don't have a leader yet so let's go generate one alt enter and generate a serialized field and what we really have here right now is a transform so we'll just start with that as the default now it could be like a nav mesh agent as well because i imagine the leader needing to be on the nav mesh but i think we'll just start with a transform because we can be more specific with the later delete those extra using statements get rid of that extra line here and that's literally all i need for this first bit let's turn this into an expression body method that it shrinks down even more and we got tiny little bit now of course we could cache this but we're only doing it on enable so we wouldn't really save ourselves any time we'd just be calling it at a different time caching it and then not using it so right now we'll just call it with that um let's hit play and if you've never seen navigation before you prepare to be completely amazed and blown away as these knights start walking in and doing their thing while they're idling and acting weird if you have seen navigation systems then uh hopefully we don't see any bugs you will actually you'll see the bug right now we're happy that you came to help us we need you to send the knights to the right castle can you quick for us no nights look at that the leader transform's not set so luckily luckily i said that we could use on enable because it has a neat little bonus effect of being able to reuse it let's go grab the orange knight leader in here drop it in disable re-enable and see if our guys walk over there there we go we can see him kind of sliding over and it worked so it kind of worked obviously we're getting the interesting terrible clustering that i mentioned and we need to fix this so let's go do that and then we'll retest it real quick and then fix the clustering and all the rest of the stuff and continue on so let's stop playing go drag the orange knight leader down here as the transform we'll save hit play and now we should expect to see something a little bit more interesting hello commander we're happy that you came to help us we need you to send the knights to the right castle can you click for us there we go that's looking better okay so now we need to make it so that the knights don't do that weird clustering i want to make it so that but don't do that first order i want to do selection of a number of nights um oh this is tough decisions decisions decisions which one do i want to do because i could either i think what i want to do is make them move into positions first thing i want to do is just disable some of these because i want to have nine total but i want to start with something a little bit more manageable and then scale it up so we'll start with like maybe four come out at once at the beginning and then we'll randomize it so more and more can come out but i don't want to have nine guys on the screen at once kind of overwhelming me and making it look weird what i do want to do though is create some transform points for these nights for where they're gonna go instead of going to a leader position they can just go to an open spot so i could just have you know nine spots here available so to do that i think what i'll do is just um i want to do this let's create an empty game object we'll go create empty i'm going to drop this right down here and then we'll hit control backspace to just reset the uh the transform there we go oh well that's not what i want to do at all let's ctrl shift f it lock it right here and then we'll hit w and then we're going to drop in a knight so i'm going to take one of these knives duplicate it make it a child and then reset the transform so that it's a child there and kind of shows me exactly what it's going to look like i'm going to reset the rotation here and then let's see if we can drop this sucker down to the ground there we go holding v we'll just do a little vertex snapping right there and i think that that should get me a better position so i'm on the rotation tool now with e holding control lets you drag it by a certain number of angles i think it just is it 15 degrees per yeah 15 degrees per snap there so let's go look at our game view again with the second camera let's go to our second blend list camera the far castles one in solo mode there we go now i can see what it looks like i'm gonna go to the drag the game view side by side here get that a little bit better up there and then reposition these oh why is it switching um let's just disable this camera can i disable that camera come on okay here's what i'm going to do i'm going to go to this view i'm going to lock my get myself right here there we go and then i'll just turn it okay there we go i got my character oh i get turned the wrong object i don't want to turn the child here i turn the orange knight child i want to turn this spawn point object let's name it to a or it's not a spawn point let's call it a standpoint i'm gonna duplicate it and hit w and move one over here hold ctrl v get it to snap and duplicate again move another one over here maybe like right here rotate it a little bit duplicate w move them right up here duplicate and maybe like right here rotate it a little bit so that's one two three four five six i need four more so duplicate again w move this guy back over here okay this camera view is definitely going to have to change and oh actually he can't get all the way there that's off the dirt and then we'll do another one up here oh man am i running out of space here and maybe another one over here by the steps and we'll rotate this guy all right this looks a little overwhelming for nights but again i think it's probably more than i want to have so i'm just going to expand these all out we're going to delete the actual night children here so select all of these orange knights that were just kind of showing me the position i go and delete them so this gives me all of my points that i want to assign and here i'm just going to assign orange night 1 to this position we'll take orange knight 2 and assign them on to the next one we could automate all of this again but the process to automate it wouldn't be worth the time that it takes it wouldn't save us the time we can just manually drag these in we only have a couple so we're just gonna do the first three for now and i'm gonna leave the rest of them out and hit play one more time watch and they should go to their own spots and then we'll start working on them hello commander we're happy that you came to help us we need you to send the knights to the right castle can you quick for us there we go so i get my four nights out there and um i feel like maybe i gotta get rid of this guy because like having um i guess because i want to send the orange knight to the castle there's four of them yeah i'm gonna do that let's see so i'm gonna stop i'm gonna delete the orange knight here this leader guy like he's a little bit confusing and it's going to get more complicated with it just use those three so the three guys will come out and then we'll tell him to select the right castle so once the guys get there and they finish reaching their destination i want to make them turn to face towards the camera i guess so let's um let's do that let's say when they've reached their destination so do an update and say git component and net and here we're going to get the nav mesh agent and we're going to say like what is it remaining distance if the remaining distance is less than or equal to 0.1 then we want to turn into the direction of our leaders transform now here this is a bad idea because we're getting the component for the nav mesh agent over and over and we kind of already shortcut it out of caching it before because there wasn't a benefit but here there would be a benefit so i'm just going to add in a little line to cache it so i'll add an awake here and we'll say that our nav mesh agent equals git component nav mesh agent so do underscore nav mesh agent equals get component nav mesh agent i hit alt enter generate a field for it and then hit alt enter here to turn this into an expression body get rid of the two private keywords that are just redundant shrink things up a little bit and then let's replace the calls to get component nav mesh agent with the nav mesh agent so i can paste that there paste that there and check to see if the remaining distance is less than or equal to 0.1 and i'm just going to set my forward to match the um the leaders forward so i'll just say transform.forward equals leader dot forward now if you're thinking hey we should animate this and make them turn around nice and smooth but again building it for a kid they're not going to care if they want to see cool little dudes there they're not going to care that he instantly turned around um and it's not not worth spending the time so let's i want to hit play but before we do i want to do one other thing let's go into the animator go to the animator and right now the animator only does a talking and an idol it starts in talking and goes to idle let's update our animator so that our animator is well let's hit play real quick watch him do the walk thing and then let's update our animator so that our animation oh come on intelligent we're happy that you came to help us we need you to send the knights to the right castle can you come for us there you go so the guy's all turned and they faced the right way let's go through the animator part now so let's see our animator windows right here and we're going to take the game view i'm just going to drag that over here so we get a little bit more space get our animator back up here so by default we're going into talking and then transitioning into idle and i want to make that different i want to make this more like a normal character controller let's go to list view mode and let's start in idle so i'll make this the default and we're going to make a transition into talking so actually we'll leave the transition out of talking back into idle there but we'll make a transition from any state into talking so i'm going to grab talking move it up here right click it make transition and drag it over and to do a transition from one state to another we need a parameter if you're here you have layers and parameters click on the parameters section and it's a little drop down and you get four different types of parameters you can use we're going to use a trigger parameter which is the kind that fires just once doesn't keep state there's ins floats and bulls those all just keep the state and they don't change the trigger is like a one-time thing it fires off once or it's true once when you actually say set trigger so we'll say set trigger i'm just going to call er not set trigger we're going to name our trigger and we're not going to name it trolk we'll name it talk so let's double click t-a-l-k and then we'll use that as the transit or the parameter as the transitions condition there we go let's click on it so i've got the transition selected here we'll go to the condition section and the hit plus button and talk automatically appears there's only one parameter so it just defaults to that let's add in the walking animation now so expand out walking go grab walking and drag it right up here so it's another entry we're gonna make a transition from breathing into walking so right click and make transition click left click on walking and make the transition into walking i'll click on the walking transition here and let's just add in another parameter so we'll add in a boolean here we could add a float to measure speed or something we're just going to do a bool for whether or not they're walking though because these characters just move at a static speed so let's just say walk and then we'll choose that as our condition so i've got this transition selected we'll hit plus go down here choose walk and now when our walk variable's true it'll switch to walk we'll make a transition out of it by right clicking make transition click on the little transition here and here we want to make another condition we want to choose walk but we want it to be false so when walk is false we'll leave the walking transition we'll go right out back into breathing idle all right if we save this off and we take our animator just drag it down here we can actually kind of play with this and see it in action let's go just um look at maybe i don't know we'll use the character blue knight we'll let everything else kind of go as it wants but then we'll use this knight hello commander we're happy that he came to help us i can hit talk i need you to send the knights to the right castle and you click for us and hit talk again and he does it again you see the talk animation playing one more time i'll do it again and if i hit walk let's see any second now he'll switch into walking and i'll show you why this is going to take a while to show you how to fix it there he goes now he started walking and then he stopped and if i uncheck it he switches back into idle a couple little things that we need to address first is this transition the transition from breathing to idle needs to not have exit time on if we switch from idle to walking we want to instantly switch same with the transition out we want to uncheck the has exit time this just makes it so that it doesn't play through the end of the animation it just instantly transitions um talking we do want it to play because we want to play all the way through that's pretty much it though let's try again let's hit the talk button talk looks good ends goes into idle we hit walk goes right in doesn't loop yet but it goes right back out instantly as well let's go fix the walking animation we'll go select blocking i'm going to go to project view see if i can get it selected here still running and still playing but i can go check the loop box check these two boxes here hit apply and let's go back to our animator hit walk uncheck it hit walk again look at that it's looping didn't even have to restart the editor pretty cool right and i can hit talk and he'll stop and do the talking and then switch back over in fact let's go adjust that talking animation too let's go bacon those positions go to the project view talking and just go bake fake and bake and apply sorry hopefully those aren't off screen that i'm checking the fake into pose for position x z and for position y all right let's see um got our characters working with animations now i just need to make these guys animate while they're actually walking so let's do that next we'll go into our orange night and we'll open up the script here and then when it's updating what we could do is just update the animator's walking state based on our speed so we could get a reference to our animator let's change this awake into a statement body hit alt enter and it switches right back in one of the millions of reasons that i love writer and we'll say underscore animator equals whoops not that control z control z equals git component of type animator we'll add in a field hit alt enter and just generate the field go back delete that extra private keyword and copy animator and then right down here we'll say animator dot set bool we'll set the walk bool to either true or false based on what our nav mesh agent speed is so say navmeshagent.speed greater than zero so if it's greater than zero we'll set it to true otherwise we'll set it to false so we'll just set that every frame that should be fine and should keep it kind of in sync and updated let's get rid of this extra private keyword save ctrl shift b to do a build jump into unity and now let's watch if our knights start walking and then switching back over to an idol once they reach their position which is what we should really we need you to send the knights to the right castle can you click for us oh they didn't switch out of walking state let's see why didn't they switch because select a knight they've got the walk on them the knight is here um oh wait speed is um not the right variable that's the maximum speed sorry um we want what do we want to check here velocity.magnitude sorry they checked the wrong variable let's save that do a build and go back in by the way that's this variable right here it was the 3.5 so if i'd cranked the 3.5 down the actual speed down it would have gone down whoops wrong property hurray come on field we're happy to help us we need you to send the knights to the right castle can you click for us there we go and they've stopped so looking good we've got our three nights here now let's make it so that the two castles pop up a number of nights so that we can see like how many nights are in each cast or or how many nights the castle holds and make sure that they click on the correct number in fact actually i want to close this gate let's go to the scene view here i assume this gate closes without much work w oh wrong one that's a wall back behind let's select the correct object w bam look at that the gate is down all right so let's put in some numbers over these gates and choose like uh random numbers for them first we'll add in some numbers that we can show that just represent like which number is the number for that castle then we'll set up a system to generate those randomly and then link that up with the number of knights that are going and all that stuff so let's go to our well we need a text mesh pro so let's go to game object ui and text text mesh pro i think that'll work and then we'll just leave the name as it is go to the canvas and we're going to switch this from being an overlay canvas that's just showing text let's see do we have it yeah that new text right there in the middle change it to be a world space camera so our world space canvas that camera check world space we'll change the scale to 0.01 or just .01 0.01 on all three axes and then i'm going to move it right over here so i'm going to put my my scene view right over here by the the spot where i want to use hit ctrl shift f which will move the canvas there and look at that i now have some text kind of floating right around where i want to be now clear out the rotation a little bit make this maybe 180 0 0 and then just drag not make sure i want to grab the canvas not the text and grab the canvas and just drag it over so that it's kind of in front of this object i think that that's probably about good let's adjust the canvas size now i want to make this maybe 300 by 300 so that it fits kind of right above the castle like right above the castle gate and then i want to select the text child here the text child should be zeroed out and let's set it to stretch and fill and i'm going to center align it and center let's see center align center align that it's in the middle and then we'll just hit auto size and put in a number let's put in like the number 10 which should be the biggest one and crank up the max and see how big that font actually gets that's up to like a 268 point font let's go to the game view and hit play see what that looks like real quick and then we'll start working over or working with it a little bit more oh commander we're happy that you're here to help us we need you to send the knights to the right castle can you click for us that one takes 10 guys obviously it's a little bit big doesn't quite fit on the screen and i want to change the font up and i think i want to make that a little bit more center to the um to the screen maybe i'll put it on the gate instead of the above the gate so just put it like right here in front of the gate number of guys that it can hold let's do that we go to the scene view we'll drag that oh not the text i'm gonna grab the canvas drag that down just a bit and i'm going to change the text to just be three i'm going to hard code two of these for just a moment and then we'll we'll set it up to be more dynamic so we've got a door for three and let's just call this the left door canvas actually i'm going to call this let's name it the way i like to name them i'll just put canvas and then just put left door but it's very obvious it's canvas for my left door i'm going to duplicate it and i'm gonna make one for my right door i'm gonna move over to the right door and we'll do another control shift f to move it into position reset those rotations do a zero look at q70 270 they used very precise square rotations i guess that makes sense um and then place that right there i think if i move this over just a bit i've got a nice beautiful three now i do want to pull this out in front of the door so that it doesn't clip through the door when the player is seeing it i want to make sure this one's out in front too it looks like it is okay cool so this one's going to be with the number two to start this is like the wrong answer as the first one and then um again we'll randomize it afterwards just hit play i want to one more time to see what it looks like hello commander we're happy that you came to help us we need you to send the knights to the right castle can you count for us okay so okay i think that's good but i think the next thing i want to do is say like this one holds three guys and like light it up and then this one holds two guys and then light it up and then have them pick um maybe not i don't know maybe i should give that as like a feedback afterwards i don't know trying to think or maybe when they walk in i'll say like there are three nights which castle can they fit in something like that trying to think trying to think through my beautiful game design as as we uh code at the same time so let's say um you know let's make a correct point so that we can click on the right spot go to the right spot and then um and then we'll add in the extra feedback after that i think i want to do that so i'm going to make two areas that we can click to actually make the dudes walk to the correct spot or get the area or the error that it's the wrong spot so to do that i think what i'll do is just set up some clickable areas and make like a sphere or a cube here and another one there maybe make the canvases children of them or something make them relate and then make it so that when you click on them it tries to use that as the point to send the guys to and then that'll send it into like a game manager that's controlling it and give us an idea of how we want to start putting together some of that code so let's go to game object let's make a 3d object we'll just make a cube i'll do a ctrl shift f here and i think i'll just make this quite a bit bigger make it like three by three by three almost like a sphere would be better yeah let's do a sphere let's do game object 3d object we'll make a sphere here all right no i'm not going to do a sphere we're going to do a cube control z control z i'm going to do a cube that's like the size of this castle that makes sense you're clicking on the castle choose the castle so let's uh fix the rotation zero actually i probably just reset all these to zero i don't need a rotated cube then we'll hit the scale button hit t and we'll just drag this out holding control drag it up looking good hit w drag it up and i think that's good i'll turn off the renderer and we just got a big old box collider for uh left castle this would be like my left castle's trigger area we'll add a box it's got a box collider already so just check the as trigger button and i think i'm going to add the canvas for the left door as a child maybe yeah that makes sense so i'll just leave the canvas for the left door as a child of it and then i'll do the same let's oh let's drag that out first because i want to duplicate this castle move it over here i want to rotate it so we'll rotate it 90 degrees on the y drag it over and i just kind of want to line this up over the other castle like that i think that looks pretty good and then i'll make this the right castle alright so we got a right cast on the left one i'm just gonna grab the canvases and drag those under as children to clean things up a little bit and then we'll make it so that we can select one of these castles so let's go into the project go to scripts go to create and create a new script let's make a clickable castle let's just call it castle i guess all of our castles will be clickable for now and then in here we'll just look for um the player clicking on on our object so we could do something like uh on mouse down and just look for us us clicking on the actual object and then call into the game manager i'd probably set up a raycast something bigger but um i think here we'll just do something like this so i think when we click on the castle we'll say game manager dot and we don't have a game manager yet so we're going to need to generate one game manager dot select castle and we'll select this castle and that's it we'll generate a class for our game manager so hit alt enter create class and we've got a new class here an internal class called game manager change that to be public i'm going to make this a mono behavior and i think i'll just make it a singleton for now we'll keep it simple so anybody that's familiar with singletons will understand how to use it so we'll just make an awake method here and then here we'll say instance escape equals this escape and then we'll hit alt enter create an expression body out of that would turn instance into a property so alt enter just create a property and make the setter private there we go simple singleton easy enough to use let's move the instance up one line though so ctrl alt shift and the up arrow with the line selected by the way in writer just moves it up like that so now we need a way to add our select castle i want to get a reference to the instance here so we'll say instance oops game manager dot instance i missed the static keyword so we'll have to fix that instance and we add our static keyword here so it actually shows up there we go dot select castle i'll hit alt enter generate the select castle method and then figure out what we want to do here let's move game manager to its own file to enter alt enter move to gamemanager.cs and then we can start implementing this select castle so when we click on a castle if we're in the select castle mode or whatever we want to pick and see if it's the correct castle so we need to check that the castle's number matches the number of nights is essentially what we want to have so we'll say if castle dot number equals night number nice number something like that um then correct which is something like correct or let's call a method called correct or handle correct answer i don't know what it's going to do yet but we'll generate it and figure that out later now we'll say otherwise we'll handle an incorrect answer that seems good and alt-enter and generate a method for that delete out the throws because we don't really know what we're going to do with them yet the other thing i need to do is generate in our castle and our night number so let's hit alt enter generate a field for night number this would be an int it'd be like the number of nights that we have and let's just randomly generate that maybe on enable for now we'll say on enable our knights number is a random number so do random.range from uh well not zero we never want to do zero or one one zero one are kind of lame numbers let's do two to five we'll just pick a number from two to five that'll be the number that we're going to use for this run and then we don't need to just keep it in non-enable we can move it later so let's turn that into expression body we've got a night number now our castles need a number so let's add a field to it or a property hit add property we've got a number this is always going to return zero though and what we want this to do is really just return the value that it's set to so we need to have some way to set this number as well i think that um the easiest thing we could do is just go right back into our game manager and when we select our night number we'll just assign one of the castles to that number and assign one to a different number so let's change our on enable back from an expression body to a statement body and then we'll say um set it we need to set one of the castles to this number and one to a different number so let's say other number and other number equals random dot range two comma five it's going to be another number in that range r-a-n-d-o-m and then we'll say while other number is equal to our night number then we'll just keep rolling again so we're going to get in this weird little loop i mean theoretically we could run infinite number of times but real in the real world it's going to run a couple times and it's going to randomly pick until it picks a different number than our night number as this range goes up the chances of collisions are low but don't worry about that for a performance thing i just want to make sure like yes some people might worry about it and freak out it's not going to matter we're going to loop over it until we get a new number so we're going to have two different numbers and then we're gonna assign these two numbers to our two castles well let's um i guess we just get our castles we don't even need to catch them really we just find them um do i want to find them though or just add a reference i think i'll add a reference let's do that so let's add a list of castles and we'll just call this castles and we'll make it serialized so i'll add a serialized field attribute to it and get rid of that private keyword there add a little space add a little space here and clean things up a little bit so we need to add a using statement for the list using system.collections and i want to get rid of this using random statement i really don't like those i'm gonna just put in unity engine dot and just be a little bit more specific i mean i know that it's a nice little shortcut but it just feels weird to me every time and i just get mixed up and then things get bad oh actually yeah i got rid of the using system statement so now i don't even need it anymore whatever let's do another build and let's figure out how to assign the castles so we got our two castles here we got our two numbers let's say like uh castles zero equals the night number and i say castles one equals the other number and this would work i think just fine or not equals but i could assign them the numbers but i need to kind of randomize this first well first let's set it up so they can take a number let's say dot number equals there we go that number equals now here again i want to randomize this up a little bit so i need to just pick um which one i want to do and i mean since there's only two choices let's just add a simple little if statement i don't want to complicate this and we'll add an ugly if statement we'll say if uh random.range 0 to 100 is greater than 50. so 50 just making it 100 to 50 in numbers without using decimals for fun so if that's the case if we roll greater than 50 so half the time then we'll set the numbers like this and then i'll just copy this and do like an else again not the prettiest code but we can just switch the places here there we go so now we're setting one castle to one one to the other now when we set this number though it's not going to update our text so our text isn't going to show up in there and i want to clean that up too we got a couple options here we could just have an update method that's reading our number constantly and setting the text that's really the ugliest way to do it um another thing we could do is just add something into the setter here so that when we set it does it i think what i'd prefer to do though is just make a public void set number that takes an int number and then here just says number equals number there we go and then making the number property here be a private setter and now what i can do is when we set this number and we replace it i can also just update the text so i turn this out of an expression body property to a statement body i have a habit of doing that by the way just starting things as expression body properties now assuming that it's going to be one line and then expanding it out because it's just an authentic to change it i could feel like it's almost list typing i don't have to hit shift as much alright so when we set the number let's set the text as well so say text dot set text and we'll set it to number dot tostring we don't have a reference to the text object so we'll generate one alt enter and generate a serialized field and that serialized field is not going to be an object it's going to be a tmp underscore text which is the base class for text mesh pro text objects it works for the yu gui ones and like the the world space the world space and the overlay ones it works for both of them and you can use it as the way that you reference it instead of having to specify which specific one and the names a lot shorter so now we've got our set number which sets the text and the number we just need to call it i'll copy that go back into game manager and here we'll say set number and pass in the parameters instead we'll just do a paste paste let's see i'm going to here watch this we hold alt click drag all the way over here paste and then open parentheses pretty cool trick and then i hit end left arrow and close parentheses that a little bit of time saver there i hit enter though that was a mistake so i hit escape or control z and undo it but there you can see the little shortcuts can come in pretty handy let's paste this one too and let's see castle. wait if oh no that's not right that's the problem when it comes copy and pasting sometimes you get too fast if the castle dot number is double oh oh look at that there's even a bug there in the numbers thing setting it and making it have a private setter called that out i wonder if anybody called that out in chat i assume so so um thank you in advance if you already did by the way if you're still watching and joining us live um thanks for being here and hanging out with us and following along um don't forget to like subscribe share and all that stuff it helps a lot if you just drop the video up on facebook or whatever other places you use while we're going through stuff also i try to keep an eye on the chat but i don't want to get too distracted and and go off course so if anybody has um anything really important or something just feel free to type in there and i'll keep an eye on it oh yeah it looks like uh there was a call out on my missing equals in the operator thank you funny i should have known keeping an eye on that stuff would help feel like a second person that's like monitoring and filtering and telling me all the all the things that i need to know need to pay attention to there all right so i've got my code working and i don't think i've hit play in quite a while let's go see if we need any references fixed up but we do we need a game manager creator wrote a whole bunch of game manager code never made a game manager let's go to game object create empty i'm going to hit some square braces and call this game manager and then we'll add the game manager script whoops game manager script that we added i'm going to reset the transform just because i like it to be cleared out and then we'll go assign the two castles got our left castle and our right castle why did those not assign plus plus go take my castles did i not oh didn't add the castle scripts so i go select those two castle there we go and then oh these actually need their references to their they need a reference to their text mesh pro text object i'm going to show you a little trick for anybody that hasn't seen it real quick instead of going in there and setting them up let's go into the castle script here and right at the bottom we'll just add an onvalidate i'll get rid of that private keyword again just don't need it and we'll say if underscore text is equal to no text equals get component in children tmp underscore text add a semicolon close that off save do a build and now when we go back in the on validate it's going to run after it compiles and it's going to automatically cache that text the first time so i don't have to go in there and select it for each one there look at that it already did it automatically handled so i'm going to go back to my game manager go assign whoops got the wrong thing here let's just drag it somewhere that's invalid and let go i'll take my two castles though drop them in here and now i think i've got everything hooked up so let's save hit play and see what happens may i expect really happen we're happy that you came to help us we need you to send the knights to the right castle can you click for us okay so i got a three there and i got nothing on the other one what happened here let's go take a look i got this canvas um the left one has apparently nothing on the text the text says four where's the text at let's go find it so go select the text object oh it's way the heck over there why is it over there where's the canvas canvas moved the castle moo didn't move um okay what have i done here oh i think i i messed up in my in my parenting there let's unparent these i'm going to unparent that actually no i'm going to repair that let's reset the position here oh it's i bet it's a scale because i've scaled up the child here that's you know i kind of messed things up that was a mistake of mine let's move this out i'm going to move the left canvas door out i'm going to make it not be a child because i i can make it be a child making ui as children of objects especially ones that i'm arbitrarily scaling and messing with is going to cause some problems and there's really no benefit to it so i'm going to take them out drag them back out make them just root level objects it does mean that my on validate's no longer good so let's go delete that save and do another build but the references are already there so i don't have to worry about it i've got my references i've got my door let's see where's my other door all right door move the sucker over here again get this in position i just i know that i'm probably gonna move these things around so oh oops control z i hit the wrong hotkey there there we go got my door in position again i think that's good let's zero out that rotation 270 and 0. all right now i'm going to save hit play i want to just make sure that the text numbers are showing up there i expect to see a three-on commander we're happy that you came to help us we need you to send the knights to the night castle can you click for us i got a two and a four and i've got a total of three guys so now that i've got that working i've got the part where i'm selecting the ones actually let's make sure that we can actually select them first let's go in let's go to our knights and let's see our game manager we've got a select castle let's just add in a break point right here and we click on a castle we check the castle just here for getting the right one so we're getting the correct answer on that one hit f5 cool never click on the other castle i expect we're getting the incorrect answer yeah okay looks good so let's make it so that we actually have the right answer um actually let's make it log real quick and then we'll make it so that the right number of guys shows up so i'll go to my game door let's go to the game manager script and in the correct and incorrect ones just say debug.log incorrect and then we'll do a debug.log correct just so it's a little bit easier for us to tell what's going on without going into debug mode adding in a break point and stepping through things that can be a little bit confusing especially if you're kind of new to this stuff um even if you're not it might be a little bit confusing all right so let's go make our knights now spawn based on the number of or the number that we select which i guess happened in our game manager we pick a night number and then we pick another number and then this deals with all of the castle stuff so let's uh minimize this let's take a look at this all of the stuff here is for the castle so it's picking numbers for the castles that don't really apply to the knight so what i'm going to do is select it all hit ctrl shift r hit extract method and then we're going to make a method and i think i'll call this like um set castle numbers there we go so we'll select a night number then we'll set the castle numbers then i want to set the night numbers too so i want to do something to set up the number of nights that we actually want to enable so i think we'll write it here and then we'll just extract it into a method so we'll say four or less yeah let's do a for loop we'll do four tab tab no we're not going to do that let's do something and we want to loop through all of the nights that we have available and then decide whether or not they should be on based on essentially like if their index is greater than or equal to our night number that way we can just loop through once it's nice and simple and the code is easy to read so let's make a list of knights copy the castle list paste it here replace castles with knights replace castle with knight so we've got a list of knights named knights we'll loop through each night with a for each loop let's say oh not castles we want to do nights hit tab tab look at that it's so beautiful it just guesses exactly what i want so for each night in nights we want to oh actually let's change it so i don't want this to be a four each loop let's make it a for loop we'll be making a four a for loop with i as the indexer to go four each night or four zero two in the number of nights we get a night here knight is knights at index i now the reason that i want to do the for loop is we'll say knight.gameobject.setactive and we want to set it to i is let's see less than yeah less than gotta think it through real quick in my head less than the knights number and that's it so that will actually turn the objects on and off based on whether or not it's the right number of things so let's sync this through real quick and then we'll continue on and actually run it so imagine we roll a two we've got five nights in the list we go through the first knight as index zero uh we get that night i is zero the i is less than two because we rolled a two here then this first one would be on the second one comes through it's at index one that's our second night one is less than two it's on next one comes through it's three or it's index two it's night number three but it's index two it's no longer less than so it'll be set to off and then so on we'll go through all of the other nights and just set them off so just a nice easy way to toggle them all on and off in fact we don't even really need this reference here we could just take this bit of code right here cut it move it right there get rid of this reference completely even get rid of the braces there and just loop through each knight and set them to active or inactive now that part i might not even need to extract into its own method yet it's kind of small it's just doing it's a single loop there so i've got my knights set up let's go over to unity and add in the references so we've set up three nights so far i'm gonna go to the game manager though i'm gonna lock the view and i'm gonna select all nine of my nights and i'm just gonna drag them onto the knights field so that they all get added at once now that i've got all my nights there i need to actually go back and set them all up so i'll click the lock unlock it and let's go make number four walk over to spawn point number four number five oh wait actually i think number four is supposed to go to three right let's let's rename these um i've got orange knights let's see spawn point one i don't wanna name these um let's make this number eight i'm just gonna i'm gonna give these beautiful names because i'm feeling uh like cleaning so we'll clean that up and it makes me realize that i'm missing a number nine so i hit f duplicate it let's just move this one i don't know somewhere way over here for now kind of off screen we're gonna have to work on that view and drag it up here and make this spawn point number nine all right now i'm gonna go through my nights night one will go to point one i'm gonna have to reassign these but it's okay number two we'll go to two number three we'll go to three and again i could automate this but the amount of time that i was spent oh that was dragging the same thing on there the amount of time i would spend automating this if i'm not going to be redoing this on a daily basis isn't worth it if i was going to do this every day i was going to be dragging around nights and setting all this up i would automate the hell out of this save myself some time but not doing it so don't need to waste the time let's save and now i expect um not the correct number of knights spawn and just walk up let's go try it i think that's why hello commander we're happy that you came to help us we need you to send the knights to the right castle can you click for us all right so now we just got to send them to the correct castle so if i hit this one i should see an incorrect message and i hit that one and i see a correct message so i guess um the next thing to do is just work on the flow of when it's do you want to do the let's do the incorrect flow first because that's very simple i can just say that's wrong that's the number whatever and then i can get the number let's go download all of the numbers actually let's go to replica oh and i said i wanted to change this one because it said can you count for us and that didn't make sense at all it was very very hard to understand so i'm gonna copy this and um i think i'll just take this piece without the part saying can you count for us so i hit save take oh we gotta pick a speaker and i'm using gray here remember i mentioned earlier choosing number of styles three gives a pretty good list or a pretty good selection of the the better rpg style characters so we'll save this take and deduct a couple more seconds off of my time like so this this tool is freaking cool so let's change this this will be my new hello commander so i'll just replace that old one save it off and then i want to do a um another message so i'll say incorrect or that's the wrong one it holds or it only holds and actually you know what i want to make sure that the wrong answer is always the less don't i or let's say uh actually let's say that's that's the wrong one um i think that's good and then i'm gonna say like you clicked on number one or two or that's the number let's see that's the wrong one it's the number i say that's not it that's a that's the number there we go that's not it that's the number blank and then i'll cut into the other number in fact i might just add this in as uh as a thing so i'll say that's not it that's the number two save it and make this like incorrect two that might be an easy way to do it because i'm only doing one through nine so let's try that i'll do three different takes there's gonna be one second whatever say incorrect dash two and then i'll do an incorrect dash three and i'll just do one all the way up to like whatever i'm gonna do like nine download download incorrect dash three oh and somebody's mentioning we could do some things like math formulas um or all kinds of other stuff and we definitely without a doubt you could pretty much convert this into just about anything um the problem i'm facing right now is just number recognition so it's the problem i i actually had and wanted to solve um but i think that like the patterns and the stuff that we're going through the general project and the structure of it you could really apply it to them just solving anything and more about just getting all of the stuff kind of tied together and working and a little bit polished up too because when you're working especially with kids like having a little bit of polish goes a long way having some voiceovers having a little bit of animation having um the characters especially say their name you can add in their name to it have it like specifically speak to them super exciting or you put in voices of people they know they really will really love that they are like that's whoever talking and they get super thrilled so all of those things uh it may make a big difference uh somebody's asking about code the code editor yeah it's writer that i'm using and i've talked a lot about writer how much i love it and why i use it i definitely just make sure you subscribe and go check out the videos about my favorite tools because that that's definitely number one on the list all right let's see i'm almost done we've got one more to download oh somebody's asking do i like higher low poly games um i don't really have a preference i mean i kind of like them both like depends on the game it doesn't really matter to me um like really games with really cool graphics are cool but it doesn't send me over the edge or get me excited anymore like it used to like i kind of went through that enough times that like improving the graphics alone didn't ever push and i've seen a lot of low poly games too they don't really blow me away either right it's kind of whatever the game is as long as it's fun all right so i've got nine wrong answers let's go in and hook those up so i'm gonna go to my knight leader and i think i'm just going to make a night leader or let's call this a i'm going to call this let's make this be like my narrator let's actually just make it the narrator that's what he is and he's going to play some audio clips so i've got a list of audio clips for incorrect so i'll say list of audio clip i'm gonna say incorrect numbers and then we'll make that a serialized field oops let's see if i can make that serialized be able to zoom this in a bunch too so everybody can see it so we're going to first assign the incorrect numbers and then when we have an incorrect answer we'll just tell the narrator to play it so i'll go to my game manager and it'll say like um handle and handle incorrect answer we'll say narrator play the incorrect answer say narrator dot play incorrect and we'll just um give it the incorrect answer number so that means that i need to actually cache what that number is i need to know what the incorrect one is or have it somewhere right now i have it on the castle so i guess i could just pass that in right here in the incorrect answer so let's say castle dot number and we'll take that right here so int castle number or let's call this incorrect number so we'll paste that in here in our plate incorrect and i'll add a semicolon i'll generate a serialized field for the narrator make that up type narrator get rid of the private keyword here and then let's move it up so select it all control alt shift move up up and there we go now we'll reference that narrator and then when the narrator um wants to play something or just play the message oh we need to add a code for the alt enter generate a method for playing correct just play the incorrect one and here i think what we'll do is say get component audio source we'll get our audio source and we'll do a play one shot and we'll play the clip that we want to play so let's say clip now i'm going to get the clip one line up i'll say var clip equals incorrect numbers and just do it at incorrect number index so this should get us the number actually minus one so let's think this through real quick if the incorrect number is one we want to get the number add index zero because we're not putting a one into our incorrect numbers list we're gonna or we're not putting a zero into our incorrect numbers list we're putting in a one so index zero is going to be clip one index two will be clip clip wait index two will be clip three let's just go through it i'll show you i'm getting it's trying to say it out loud and picture it and then visualize it out here let's just go here we'll go assign the clips and you'll see exactly what it means so i'll go to the audio field we'll go lock the narrator here let's call this blue knight narrator in fact i'm going to move narrator to the front add in some square braces and make it really obvious that's my special script here drag it down here by my game manager because it is very special and i'm gonna go drag in my incorrect numbers oh i don't even have an incorrect number for one um well let's take all of these oh i don't want to do that maybe i'll just generate one that's incorrect for number one let's do it i'll generate one that's incorrect for number one just in case somebody ever adds in number one then the code will work and my indexes don't get double out of place because i'd rather just add in the extra file let's do it so we'll say incorrect that's number one bam look at that now with this still locked and my incorrect numbers there i'll go select all of these clips drag them right over and here you can see element zero is one element one is two element two is three element three is four and so on so that's our indexing is or our indices matching up we go back into our narrator um we need to do anything else yep let's get rid of this extra using statement save do a build jump back into unity hit play and go pick the wrong answer all right play play play hello come on hello commander we're happy that you came to help us we need you to send the knights to the right castle all right so we've got three nights we click on four oh and we get an exception so in the game manager i didn't hook up the narrator reference i'm just going to do that now and click again that's not it that's the number four that's not it that's the number four that's not that's not that's not that's the number four so aside from being able to spam on it and keep playing the sound effect over and over it seems to be working right so let's um i don't know do we want to fix that well let's fix the reference first um let me think what do i want to do here and decide um we could highlight the wrong number do some stuff to clean that up a little bit or we could just go let's do the i want to do the correct answer flow so that way if we start to run out of time run short on anything we have the full answer flow and everything working so let's go back in let's go to our script i'm gonna take the narrator move that back into the scripts folder where it belongs let's go to our game manager and let's handle dealing with a correct answer so if we get the right answer then what do i want to do i want to i guess tell them what the number was and i want to move on to picking a new number so let's say that's correct um that's that's that so say you got it that's the number one right i mean i know we're not using one but we're gonna do one we'll do a two a three a four and a five and all the way up so download download i saved it off as the wrong file name download it correct dash one i'll do another one for two and again i could probably split this up combine the clips and stuff but not worth the time savings so and it probably wouldn't sound as good and add extra complexity that we don't need for this so we'll get number three we'll download that save it i probably should have played at least one to make sure that they don't sound weird the simply you got it that's the number three you got it that's the number three you got it is not the best answer say that's right great job let's try that that's right great job that's the number three there we go so i'm gonna actually just change the text on each one so let's do correct dash three and let's do something like this wow that's amazing you found the number four right something like this let's get him excited let's hit play make sure it sounds cool well that's amazing you find the number four let's try wow getting separated wow that's amazing you find the number four add in some exclamation marks gonna be excited wow that's amazing you find the number four say great work i actually had it we'll add that in the next one let's download this we'll save off the take get number four and add that in as correct four and let's say we need a five let's see great work um you got the number five ah [Music] great work you got the number five there we go save and that's correct dash five and then let's see we need a six um i that's it you found the six something like that that's it you found the six maybe like that without the space ah that's it you found the number six great work there we'll add that at the end a little more encouragement all right we got four more to go download download correct dash six um let's just make a seven i'm going to speed these up save and download a seven and then we'll get the eight nine ten i guess and then be done so we got correct seven up seven and then we'll do an eight that's the number eight you found it you got it there we go try this one that's the number it you got it all right actually there's some good work there make sure that they know that it's the correct one so save that we've got two more to go and then we're back into code oops not an ogg we'll download the mp3 correct dash eight and then we'll do the last one which will be not or the second last i'm just going to make these last three the same so we'll say download for number nine correct oops correct dash nine and actually i didn't go up to ten so yeah we're done all right let's jump back over to unity now and then assign the correct one so if we go to our narrator i didn't add a correct numbers field so let's add that we'll go to the narrator script copy the incorrect numbers and zoom that in a little bit go to a new line paste it and just remove the i n now we have correct numbers we'll copy play incorrect paste it and we'll get rid of the i n and the c and capitalize that replace this incorrect with it correct replace that with a correct place that was correct and uh yeah that's it right now we've got a play correct and a play incorrect copy the play correct find references to play incorrect with shift f12 with playing correct selected or you can just click on that one usage i just shift f12 though just takes me right to it which calls to the navigator.playing correct so i just need to basically copy that so copy it paste it right here change this from play incorrect to play correct i don't want to use the wrong parameter name so i'll change that to correct number as well and then we'll make that a parameter of our handle correct answer so say incorrect and number right there and we need to fix the call that's using it or so if we go right here we can just click on it let's do that click on select castle right there and you can see here's the error we got a little red squiggly saying that we're not passing in our parameter so we'll just copy the parameter right there and pass it in now we could probably realistically get rid of these methods because all we're doing is calling into the narrator but we're going to add more to them in just a minute so we'll leave them there for now let's do a build hit play and then we'll go assign our correct numbers and we should see that we at least get the correct or incorrect text and the audio and then we'll be ready to do some transitioning on to like sending the guys off and getting the next set of them so we'll expand out the correct numbers go to the project view go to the audio field find all of our correct ones let's lock the inspector here select correct one through nine with shift drag them all right on to correct numbers and they just go automatically right there in order and i don't have to do them one at a time save hit play and let's try out a little bit of the magic and check out the oh come on we're happy that you came to help us we need you to send the knights to the right castle we got four nights that's not it that's the number two that's not it that's the number two wow that's amazing you find the number four there we go so since it's the right number what do i want to happen next so i think i want the castle gate to open up the knights to walk in so that would be like the next phase of the game they get the number right the knights cheer maybe they'll actually let's do that let's make them do a cheer like they get excited and then they'll go walking in um so let's go into our scripts i think actually let's go to the castle so when we no let's go to scripture so when we get the correct answer we'll play the correct message and then let's tell the castle that we want it to open as well let's say castles now i don't have a reference to my castle i need to find the castle but if we look at our handle correct answer we already have the castle here let's just replace castle.number with castle we'll change this from correct number to castle let's see if i can spell that right castle castle there we go and then here we'll just replace castle. or the correct number with castle dot number so now i've got my castle in here that i want to open up so i'll just paste in castle again and i'll just tell it to open we'll say castle.open seems easy enough to generate a method for open on the castle and the open method on my castle should just open up the gate now gate doesn't have a way to open i've got a bunch of different options for it i could use like a tween an animation i could just pop the gate open actually that's probably the easiest thing to do instead of i was thinking i'd just animate it up but let's just pop the gate open let's just go boom the gate pops open maybe a little poof particle plays and then um the knights walk into it that seems fun so let's see we got our open method here let's get a reference to the door so we'll add a serialized field to the door this would be just a transform named underscore door get rid of that private keyword again we'll copy the door go down to the open method here and just say door dot game object set active to false simple enough go into unity let's go find that door so here we've got our left castle and our left castle is actually just going to animate this little door right here so i'm going to go find this door object which is this cast iron gate interesting okay and let's um oh i didn't lock my inspector so let's open up let's go down there find our castle box again and i'm going to lock the inspector see collapse clap flaps we'll go select the left door there we go i've got the oh that's not it left castle there we go left castle selected i'll hit the lock and i just want to assign that door so i'm going to go find the door here go click on it click on it click on it i get it and then just drag it in as the door and do the same for the other one i need to uncheck the lock here go find this door i'll probably just have to collapse collapse collapse and then go find the right castle lock the view go select the door here and then just assign that as the child here on there so let's do a build and again oh i don't want to do a build in there i want to we're going to want to hit play so let's hit play and let's just open up the door now so it should open up the door but happy that you came to help us we need you to send the knights to the right castle we got four nights wow damn that's amazing you find the number looking good so next i want to do something with that text as well in fact i think i might want to do is just animate the door and the text like make it kind of like pop do a little bit of a thing and then disappear so that it's not just instant i think i i want to do that instead so let's go to um let's see i don't want to do this i've got this gate here let's just move the gate out so that it's not a child of this big giant object and drag it and just pull it all the way out there we go we'll make it just a root level game object i'm going to do the same for the other gate here so that it's kind of separated out from the rest of the scene the scene right now has all of the objects in here just as little objects placed inside a big giant hierarchy there's no real like uh there's not like a parent child structure or anything like that and it's not its own little prefab underneath the castle or anything so i'm just going to drag these two gates out here and then we'll collapse down the child you see it's this castle screenshot i guess it's kind of separated a little bit not not very much i've got my two gates and i want to make these work with my canvases and my animation so what do i want to do i think you know let's just make them children of their actual castle so i'll make this left one or the right one a child of the right castle make a left one the child to the left castle then on these castles i could just add animations so i'll go to the animation window go to window animation and oh maybe i do want to just put these canvases back on if i don't mess with them it's that's going to mess things up i i know i'm going to mess it all up i do yeah let's not do that oh wait left castle right castle i have my lock on i need to make sure that i unlock that before i break things all right so let's go to the left castle here and let's add an animation i'm going to go to window and then go to animation and animation we're going to hit create we're going to create a folder under the assets root here called animation so go to new folder oh i already have an animation folder let's go into that one go into animation here we'll create a new subfolder here and call this a castle doors actually no let's not even make a folder let's just do it right here let's call this open castle door left there we go i'll hit record and let's record this door opening up so we'll go down here to the bottom and to make this thing move up i can just select it go over here to maybe the one point frame and drag it right up now if i uncheck record and hit play you'll see that it just plays a going up animation i think that's probably good it's just play going up and i guess that'll work actually let's take the left door text too i'm going to drag that down here as a child while i'm not in record mode and then we'll go back to the castle we're going to hit record and let's go to the castle door text view and let's just move this canvas up as well so i'm going to go to the end point here and i'm going to move the canvas up kind of as well so that it just kind of disappears along with it so let's stop hit play and see what happens the text just kind of goes up yeah that looks kind of interesting but i feel like i don't know let me see do i want i want that to go up and then i think i want the text after that to just kind of pop out so let's do that let's go over to the two second mark and right here we'll make the text go forward so it's gonna go bam and then get maybe get bigger let's see oh no i wasn't in record mode control z hit record mode there we go drag it out so we get a keyframe of it being right there and then let's do um let's see if i select this thing here and just scale it up even more don't scale it up more i don't know if i want to i think i'll probably just want to scale it down so maybe um turn auto size off i'm just trying to think out loud here i don't want to turn auto size off in there but maybe i'll turn down the max size to like uh actually let's just leave that alone i don't i don't want to mess with the size here thinking about it from them but i do want to just make it kind of like pop up and go out so stop playing or stop recording hit play and i go bam and the text will just kind of pop up and pop up and out i don't want it to go up like that and go linear like that i want the anchor position part this on this keyframe here it goes straight up nope what did i miss wrong one i want this one here that it goes straight up and then straight out there we go looking good so we'll save that off and that's my one animation i'm going to use the same animation i think on my right castle or very similar animation actually let's just record our own animation for it let's go over here to the right castle we'll hit create and let's call this open castle door dash right and then we'll record an animation for this one as well so go to the one second keyframe we'll go select that gate and just drag it up i'm going to stop recording again grab the canvas for that one and just drag it down as a child so that we can set up the animation here go select the castle again select the animation hit record go select that canvas go to the two second or no the one second mark right and then move it up here and then at the two second mark just like i did in the other one i'm going to move it forward so that it kind of pops up and out from there so go bam pops up and out i'll just take this z transition or the z key point there and move it over stop recording watch it goes up and out looks good all right so we play we've got animations on both of those and they should both have an animator now so if i look at them both my right castle has an animator that's opening up the right door automatically and the left one has one that's opening the left door i'm going to add in a transition so let's let's make a default state we'll go to the animator here we're just going to set up these two animators separately i could combine them but i'm just going to be lazy with it and make it make two separate ones real quick we'll right click hit a create empty state and make this just the default like idle or default state right click make that the layer default and then we'll make a transition from any state into open door i'm gonna actually just drag the idle one down here and then we'll just add in a parameter just like we did before that's a trigger name it open and then we'll make that the condition so we'll say condition here is open and bam now we'll do the same exact thing for our other animator controller so this was the right one i'll go select my left castle we'll go open up the left castle controller let's go to the project view real quick and just see where that is though left castle go select the left castle controller you see it's right here in the animator folder or the animation folder just like the other one here we got the same setup so i'm just going to move that up here we'll make an empty state we'll name this idle or it's not really doing anything make that the default for now and then we'll make a transition over here we'll hit plus add a trigger name it open and then add that as the condition all right so now i've got some animations that'll play when we call trigger dot or animator dot set trigger open and make those doors open up and then the other thing i wanted to do was make the characters walk over to those points so i need to put in these castles like some sort of a walk point so let's do that as well i'll right click on my left castle let's add an empty game object or let's add a 3d object that's a maybe a sphere let's do a cube here we go i wanna oh that's way huge so i'm gonna scale this thing way way down let's drag that out so that it's not a child reset the scale to one one one and then drag it in so it is a child problem with having a weirdly scaled parent there i probably should have made an empty parent and then put the collider underneath it but whatever i've got my cube here this is going to be my walk point or like my destination i'm just going to shove this kind of back here into the castle so they can walk back into there and i could even leave the renderer on i don't think my player is going to see it i'll duplicate that well first let's name this uh destination let's say left castle walk point that looks good then i'll duplicate it make a right castle walk point so i'll rename this from left to right get rid of the one here i'm going to reset the position here such as 0 0 0 it and then the rotation as well i don't know why that's offset and then let's put this into position so let's drag it down hit f and get it kind of where we want now the the scale of this thing is still all wonky and weird but i'm not really too worried about it i just need to have a point here that i can use to send the players to i can even turn off the mesh renders if i want to and just use that so i don't need to worry too much about the scale or anything i just need to have those points so now that i've got that let's see what do i need to do i guess we'll go hook up our code let's go back to our game manager we'll go open up the game manager script and if we've got a correct answer we call castle.open which needs to set our animator to open and then we also need to tell all of our knights to go to that castle so first let's make it set the animator to our open state so to say get component animator dot set trigger and we'll set the open trigger we can get rid of this comment to disable the door because we don't need to do that anymore probably get rid of that reference completely in fact the other thing we want to do is go to our night manager or night game manager and here tell all of our knights to go to that castle so say for each bar night in nights just look through all of our nights if the night's active it'll move so we'll say knight that get component nav mesh agent and we'll set the destination of that nav mesh agent to the castles um what did we call that point i already named it and forgot it's the castle walk point so we'll go back into the script we'll set it to the castle.castle oh it's called that walk point now we need a walk point so we'll generate a field for it we'll make a get only property that's a vector three and this could just return back the position of that transform so let's say walk point dot position we don't really need the transform we just need the position so let's generate a serialized field for the walk point should be a transform we'll get rid of that door reference because we don't need it anymore save that off let's just look at that full script one more time so you can see the whole thing we'll get rid of line 25 as well we don't need that one more build jump back into unity and let's go hook those up so it's on our castles we need to add in the walk points the left castle gets the left castle walk point there we go and right castle gets the right castle walk point um we don't need to set up an avatar i think we're good to go am i missing anything i don't know we'll hit play and we'll see if anybody can think of anything that i missed let me hello commander we're happy that you came to help us we need you to send the knights to the right castle all right so we've got the four that's not it that's the number three wow that's amazing you found the number four all right they went in and they walked in now one issue of course is just that the animation is looping so we've got to go fix that i think there was a question about why we couldn't just use one animation we could if i wanted to line things up right and set up the parents and child children right i just didn't feel like going through the process right now they're offset the children are offset a little bit from the objects and all that and i don't want to go moving things around felt like it's just going to be a little bit extra work so that's all um let's go find the animation so we've got these two animations and i want to uncheck loop time on both of them we're going to uncheck loop time save and now the castle door should open up and the guys should just walk right in let's try one more time by the way if you haven't hit the like button we need you to send the knights to the right castle all right so here we got three guys that's not it that's the number two that's right great job that's the number three all right so they went into number three and then we need to do like a reset like that needs to close and then the doors just need to completely reset so let's do that next we'll go into our game manager let's see script game manager and then after we get the correct answer let's just hang out for a little while in a co routine and then do a reset so let's say reset game after delay and we'll make that a co routine so let's say start co routine reset game after delay alt enter and generate a method in fact we pro oh we want to make this be a i enumerated on that string in fact we might want to did i spell that wrong i ie or i definitely spelled it wrong so we might even want to make handling the correct answer be kind of run in a co routine because we might want to run a bit of more complex code we might want to not just set the destination we want to like play some animation do a little transition and all that so i think that we'll do that let's let's let's change this so let's go handle correct answer instead of being void is going to return an i enumerator i'm going to find the reference to it here which is in handle incorrect answer or handle correct answer no but here's what we'll do we'll make this void and we're going to take all of this code here alt enter and extract it so everything down to 64. extract it and we'll call this handle correct answer answ a-n-s-w-e-r-a-sync there we go and then this is going to return an i-enumerator there we go not get my spelling right but i got it in there okay so what do we want to do that for well i want to make this just be a co routine so i'll start the co routine kind of kicking it off and then i'll get rid of that second call to start a protein and we'll just kind of manage that inside of here in fact i could probably get rid of that and just do it all in the handle correct answer i need to add a using statement for it using system.collections up there at the top that got added with alt enter and enter and now we'll make it go through and actually handle this stuff so we'll play the correct answer we'll open the castle door then let's wait the yield return new wait for seconds and we'll just wait for one second so we'll give him a whole second to play now when he plays a correct answer let's also make him play an animation so i'm going to go down here into play correct i'll say get component you know get the animator and we'll do a what do we need to do set trigger and set the talk trigger i believe that's what we called it let's go back and look at it real quick remember on our character on our narrator character the blue knight here so select him go to the animator he's got this talk trigger that just takes him into the talking state so i just want to be able to fire that off when he starts talking or when he's giving the correct answer so hey we're playing correct talk in fact we should probably just play this when we play an incorrect one too let's paste that there okay so we play correct we'll open the castle we'll wait for a second walk the guys in and then let's move this debug log way up to the top then we'll wait again let's copy the yield wait and let's wait for like five seconds after that we'll just go through and pick a new answer reset our guys and um yeah i think that's it right let's say reset game after that so to reset the game let's generate a method and let's figure out what goes into resetting a game it's essentially the stuff that we used to set it up initially so if we go up here into our on enable we need to pick a random number of knights i think we could probably crank this up between more than two and five let's go all the way up to nine now we can set them to active and then we set our castle numbers so let's um let's make this number here something that's a little bit more variable i'm going to go up and add a serialized field serialize field we'll say int max number equals nine and then let's just copy that in here paste and paste and paste and we've probably added in a min number two i'll just copy that paste it make this min get rid of the private keywords and copy that min in there as well replacing the twos all right now i'm going to take the code here that generates the knights or sets the knights and sets the castle numbers and on enable cut it drop it right down here into reset game and then let's just call reset game in on enable so when we enable we'll do a reset and then afterwards we'll do another reset where we'll go through we'll set the knights we'll set the castle numbers now when we set the knights we also need to set them back to their initial position so let's say knights i reset position and we'll just add a method on there so they can kind of reset themselves so hit alt enter generate a method and say transform.position equals original position and regenerate a field for the original position now we just need to cache that original position maybe in a wake and now we've got a way to just bounce them right back so they'll reset they'll set themselves to active or not and then we'll set the castle numbers let's go try that out and hit play i think we're almost done functionality wise and then i can go eat because i'm getting hungry oh yeah not enough nights or too many nights it's a good idea too anyway i also just wanted to say again thanks um for everybody hopping in here and just um joining us i i'm trying to keep up on chat and stuff but it's pretty impossible to do that and talk coherently while we work through code without getting lost so thanks again everybody for coming out here um if you don't mind dropping comments afterwards or just hitting like button subscribing sharing and all that stuff it really does help um any time now come on hit play play button a while ago sitting here waiting all right well i don't know what's going on sitting there let's do a building writer forces unity to start acting right nope well that's an interesting one this is the longest time i've seen it sit here figures that they would do something like this on a stream huh there's a min amount to two and not nine like oh yeah good point i think i left the min and max at nine because i did a copy paste thank you very much for calling that out let's go right back up here that was in uh game manager yep mid number needs to be true let's do a build again all right come on unity switch back over i might have to kill the editor and just restart it in fact i think that's what we're going to end up doing looks like the editor has completely crashed i don't think i have any changes here that aren't saved so and we'll just kill it and we'll restart it so let's go find unity which of the millions of unity instances it is die unity editor did it die yep there we go okay so let's try that again we'll reopen our unity hub pop this project open knights invade the castle and we'll give it another go all right let's see should be good let's hit play and see where where it is i think everything's gonna work hello commander i'm happy that you came to help us we need you to send the knights to the right castle or three oh wow one two three four five six seven eight night that's not it that's the number three that's the number it you got it good job okay so that's not bad but uh that is not gonna work i just walked right in okay let's see what happens next i think it's gonna switch again is it no that's not it that's the number five fight great job that's the number three ah okay so their destination that was interesting let's see i've got a couple things messed up here so first is an error saying that the destination couldn't be set that's where oh cause this guy probably the night was not enabled so we just need to make sure that the night is active so say if night dot is active self is active and enabled there we go that'll work then we'll actually set the nav messages destination because we don't want to move ones that aren't there that's just spamming out an error the other issue but i mean that error shouldn't stop it so the other issue is let's see we reset game we pick a new set of numbers we set a new set of castle numbers we don't reset the castle so we need to reset both of the castles let's do that and then um what's the other issue that's going on we are setting a number i guess when we set the number we could probably just do a reset right there too so we'll just um let's say close the thing right here so i'm actually just going to copy this when we set the number we'll just call close and i'm just going to make that do like a reset and go straight back into the other animation or the other animator or the other animation state let me get my words clear a little bit so go to the animator i'll go to the animation we'll go to those castle doors uh not the animation the uh left castle right here the animator i'm gonna go any state into idle and we'll just make this be a trigger called close i'm just gonna switch back out of that open door i'm gonna do the same thing for the right castle this is getting pretty ugly not not a beautiful animation transition at all not a good animator setup but it'll work for now just got to be simple enough oh i need to actually select the condition go to close i need to make sure i did that on the other one because i don't think that i did yep i left the condition unselected should make it a little bit weird it would just jump right into that okay so i'm going to hit play one more time and then we're just going to walk through the uh functionality and make sure that oh commander we're happy that you came to help us we need you to send the knights to the right castle okay so we've got three nights that's not it that's the number six that's right great job that's the number three they walk in and then why are they going again what is going on here where did i miss the first let's see if there's any errors okay no errors all right so what we're going to do is just debug because they are just missing something obvious and simple and i'm not sure what it is um when we reset the oh yeah i know we're just when we reset the nights um hold on maybe i don't know what it is so we go to the game manager in here we're setting the cast numbers and we're setting up the knights we set the knights and we should be where where's my code reset game is going to reset their position and set them to active or not based on whether they should be active is not going to set their destination we set their destination let's go in the night um in reset position we should probably set their destination right because right now in on enable we go to the leader.position and then we have another bit of code that sets the destination back to something else so in reset position actually yeah we just want to call this line of code there we go that's it so in on enable we just want to call or in reset position when we reset the character we want to reset them to walking out to the correct spot that makes sense that fixed it it seemed like a much more complicated issue than um oh come on though we need you to send the knights to the right castle all right so we got three guys they go in what now i've got an exception what did i break okay so something broke here let's go take a look at it double click on it and it's saying that the clip for incorrect numbers is wrong from the incorrect number oh that's what let me see if i click it let's let's put a breakpoint here i'm a little bit confused did i break my incorrect numbers what did i do here so incorrect number is zero why does it think it's zero and then the so there are entries here but why does it think that i'm clicking on castle number zero why does it think that castle is bound to zero must be an exception somewhere else breaking it ah okay i bet um reset position is called either let's see either the nav mesh agent isn't cached yet so that's happening in awake where is this called from it's called from reset game and reset game hold on where's reset game called from let's find it called from on it okay here's the problem let's talk this through real quick because this is an issue that might hit multiple people in other scenarios and this is literally just a script execution order issue and it's something that can be weird and kind of catch people off guard so i got my console window i don't have two console windows my console window down here i just want to talk through what the problem is so right here we're getting a null reference exception that reset positions nav mesh agent is no let's say that something is null here and i know that the problem is that it's the nav message and the leader is serialized it's just in there i know that that didn't break so the nav mesh agent isn't set and if we go up here we can see the nav mesh agent is cached in a wake of the knight if we go down here at the reset position method we can see where this is called from we got one usage it's called either from what is it game manager reset game right there so we look here we've got reset position called from reset game reset game is called right here in the handle correct answer but it's also called one other spot it's called right here in on enable now on enable is called after awake but the way that it works and the way that it works in unity is that awake and unenabled are called for an object and then they're called for another one and then they're called for another one and then another one goes through all the awake and non-enables for an object it does it for one object and then the next it's not like all awakes get called and then all on enables it's all awakes and on enables for the object then starts get called so the easy solution to fix this is to just change this to be from on enable to be in start where we do a reset of the game now the reason that that helps us because if our game manager runs its awake first it won't have a null reference exception in the night because the knight will have already cached itself but if the game manager runs first which is what we were just having happening the knight hasn't cached its uh it's nav mesh agent so we get that no reference exception switching it to start means that the knight and the game manager both cache their important things in in the awake like their references and then start is available once all of that stuff is done and all the references are set up so moving that to reset or that reset game into start and let's just turn that to an expression body as well doing one more build that should solve the issue let's hit play and try it let's see hello commander we're happy that you came to help us we need you to send the knights to the right castle we got three we go choose two and oh we got another error let's choose the right answer let's see what the error was now must be outside the range of collection did i miss something else let's see narrator is calling the incorrect what did i missed here i've definitely missed something so i'm going to stop playing i'm going to uncheck maximize on play and we're going to do a little bit of debugging here so i oh i know i keep getting consoles come click on the window down there that's right so close that close that um let's hit play i'm going to clear the log we're just going to debug through and figure out what's going on here we're happy that you came to help us we need you to send the knights to the right castle navmesh agent set destination is still getting in no reference why is it getting a no one let's try it again right just double checking that mesh agent's good the leader's good seems good good good good good where's the error one ah here we go so this one not all of them orange knight four doesn't have its navmesh agent oh look and i bet i know what happened happen to help us we need you to say he have a nav mesh oh oh i bet it's because they're not enabled that's why okay i know the problem is so the issue here sorry i another weird fun issue since these objects were not enabled since my knights over here were disabled four through nine their awake method that does the caching also never got called up two different issues two two problems and we just fixed them both by just enabling those guys remember that the reset is gonna turn that you came to help us we need you to send the knights to the right castle there we go so we got one two three four five six nights that's not it that's the number eight hey that's it you found the number six great luck our beautiful knights walk right over and then okay we did hit an exception here i'm not sure what that is we'll take a look at it in a second you got two nights you got it that's the number two all right i think we need a little more instruction here for sure we get there's gonna be four nights that's not it that's the number three that's amazing you find the number four all right so i think we're getting closer now i want to add in more instruction here and some cheering and i also want to clean up that path a little bit let's look at this uh this navigation area if we go to the navigation window where's that at window remember ai and navigation kind of like walking over that edge there and i really don't want them to i guess part of the problem is that they're walking over the edge let's make this navigation static and not walkable and make it baked because the ground here is going down underneath and it's kind of making it so that they're walking underneath let me show you if it goes select this object here go to the inspector they're walking on this part that's why you're seeing them kind of sliding underneath but if i make this not walkable or on the navigation section now it's kind of tightened down that area and i just want to do the same for a couple of these spots let's make them not walkable so that we get a tighter area on the path that they're walking on go to not walkable there i think i want to do the same over here not walkable um maybe even this area not walkable and on that one okay let's go to bake again we should get a tighter a little nav mesh there oh that got too tight um let's make this one walkable again or let's um i don't want to do that i'll do that there we go i just drug it over a little bit and now we've got a path that they can walk on that'll work for me okay i think that that should look a little bit better uh i think that that looks good now i want to make it so that um they they play that little cheer animation or something though and we didn't grab one of those so i'm gonna jump back to mixamo and let's just find a cheer i still have the window open so it's nice and easy to go find like a cheering animation like that ah they're excited oh yeah let's uh download that fbx for unity without again looking good and then we'll drop that in we'll go set up that animation real quick for anybody that missed the animation setup part all we have to do is go to the animation folder we go find our cheering animation go to the inspector go to the rig choose the avatar and copy it from another avatar we'll copy it from our first night avatar yes and this is the night avatar that's in the models one not in the fixed folder and now we'll go back to the animation go select the cheering go back to the animation tab and we'll just hit the play button to view it in the preview i don't see anything showing up in there so let's drag a character and let's go collapse oh let's hit apply first collapse all this down and we'll drag in like an orange knight here into the preview i've lost my window let's see cheering there we go dragon orange knight in bam we'll hit play and that's what it should look like that's going to be the cheer all right let's go find the animator for our knight we'll open it up and then we'll add the cheering animation to it so drag that in and just drag in cheering and then we'll make that a transition probably from any state i think so we'll do a transition from any state to cheering we'll make a trigger here or let's make a bull make this called cheer and when it's true we'll go into the cheering state and then as soon as it's false we'll just switch out and into the idle state which can then allow us to go into walking so do a make a transition into idle here let's move this over you can see the line a little bit more and we'll do this as soon as cheering is false there we go so cheer is equal to false so that should give us the transition all the uncheck has exit time so as soon as we turn off tearing they stop cheering and start walking and then let's go back into the code and make them actually cheer so we'll open up writer one more time and then in our night code where's our knight right here when we get the correct answer right now what do we do we just um let's see well let's let's go through when we get the correct answer let's find our correct answer code handle correct answer we go handle correct answers async we loop through all the nights and we set their destination first let's just loop through them all and make them cheer so we'll wait uh maybe right when we start we'll actually loop through them let's do that and then we'll say if they're active and enabled now we should probably move some of this code into the night but i'm not going to for now if they're active and enabled then we'll get a animator component let's say get the animator and we'll set the bool um yeah we'll do set bool and we're going to set cheer to true so that'll turn on cheering for all of them and i could just turn this into a method let's say toggle cheer and then let's make this maybe be like true it takes in a boolean parameter i can click on it let's minimize this and make this take a boolean parameter so state say state right there and copy that down here now i have a toggle chair that loops through all of my nights and toggles them either to true or false cheering state save that off and then what we'll do is just call toggle chair at the beginning toggle it on and then we'll wait um before we'll wait maybe let's wait one second there then we'll toggle chair off let's wait two seconds or let's say 1.5 and then we'll wait another one second here so we'll cheer we'll turn it off and then oh let's go maybe half a second there we go something like that just trying to figure out kind of a reasonable flow and then we'll do the walk and all that and uh maybe after this i think i want to play like some text saying great job here's here's some more nights or something uh one other thing i wanted to do though i want to move this guy so one of the issues that i've got is i can just picture them counting and counting this guy in there as well because he is also a knight and it's going to be a little bit confusing that he kind of counts as a knight so i feel like maybe he should just disappear or something else or hide or i don't know um i don't i feel like it's going to be confusing like maybe i need my narrator to not be a knight maybe my narrator should be like a different character like so he looks like actually let's try that let's try switching that off and turn on like the oh that didn't work right let's try this guy this one have a material soldier zero one let's see let's go let's just go take a quick peek at him so he's got a material here where's his uh material section oh it's missing let's just find it uh it should be soldier or something right characters okay oh yeah that's kind of it um i want to make him [Music] maybe that one and let's take off his sword can i do that let's see uncheck his sword well uncheck his helmet this will i'm going to make this guy not a knight hopefully hopefully we can argue that he's not a knight if i can select i don't know if his helmet will actually uncheck though i don't know if that's an option here root we got the spine the upper legs the spine i don't know if there's a a parent up there head no okay i could turn off his head bone but that's not going to help okay oh good that that's enough for me i think i'll just use this guy as my narrator mesh and maybe maybe i'll move him maybe not i haven't really decided um let's hit play one more time i've forgotten where we were hello commander we're happy that you came to help us we need you to send the knights to the right castle one two three four five six hey that's it you found the number six great work all right numbers feel big that's the number it you got it good job okay so yeah i want to do a prompt here that's right when the new guys jump out so let's say like um what castle should these these orange guys go into something like that let's say what castle will fit these orange knights save oh we gotta pick a speaker let's pick uh gray again so i think i'll just make a couple little phrases here like which castle can hold this many orange knights we'll just download like um i think that's good we'll just do these two a witch castle one and then we'll do a witch castle two okay so we got two clips there so we can play between and then i think i want to just play that on the narrator so i'll just go to our narrator again and we'll say like this would be the choose castle lists or something so copy the serialized list of audio clips and say choose castle just be a list of options that we can pick from for that so we'll make it public void choose or play choose castle and then here we'll just play one of those clips so we'll say var clip equals and we'll pick one from here we'll just do random dot range of zero comma choose cancel that length which is just going to give us one of the two entries here hopefully that's all showing up on the screen there and then we'll just play it right here i should probably cache this audio source but i think i'm still going to just stay lazy with it for now so a play choose castle here in narrator and we'll just call that from the game manager so when we reset after the nights kind of walk out to their walk point um or this is not in the reset first reset right here so after the nights are reset and go to their walk point um i mean i kind of want to make this into a an ienumerator like a co routine like wait a little while and then play the choose castle message right so let's make this i enumerator instead of void we'll get rid of that private keyword here we'll do a little yield turn new wait for seconds and we'll wait for like uh i don't know let's wait for five seconds for the guys to come out and then we'll play the text that's on the narrator though so say narrator dot play choose castle and setting the castle numbers that um right now it resets everything and clears them out i almost feel like oh i guess we could do that right away there's no reason to wait on it let's make it so that reset game is called as a co routine though so i'll copy it find our two usages of it one is in start to do this i can just make this ienumerator a lot of people don't know that but a start method can actually run as a co-routine then we just do yield return reset game let's see if i can spell it right but yes you can just make a start method um essentially work as a co-routine there we go if you can spell yield there we go wait what am i what am i missing here okay let's switch this out of an expression body oh i got my words mixed up there yield return reset game there we go it's because i was in the uh expression body method there we go sorry all my typing is because i had essentially when i was in my expression body i had it like this return yield return and i was getting myself all kinds of mixed up so i can't generate this into um an expression body method that happened to mine i guess it wouldn't work there all right so i've got my reset game method here and now if i go down here it's actually going to kick off as a co-routine let's find the other reference to it though so we had one in start and one didn't handle correct answer same thing here we're already in a co routine so we don't want to start a new one we just do a yield return yield return that co routine we'll just wait until that co routine is done all right i think i don't know i think i might be almost done with this game almost wrapped up let's go add in our sound effects here we've got our choose castle sound effects we'll go to the project view go to the audio folder and we'll take which castle one in which castle two just drop them in number one and oh can i get my mouse there number two drop it right on save that off hit play by the way there was a note um in chat about my random selection being inclusive for mid number and max number um we should probably fix that so let's just go to game manager because we technically we can't get up to the number 10 or we can't get up to the number nine because it's exclusively counting out is so it's basically cutting out the number nine in our random check let's do that if we go down here to the random nut range um we have a couple ways that we could change it we could probably just do max number plus one probably the best way to do it um in fact that let's just do it that way let's do the max number plus one make it inclusive here um are we doing a random range somewhere else i think so let's search for where we're doing another random range f let's see control shift f random dot range so we're looking through the max number here for knights as well just saying plus one um any others night number night number and then this is all other stuff it's not ours okay cool so we'll do the build and i think we're good let's hit play and try it out i think we've got a game hello commander we're happy that you came to help us we need you to send the knights to the right castle castle will fit these orange knights ooh the text is a little bit too soon so let's stop playing and fix that one of the game managers it's just a timing issue so in the let's see in the part where we're playing it which was in our i've lost track already um oh it's right here it's right here i'm literally looking straight at this spot i just need to increase that to maybe seven seconds let's try that give them a little bit more time i don't want to rush them through it and start spamming questions and make make them not be able to look around and think so hello commander we're happy that you came to help us we need you to send the knights to the right castle which castle can hold this mini orange knight outside of their collision stuff we can fix that too one two three four five six seven eight but one two three four five six seven eight nine there we go that's the number nine you got it good job nights walk in get new numbers what castle will fit these orange knights there we go great work you got the number five looking better so i wanted to change something on these knights so that they avoid a little bit better let's go to the navmesh agent and let's just um actually i think i'll probably just pull in the radius what castle will fit these orange lights that's the normal in that radius so that they don't collide as much and they'll just kind of avoid each other and be good enough i think for now let's see get a couple more hopefully we got seven not two oh that's two which castle can hold this many are the number seven that's not it that's the number seven that's the number two okay last thing we need to fix so first we're going to turn down this radius real quick to 0.25 and then we're going to make it so that when you click on these you can't click on them again for a little while because otherwise they're just going to go bam bam bam bam and just keep clicking the screen and drive everybody nuts and ruin the game and not have a fun experience with it so let's kind of kid proof this real quick by making our own mouse down not be able to fire more than once like per three seconds or something so we'll say if time dot time is less than or equal to last click time plus three return and then we'll say last click time is equal to time dot time and we'll generate a field for it so that that's all we really need now we're limited to only clicking on it every three seconds so when we click on it time.time will be oh what sorry yeah it won't be less than because time.time will be greater than last click time will be zero so unless we click on it in the first three seconds we find then we'll set last quick time to our current time and then just check let's go see and make sure that i didn't mess up my logic there but assuming my logic makes sense which it does in my head but been at this for a little while um yeah we'll see so let's that's not it that's the number three there we go that's not it that's the number three that's it you found the number seven they're all amazing all right so if you're excited too make sure that you hit the thumbs up button i think i'm gonna wrap this up in just a second if anybody wants to see the code like just wants it shared i could definitely do that just drop comment below if there's i don't know like 10 people or so that want to see it i'll go through the effort of dropping the code up onto a gist and making it available um it looks like there might be one or two little bugs left still and there's definitely lots of room for improvement but hopefully you've kind of learned how to set up a basic game with some simple flow run through the whole process of hooking up some voiceovers animations and a whole bunch of other stuff if this was any kind of helpful make sure that you like subscribe and all that stuff share the video out somewhere share it with whoever you know everyone you know um i got courses and all kinds of other stuff linked down below you can check out as well and um i'll be doing lots more of these videos if this thing's popular people like it we'll do a lot more like this and we'll just kind of build on maybe different game types perhaps some that are like more um adult or teenager friendly not so much kid based but again this was just an idea that popped up it gave me the idea and i thought hey let's make the game real quick the next day it's kind of got a little bit delayed i'm going to build it out though put it onto a mobile device let them play it and see how it actually works out so thanks again for everybody for coming out here and watching i i really appreciate it and um thanks for hitting the like subscribe and sharing and all that stuff as well all right i'll see you all again soon um and goodbye you
Info
Channel: Jason Weimann
Views: 47,012
Rating: undefined out of 5
Keywords:
Id: 9aCQKqyRD94
Channel Id: undefined
Length: 153min 55sec (9235 seconds)
Published: Thu May 27 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.