Let's build a Video Game LIVE - Dungeon Defenders? (+ gamedev giveaway)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
getting started now i'm gonna hit the button and then we will uh get going with this thing all right uh welcome everybody to the stream um yeah let me just start this off with a real quick introduction of what we're gonna do today what's going on we're going to go through the process of building out a somewhat of a dungeon defenders type game from scratch we'll start with an empty project we're just going to pull in some art and we'll go through the process of writing that code to make the whole thing work um setting up enemies that walk along that we can kill setting up player input all of the types of things that you would expect to see in a game like this in like a dungeon defenders type of game it'll be our own little take on it um we'll see how it goes as we're building it along and take some feedback from chat and everything too see what everybody's got in mind or any cool ideas or recommendations people have so i think we're just about ready to get started before we do though make sure that you hit the subscribe button or at the very least just hit the like button it makes a huge difference and it really helps and then once we get going um actually you know what let me just switch over to desktop mode and start talking about what we're going to build show what we're going to use what we're going to build and then talk about um something else that's a little bit exciting and kind of cool that i want to share so let me switch over to our desktop mode real quick here so hit the uh button there just want to make sure that i've got everything set up right i think that's looking good all right so here's my empty project and let me show you first the um assets that we're going to use so you can have an idea of what this game is going to look like and how it's going to play and i haven't built it yet so i don't have like a pre-working demo to show you this should be a lot of fun though all right let's see the assets that i'm gonna use here oh no did i already close my page out for them give me one second i'm gonna i'm gonna load them right back up so it's the uh character bundle right here this low poly character bundle if you take a look at it it's got like a 19 or 14 different characters that are all low poly and i i'm going to grab a couple of them and use them in here i've already got a couple of them imported in and like i said earlier in the chat if you have a request or one of these characters that you want to see in this game as one of the enemies that walks by or maybe as the player i'm thinking that the player will be this little anubis dude here but um if somebody if there's a consensus on something else let me know but if you have a recommendation or just a request on one of these to be in here just type it in chat let me know if there's a bunch of something in there i will use that one as well as the ones that i'm already using also um i got an extra code for this so i wanted to use this pack and i bought it because i thought hey this is a neat one but then i got an actual free code for it too so i'm gonna probably give that away during this stream i think maybe once we hit like a thousand likes on the video um i'll just reveal it on the stream and whoever claims it first can get it first i'll let you guys know before i do that though so you don't have to like freak out or anything if i end up doing that i'll give you like a a warning of a minute or two so you know what's going on all right um looks like lots of talk about the eyeball and a bit about the skeleton coming in here all right cool so we'll i'll let that keep going and i'll pull them both in for now i guess and then we'll get into the um the asset pack that i'm using for the environment that's this dungeon pack here let me find this one in the asset store too real quick just want to show everybody what i'm using it's this oran let's oh did i spell it right i gotta spell the uh the name of it right this is actually a free one too so the uh the dungeon pack that i'm using is completely free if i can spell it right let's see there we go did i spell it right yep and it's here i'll pull it right over here this dungeon low poly pack so it's totally free and i think it's going to work well as just a map so what i'm thinking is i'll take a bunch of these blocks and line them up and make like a very simple environment at first where the players or the enemies can run across and maybe go you know attack the enemy flag or the enemy crystal or the player's crystal and kill it to you know have something that we need to stop and then we can set up traps it's got all these little traps and things here so we could put those down we could put down towers and we could also run around and just kill the bad guys all right let's um i guess get started with the video or the the process of doing this so i already imported in the dungeon pack and i think a couple of the characters i grabbed the mummy and the dragon and i'm gonna go to the package manager and grab that skeleton too and the eyeball because there was a lot of talk about both of us so just go into the package manager i've got the skeleton here i already grabbed it from the asset store and hit download right before we started this so i'm just going to import it and pull it in and then um oh i don't have the eyeball one already downloaded so i'll grab the medusa and then i'll grab the eyeball later so let's import in the medusa as well i don't know which one of these i'm going to start with maybe i'll start with the skeleton since it had the most uh the most requests so far so i've got a couple different art assets imported in xero code we've got nothing here at all i'm going to write the code as we go and then i put a link in the description where i'll just paste the code into a github gist so you can just follow along and copy it out of there if you want or you can just kind of watch and copy my code as i write it all right so let's close this out and let's go take a look at the dungeon pack first i'm going to go into the scenes folder and just look at their demo scene for one second and we just want to see what it looks like in here go select something and zoom around and all right there we go so it's a little map it looks like a bunch of different blocks like each piece is a separate block each floor piece is a block which might not be the most performant thing for us but i don't think it's going to matter at all in this game um and then it's got a different a separate level up here and then a bunch of different props and i think if i collapse this thing down there's actually a whole section for floors and then other things so i could even separate out the floor completely i think like i said i just want to build out something simple at first and then uh kind of go from there like let's make a really simple npc that just walks across the ground goes and hits a target and then we'll set up our ways or make it so we can build a more complicated map later we don't need a super complex map let's drag this out a little bit too because i realize my window is not taking up all of my screen thanks for calling that out too to get that sized up again all right in there completely too too many windows and too much stuff going on here all right i think that's closer perfect okay so let's uh make a new level here let's make a new scene where i can set up these blocks and set up an enemy that's going to be the first step so we'll go file and new scene i won't save my changes there and i'm just going to go into the prefabs here and let's see what it had for blocks got four pieces so this is floor d one or zero one d and zero two d if i zoom in here with a control on the mouse wheel get a little bit of a preview there of the two it looks like they're just the two different colors so i'll drop one out here into the scene view and reset the position and hit f to go to it i got one here at zero zero zero and i think that these are two meters wide by two meters i think they're two by two by two cubes and not one by ones let me double check that though by dropping out this other cube right next to it i'll reset that position again and then i'm gonna turn on grid snapping mode right here if you're not in a global mode you can't do it you got to switch to global and then you can turn on grid snapping and it'll just snap over by you yeah like if you look at snaps one here isn't enough it's like halfway through the thing but two is enough so go to negative two and it's side by side that's looking better and now i've got that kind of checkered mark or i have the two different colors so i can set up that checker mark so i'm just going to select both of these oh i don't want the directional light i just like the two floor pieces there we go and ctrl d and duplicate them and i'll just drag them over here and let's uh do that i think i want to go like maybe 10 wide so i'll duplicate it duplicate it duplicate it and get it to ah let's go like 12 wide let's duplicate one more over here okay so now i've got a straight little path and then i'm just gonna double the size of it so i'll select a model duplicate and move those dupes over here and then offset them by one spot and take this one here on the end and just move it over so now i've got kind of a a bigger fat road let's go to the game view though because the game view is going to be way off and now i want to set up um let's set up a player or actually let's set up a flag and an enemy first let's set up a target for the enemy to run to and an enemy have it start running across and killing our thing before we even give ourselves a player let's find an item that we can use for a flag i think there's actually a flag included in this kit if i look in the different teams yep there we go red one's got a flag so i'll just take this red banner and drop it right out into the scene the position is going to be all messed up so i'll reset it right here and then raise it up out of the ground going down here it's remembers right mouse and wasd if you hold down right mouse you can turn and wasd to move around if you're not if you're new to unity or anything all right so on the x rotation here i'm just going to put in a 90 to flip it up to the correct orientation because it looks like it was offset by negative 90 there and then move it over to somewhere that i think makes sense oh that's not the right spot let's go to kind of like the middle there and there we go that actually looks almost perfect now if i go to my game view though it's still going to be weird because i'm like off to the side i'm going to move my camera up so that my game view kind of matches what i really want to do is get my camera into position so that my game view looks right and i'm thinking that uh well actually if i want to leave the orientation of my camera alone i think do i want to do that i think i am i'm going to leave the orientation of the camera alone and i'm just gonna rotate the world around this a little bit the reason for that is just um really just to keep everything straight so that if i'm going backward and forward on my z-axis i don't have to translate it if i'm not doing any rotation i don't even know if i'm going to need it but i'm just going to turn all the stuff around instead of moving the camera around so to do that i'm going to create an empty game object here i'll reset the position name it environment or actually i'm name it floor and then i'm going to take all of the floor pieces select them make them children of it and then i'll just move this thing over here and rotate it oh whoops wrong rotation let's switch to um there we go center rotation there we go it's this little tool right here to do the rotate there and i i can just put in a 90. oops nope i can't do it that way i have to actually drag it okay let's see can i get it to the right angle i want okay let's undo that let's try again so i'll hold ctrl and now i'll drag it there we go there we go the problem was that i started dragging it without control i got a little bit of an offset in there and i really wanted to get this at negative 90 for all of these so that the whole thing was rotated now if i look at my camera view i can see that my camera's aimed right at it which is closer to what i want to have i just now want to move this camera up a little bit and then maybe tilt it downwards so grab it move it up and tilt it down or even come over here get it kind of lined up to where i want it to be and with the camera selected i and just hit um control shift and f that'll move the object to my position and rotation right here it just sets the transform of whatever object i have to match my scene views transformer in fact let me line that up a little bit better and then move that banner here hit w and get it kind of over here as an end point that actually on the ground or is it floating up above looks like it's in the ground all right so there we go i've got a little piece of ground here and i can set up an enemy here and make him walk over there i think that that's the um the first part right that'll just be the the thing that we need to yeah i guess have as an enemy or something that we need to kill a target or a bad guy to kill let's save this law off as a scene i'll go into my scenes folder and let's call this um dungeon one and then we'll create an enemy so we've got a level um let's make a bad guy and make the bad guy start walking we'll go into the infinity pbr folder and let's expand it out real quick so we've got the medusa the mummy the skeleton and the dragon um i think we're gonna go with the skeleton first since that was the most requested one but let's take a look at how this works real quick because there's actually some really cool stuff on the skeleton so we can really customize it and make it look kind of cool let's go into the prefabs folder here and just double click on the prefab and open it up but what did it open up my prefab what did i do there oh i'm in the game view sorry i had my game view set up and i completely mixed myself up so here we got the um the actually you know i'm gonna get out of that i'm gonna go out of prefab mode i'm just gonna drop this guy out into the scene drop him right out here and go to him and then let's go select him if we go in here um oh that's right this is uh not the one i'm thinking of is it give me one second i'm just trying to think this through what did i have in here i did i didn't play with this guy let me put let me pull out the uh mummy real quick mummy is the one that i did play with and remember where the um oh that's right it was in here sorry okay so we'll open up the demo scene let me save my dungeon real quick and open up the demo scene for the skeleton real quick and hit play this is what i wanted to show but oh there's an error in here i'm guessing the errors with um some asset pack that isn't in here let's just clear that out wardrobe manager.cs file at i'm just going to delete that because i don't know what it is or why it's causing a compile error i assume it's going to mess with clothing or something on one of these these guys all right so go to the game view and here we can actually see the character well it's not rope why isn't it rotating there we go can we rotate it am i hitting a com an error what's going on all right my ui is total oh i'm not ah it's not playing sorry everybody acting crazy apparently my thing is not playing because something else is referencing this wardrobe manager i should have probably not just deleted it and i should have um i i should have just let it work i should have fixed the issue here let's see let's go back and fix it real quick so it's saying that the skeleton demo is erroring out because i deleted my wardrobe manager i'm going to go re-import this package real quick so go back to the package manager go back to that skeleton and import it sometimes this happens when i pull stuff in and break things and i'm not paying enough attention what happens when you don't pay attention like like i wasn't doing right there in fact i probably should have made sure that let me double check that everything is getting imported there yeah it looks like everything's there all right so let's hit play again see if i have an error if i don't have an error look at that i don't know what i did somehow i totally messed it up for no reason so i'm going to close this because i don't have the environment i don't care about the environment so much though i just want to see this guy in action so i'm going to hit maximize on play pause it and unpause it again so you guys can see it full size and i'll hit maybe later on the review and then let's go through some of the options here so this is the reason that i wanted to use this pack not just because it's got a bunch of animations and stuff set up that i can use which i think will be kind of cool like i can make this do just attack or get hit or whatever or like collapse and die it looks like he's got some reassembled stuff but this stuff over here let's um here reset yourself go back to walking and then let's go through these texture sets so i can swap out the different sword and armor here you can see you've got a bunch of different variations here i can swap out the different skeleton textures here but i can also just go down here and hit this randomize button and this is the part i like and just hit this and just get totally different variations of it constantly i don't have to go in there and try to make a bunch of them because i'm a terrible artist and uh yeah i would never make anything that looks really cool or cool variations on stuff if i can just hit a button to do it i think that works a lot better so you can see it kind of modifies the different parts of the shape and then um also swaps out the different armor pieces here and it works like that for all of these different characters which is why i wanted to use them in the first place all right so let's take this little skeleton dude drop him into the scene and make him actually play and do something just looking at art is fun but it's not fun for very long all right so we got a warrior here and i want to make this dude just uh walk across and go attack the the flag over here so i'm going to move this dude get him right over to the edge and um i'm gonna go to the game view just to make sure he looks about the right size i think that seems okay i'm gonna crank up the directional light too because i feel like this is a little bit dark with this at maybe like a 1.5 so i can see it pretty well all right so to make this dude walk across i'm just going to use some simple navigation we'll just set up a nav mesh and make him use the nav mesh system so i'm going to create an empty game object to hold the model for this enemy so the art sub piece of it is kind of a child of it that way if i want to swap things out later it's really easy to do and i don't have a bunch of things kind of built on top of this prefab so just create an empty one i'll write or drag it out of here rename it to empty or no enemy not empty in fact let's let's name it skeleton s-k-e-l-e-t-o-n there we go and then i'll take the skeleton and drop under the only reason i made it a child is just to get the position right so that this thing would be at the same position as that one i could have also just copied its original position now i've got my skeleton here i'm going to go back to scene view hit f let's add a nav mesh agent so it's going to nav mesh agent and that pretty much just automatically sets up right i don't really have to do much here except maybe fix this position because the y position was just a little bit below the ground and i think it looked a little bit strange now i don't like the y position right here is at one so i'm going to move my floor down because these things are two meters high and i put them at zero there it looks like they're they're offset they're going up to one and normally they would be up at like point five if i just move it down by um down to negative one i guess type in the negative one i should be able to put this guy down to zero and then have him zeroed out on his position there's no real technical reason for that i just felt like it it it seems better to me all right now i'm gonna make the ground navigateable so we can make this dude actually move along it so we'll just select the static box over here and let me just drag this over to the side if i click on here you'll see there's a navigation static option i just need to check that and hit yes to change children that'll make it so that all of these little floor tiles here have the navigation static option checked and that'll make it so that they actually get included in the navigation mesh system so to generate our nav mesh we'll go to window and then go to i think it's under what ai now and then navigation and then go to the bake section here these are actually little tabs here object also lets you check whether or not something's navigation static and see it's on for that floor piece i'll go to the bake tab hit bake and i get this little blue outline here this weird little blue outline i don't know why it's uh chopping up so much and acting weird but that outline is the navigation mesh for my characters it seems like that something weird going on with this uh collider oh these things don't have colliders so i'm gonna select all of these floor components and we're gonna add box colliders to them that's an issue there so i'm going to put box colliders on them and then i'm going to go regenerate my nav mesh let's rebake that okay wait what happened there so when i baked my nav mesh it should have baked on the colliders and not the uh the renders i'm not sure what happened there if it did or not but it certainly looks a little bit weird actually let me just move the floor down and i'll see what the nav mesh looks like okay it looks fine it's just clipping through here and looking a little bit strange so i'll move it back up but you can see here let me move this down a little bit but what you'll see here is this blue line is essentially where this nav mesh agent is going to work i think is walkable anywhere on this blue plane even if i move the ground after i bake this stuff it's still going to move there in fact let's leave it down here for a second we'll make him run around and move on it and then i'll fix the ground so it's actually in the right position as you can see how that works so i'm going to go to the skeleton now and i think it's time to um write some code we got to make some code that's going to make him run over and attack our little banner here that's at the end of our nav mesh remember if it goes navigation system it's it's there kind of at the end of it so let's uh let's do this by creating a scripts folder we'll go to the assets folder or right click and create a new folder called scripts i've got a spell right scripts i'll go into here and i'm just going to make an enemy script so here create c-sharp script name enemy with a capital e at the beginning and then we'll open it up in visual studio now while that opens up in visual studio um if you don't mind hitting the like button and the share button i'd appreciate it i guess and then we'll uh get to writing code so the enemy what does it need to do it needs to tell its nav mesh agent to walk to um our flag that's the only thing i really wanted to do at the start so i'm going to get rid of all of this let's add an on enable and we'll say git component let's zoom this in too because no reason for it to be small we only really need to do one thing we'll get the nav mesh agent i need to hit alt enter and add the using statement to add that using unityengine.ai in fact i can get rid of these other two using statements up here so get the nav mesh agent and we'll do a dot set destination so we can do this on the next line or that same line and we'll set the destination to the position of our enemy flag or our flag so i'll say flag position now i don't have a flag position so i'm just gonna generate that one line above so say vector three flag position equals and i do let's do a gameobject.find one really really ugly call and everybody can hate it but i'm gonna do one by name and it'll be totally fine because we're gonna change it later say gameobject.find and we'll just put in the name target with a capital t all right so we're going to look for a target and we're going to use its transform dot position not not ps transform.position so say transform.position and we'll move that semicolon up here and look at this so now we're going to get the position of our target and set that as our destination super super simple so now i just can go in here assign this to my skeleton and watch it not work watch attach it to the guy i hit play and i should see a nice little error message saying that it's null or an object reference has not been set it's just because we didn't set up a target so go back into unity and stop playing and just rename our banner to target save and hit play now i expect that well let's see there's no nav mesh agent attached to the warrior object okay let's check that out so let's go to the warrior skeleton ah yep i wait oh no i put the what did i put the nav mesh on or the script on i put the script on the child here instead of on the parent that had the nav mesh agent so i'm just going to take it select this one click and drag it right up to the parent and that should fix it second select child looks good the parent now has the script i play one more time and look at that he just runs right over to it even though like i said the ground has been moved because the nav mesh was baked when it was up there it still counts and it still uses that as the nav mesh let's move the ground up oops not that one i want to move the whole floor up take the whole floor put it back into position so that it doesn't look weird anymore was it at negative one i guess that's about right or let's just type in a negative one exactly and go back to the nav window there we go so now i've got an enemy that walks right over to the uh i guess the enemy flag um i want to make him animate real quick and then we'll make it so he attacks and make him do a little walk animation which should be really simple and then make him start attacking the flag and then we'll start putting in ways to kill the guy and defend ourselves and we gotta have some kind of defense i guess all right so our skeleton here probably has an animator on him let's see yep he's got an animator with no controller but he does have an avatar set up let's just go make a controller for him so i'm going to go to the assets folder right click hit create and make an animation folder and then we'll make a really simple animation controller for our enemy that just handles walking right now so just do walk and then we'll expand it later go right click create an animation controller name it enemy and then assign it to the skeleton so take it and just draw up not here assign it right down here to the skeleton and drop it in i might want to have different animation controllers for different enemy types but right now i've only got one so no real reason to uh to complicate it so let's double click on the controller open up the animator controller and set up an animation for it so i want to take this animator and just drag it up here out of the way so that i can find an animation and drop it onto here this is going to be one of those skeleton animations and i'm looking for the walk animation so let's make this a list view oops go to the correct folder go to that skeleton warrior folder go to the model folder and if i expand out the model i should see the animations underneath it is my guess yep there we go there's a walk i'd walk backward a taunt an idol a bunch of other things i'm just going to take walk and drop it out there because right now it just needs to walk forward doesn't need to ever stop or do anything else so that should be enough right now if i go to my character here let's go to the scene view he's got the controller on it the controller's got the walk on it if i take my animator drop it down here i should be able to even just watch him animate and watch the animation play let's see there we go he's walking he's animating looking pretty good it's not perfect but it's not bad um i want to slow his speed down just a little bit because he walks a little fast i'm going to put him at maybe like a 2.5 instead of a 3.5 which is the default there because i think this the skeleton should go a little bit slower in fact i might slow them down a little bit more even let's take it out of maximize on play mode and then i'll turn this down to like a two and then hit play and then i can just adjust it at runtime i can just take the speed value and slow it down or speed it up a little bit so if i want to make them like a yeah i think that's close to where i want like a 1.3 maybe 1.4 i want i want the enemies to walk relatively slow there we go so i think i'll go with that like a 1.4 so stop playing put in a 1.4 and save it off so now we've got an enemy that walks over there in anime actually let's watch what happens when he gets all the way to the end while i uh crack open a rock star real quick so let him walk to the end and see what he does when he reaches the end because that's i think our next piece to hit see if i can if i can get this thing open all right yep and there you go see he just kind of like he stands there and he just keeps walking so that's about what i would expect he's reached this position but there's nothing in the code that says hey stop animating your walk so let's make him stop animating his walk and then start to do an attack attack this thing kill it and then we'll make a way to kill him all right so we'll stop playing and let's go well first let's just set up the animation real quick we'll make an idle animation in here so i'll take the animator drag it up there i still have his character model selected and expanded out so i'll just take the idle and drop it into here and then i'm also going to take the attack let's take just attack one and drop it in there as well i've got an idol and an attack animation let me take the attack and just kind of drag it up here and then i think it's alt and yep alt left click to drag and pan around here so just alt and left click on the back there to drag it around and i want to add in um two parameters i think i'll just add a bull for whether or not he should walk and a trigger for whether or not he should or when he should attack so add a bull and i'll just call this walk and then we'll add a trigger and i'll call this attack so the trigger for attack will happen from any state so just right click on any state go into the attack make the transition there so i right clicked and hit make transition clicked on attack to actually create the transition now i click on the arrow which is the transition between them i don't want has exit time checked and i do want a condition that makes sure that i've done the attack trigger so check that and now whenever i do an attack it'll go into play this attack now i want to go from the attack back into the idle animation so i'm going to move this actually let's just take the walk drag it down a bit and put the idle in the middle i'll make a transition from attack down to idle so after the attack plays it goes to idle then i'll make a transition from idle to walk and put in a condition so select the transition here add a condition and we'll just yep there we go walk true that was the default one i don't have to change anything i do want to uncheck has exit time because i don't want it to wait and blend those animations i'll make another transition back up from walk to idle same thing right click and hit create or make transition then click on idle then we'll go to it again add the condition and make the walk false and uncheck has exit time so now we've got a set of animations or a way that we can toggle through these animations i'm going to play through them real quick make sure that it works before we set up code it's always good to kind of like get these things working make sure that it works when you click the box before you write the code because if you mess something up in here and it's not working right you don't want to be trying to debug the code like thinking that it's a problem in the code when it's really just something in the animator all right so there he goes he's in his walk animation so far nothing seems right at all right so okay he's trying to play an idol and it's not working so click to walk and that works idle doesn't seem to work the attack okay it seems to work let me try this one more time let's hit play again and let's watch him right from the start so he might be doing something what i'm not sure on is whether or not he's playing the idol just once and not not looping it or if he's just never playing the idol so let's go take a look real quick we'll go to the project view go select the idol and just hit play yeah that idol right here let's see if i expand it out it's very easy to miss so it'd be very easy to not notice it if it is happening so i'm going to close that back out let it snap back down there and i'm just going to go make sure that this thing's actually set up to loop so go select the character up here or just click and hit left and go select the base one and i'm gonna go down to the idle animation oh loop time is on so he is set up to animate and loop it i don't know why he's not looping it then let's see let's double check that he's not looping it so go back to the animator got the idle animation right here let's just hit play oh you know what i think he actually is animating let me go to the scene view zoom in a little bit and play back the scene view yeah turn off the nav mesh agent there we go now we can actually see it problem is he's moving while he was animating so it looked like he wasn't animating and his his idol animation is super super super chill it's really hard to see it but you can see he's animating there and if i switch over to the walk mode he starts to play his walking animation not actually moving because i turned the nav mesh agent off and if i hit attack i'll go into an attack he'll go through idle and instantly go into walk so he doesn't actually stay in the idle he just kind of snaps right through that into the walk state so that looks like our animator is set up right and good to go i'm gonna actually write the code now so we've got our enemy script here and our enemy script just needs to deal with what animation to play so the first thing is i guess setting whether or not we should be walking based on what our nav mesh agent's speed is and then setting whether or not we should attack based on whether or not it's time for us to attack so let's make an update we'll at right here add in an update method scroll in or scroll down and zoom in a little bit get rid of the extra private keyword here and let's say well actually let's cache our animator first so i'm going to go up to the top here and i'll add an awake and we'll say underscore animator equals get component in children because the animator was a child component so i'll get the animator here and then we'll cache that or generate a field first so hit home alt enter and generate a field get rid of these private keywords just to shorten things up alt enter to turn this into an expression body method to shrink it down since it's only one line and then i'll copy this and let's delete that private keyword too there we go so i've got my animator now cached and awake so i can use it in update and update i'll just say animator dot set bull and i'll pass in walk the name of our boolean there and we'll set it to either true or false based on what our nav mesh agent's velocity is so um well we don't have our nav mesh agent cache so i'm going to cache the nav mesh agent i'll copy this little bit of code here and i'll turn my awake back into a block method and say hey underscore nav mesh agent equal space then our git component call now we're going to cache both of those that's how quickly sometimes you have to change things like you need it one way and then you change it back the other way it's easy to do though with the shortcuts once you get used to it and get really fast with just hitting alt enter and the shortcuts to go back and forth it can save you a ton of time just and keep your code clean while you're writing it so i've got the nav mesh agent now let's zoom out a little bit so everybody can see the full script there's really not much to it yet and once this file is done i will put it into the uh just it's uh on the in the link right below so we better go grab it in just a few minutes once this is done with the first version of it so we're going to set this to either true or false based on whether or not our nav mesh agent is moving so i'm just copying my nav message and here and i say navmeshagent.velocity.magnitude greater than zero that's really all i need let's zoom in a little bit now obviously this isn't the most performant thing that i could speed this up and cache it or just change it only when i needed to but it doesn't make any difference here what we're doing is just setting walk to true or false based on whether or not our character is moving not going to impact us at all the other thing that i want to do is set the attack whenever we want to do an attack so let's um first let's play this make sure that the walk thing works and let's do the attack because the attack is a little bit more complicated not very much we just have to have a timer and a check to see if we're in range and then we switch to an attack so let's watch the dude walk i'll take a drink and everybody can hit the like button while i do that all right he's almost there come on he got to the end and he switched to an idol perfect that's about what we expected right at least that's what i was expecting he would get to the end and be ready to attack but not quite attacking so we'll write some code now to make him attack all right in our update method i think we could just say if we're ready to attack we should perform an attack and then make him play an animation and do an attack so we'll write in a little bit of code here and update we'll say if ready to attack and make that a method we'll generate it in just a minute then attack pretty simple at least that's the flow there's a lot of uh what we have to do when you're writing code right just think through the the idea and the flow of how you want the thing to work type it out write out those methods and then fill them out like once you've got it kind of stubbed out start writing the code so here i don't know if i'm ready to attack i want to attack that's it i don't know exactly what those are going to look like but we'll figure it out so ready to attack should be i think pretty simple i just want to have it on a timer and know like if i'm close enough to my target and my timer's up i should be able to attack so first let's uh add in a check for our target let's cache our target here so we can see what our distance to our target is so here we've got our flag position let's just make this into a variable that we save off so i'm going to rename it to underscore flag position i'll get rid of the declaration there hit alt enter and generate a field for it now it'll just be saved off in fact let's uh shrink this down let's get these under one-liners now i think i was going to put more there but there's really not more to put so i don't need to so here we'll cache the flag position and we'll set our destination and then here in the attack we'll check to see if we're in range to attack so say or let's say float distance to target and let's scroll that up a little bit equals and we'll use vector3.distance this will get us the distance between two positions we use our transform.position so this is our current skeleton or enemies position and then our flag position that's it so this will just return us a distance in meters from between these two points and we'll just check to say hey if distance to target is greater than attack distance then um return false oh and i just realized i'm doing this in the wrong spot because this is part of my am i ready to attack check not part of my attacking code so i'm going to take this bit of code cut it with ctrl x so i select it all control x and ctrl v to paste it is also just command x or command v if you're on a mac so now i've got the code here for my ready to attack that will bail out or return false if i'm out of my attack dis attack distance doesn't exist yet though and this method's not complete so we have two errors so let's generate attack distance hit alt enter and generate a field for it it's the default option right there for me that'll create it and get rid of the error but it's not actually going to fix the problem i need to hit f12 and then go actually set up a distance i'm gonna make the attack distance equal to like two meters for now and i'm gonna make this a serialized field there we go serialize field instead of just a private field that i can modify it in the inspector also gonna get rid of this extra private keyword just because i don't need it then we'll go down here and check our ready to attack so if we're out of range we are not ready to attack the other thing we want to check is if it's um not time yet so if our time isn't met then we should not attack either so we'll say if time dot time is less than next attack time return false and then if neither one of those are the case then we'll just return true and of course we could rewrite and rearrange this in a bunch of different ways and re-restructure this but it needs to do essentially this we need to make sure that we're in time and that we're in distance so we need to generate a next attack time i'll hit alt enter and generate a variable for it which should give me a float if i hit f12 there we go i've got a float for it this is not going to be a serialized field i'm going to cut it and move it right up here so that it's aligned with my other non-serialized private fields and then we'll just set up this attack time so whenever we attack our next attack time will be the current time plus whatever our attack delay is so we're going to need an attack delay so let's copy line 12 paste it right here and replace distance with delay this will be the amount of time in between each attack i'm gonna leave it at two why not actually no let's turn it up to three just so the numbers don't exactly match and then let's go down to our part where we attack so actually let's take a look at the whole thing and then let's figure out the attack and then i'll upload the code real quick and take another drink while we watch it in action so right now we have our four fields that we're caching our two serialized fields that we're going to see in the inspector in a second we're caching the animator and the nav mesh agent in the enable we're caching the flag position and then we're getting our nav mesh agent just telling it to go to that position we don't tell it to ever switch targets right now maybe we'll do that later but right now we don't need to so we just say hey go to that destination in fact hey look at this nav mesh agent right here could actually replace this git component call let's see i'll zoom in real quick just so everybody can see that that nav mesh agent was already cached and awake no reason to get it again all right let's zoom back out the update just updates our animators walk state and checks to see if we're ready to attack and then performs an attack if we are get rid of these private keywords that we don't need and then let's make the attack work so for the attack what do we want to do well we want to set our next attack time equal to time.time plus our attack delay whoops not our nav message our attack delay this will make it so that we can only attack every three seconds or whatever our delay is and then we want to well let's first just play the animation we'll say animator dot set trigger attack oh gotta put it in quotes there we go and save that off so now you should just run up play his attack animation once he's in range i'm gonna hit play we're gonna watch it in action oh there we go we got our two new fields watch the bad guy do his thing take a drink real quick and then see what happens all right walking over all right and he's at the flag and he stops but he is not attacking why isn't he attacking well let's take a look so he's never going into the attack if i click the attack i can see him play it so he's never actually setting that attack trigger go to the console i don't see anything here let's turn up his attack distance i wonder if the distance is too high yep that's the problem so the issue there is that he thinks he's farther than three meters away i think that the reason for this if i just go over here and select one of these objects here let's go select the skeleton so here's the skeleton and his base point so the center of the skeleton is like his position that's where he's actually at um oh wait am i on the wrong thing no here's his actual position i was like i had select center selected i needed to be on pivot the pivot or the bottom the feet which is much better i was a little bit worried for a second is where his actual position is at so that's where he's supposed to be but if i select my flag or the target and hit w you can see here that the pivot for this thing is way up in the sky so the distance between these two things is way greater than three what i need to do is well first i need to pull this thing down so that it's in the right spot but i also need to set the base of it to be the actual position or the key object or the primary object so i'm gonna stop playing we're gonna right click on the target i'm going to hit create empty i'm going to make an object that's right down here at the base um in fact let's make a cube i'm going to delete that i'm going to right click and hit 3d object and create a cube and then i'm going to make that cube down here at the base so this object is going to be kind of the home object or the the position of it and i'm just using a cube so that i can see it very easily or so that everybody can see it i take this out drag it to be a sibling of the target and then make the target a child of it rename the cube to target and rename target to banner red because i think that's what it was it was a red banner now that the target is the actual base level object you see that it's down here and i can use this position so all i need to do now is well actually i don't think i need to do anything except for turn off the renderer and the collider there and then get this thing down into the correct position there we go now that it's in the right spot i should be able to save hit play and watch it work remember because i named the object target just looking for an object named target it should just go right over to it okay you know somebody was asking if you can change the pivot point of a game object um you can't do it just in unity well actually there might be some way to do it in unity without um parenting it though so you can just re-parent it underneath something that's usually what i do you can also just do it in your art tools if you're good with a blender or any other art tool it's something you can definitely do all right so here we go this guy is now walking up to the flag and attacking it i think he's getting a little bit close to it though um where's his stopping distance right now his stopping distance is set to zero i'm going to crank that to like a 1.5 and then grab him and just move him over here a little bit and see what happens if he there we go so now he's stopping at 1.5 meters out that's what this stopping distance is here on the nav mesh now he's actually stopping i think at a range that makes sense it should be greater or less than his attack distance but not right up on the object so i don't want him to stop right on top of it so i'm gonna stop playing i'm gonna put a stopping distance at 1.5 again while it's not playing and save it off and then i think um oh well we need to make it actually kill the flag real quick and then we'll make the enemy killable actually you know what let's uh let's put this up for a vote does everybody want to make the enemy kill the flag or make it so that we can kill the enemy first um go ahead and vote in chat real quick and i will pull out some milk duds while you do that and ask everybody to hit the like button that hasn't hit it already or if you have hit it um share the thing instead all right so yeah you guys want to see um the enemy kill the flag or you want to make a way for a player to come in and start killing an enemy good stuff all right i'm seeing lots of votes for killing the flag first so i guess that'll be the uh first step so let's do that let's go into our project oh those make me thirsty we go to our scripts folder actually let's upload the um i want to get that enemy script uploaded real quick so that everybody can use it so let's go up here i'm going to paste it into chat or not in the chat into the uh the gist file that's linked there let's see right edit this let's go back to edit mode edit add a file enemy cs and paste it and now you can go grab it in the link in the description all right so let's set up our script now for the flag so right click create and make a c sharp script and we'll say flag and don't worry if you want to see the enemy die that's coming next we're going to do the enemy make him go launching off with uh ragdoll physics and stuff maybe make them like launch off the edge or something and die but we'll do some cool stuff to kill them all but first we'll make it so that we have a reason to kill them i guess so we have some pressure all right so we've got a flag script i'm going to put that on my target here assign it and then um let's see how we want to set this up i guess the flag could just have some help it could take a hit every time we attack and whenever it takes some number of hits it dies seems simple enough let's zoom out here we'll add in a health amount so i had a serialized field for health or let's call this uh max health int max health and i'll assign it to like 10 so it can take 10 hits and i know i'm going to need a current health so i'll say end health and then we'll add an on enable on enable we'll just set our health to our max health and then let's see what else do we want to do we want to have a way to take damage or to take a hit so add a public void take it and i'll take a damage amount so into amount and then uh let's call it take damage take damage i'll have an int for an amount we'll say health minus equals the amount and then if health is less than equal to zero then we die and then dying right now i just generate this let's make dying just uh reload our current scene for now we'll say uh scene manager.low [Music] and we'll add a using statement for so when we die it's going to be annoying it's going to reload our scene um i think that's about it so we'll load yeah okay now all we need to do is set up our take damage so we'll go to the enemy and say hey whenever the enemy does an attack tell the flag to take damage that means that we should probably cache a flag instead of a position now so i'm going to change this flag position from a vector 3 to a flag not a floaag a flag where we remove the word position remove the word position we'll get uh let's do a find object of type and we'll make it of type flag so we'll change instead of getting the target we're going to find a flag and we'll cache that thing and then we'll just go to the flags position in fact i can just put a dot there look at that oh no i can't transform dot position totally lied to you there all right so now we've got oh we can get rid of that though now we have a flag that's cached instead of the position and when we do our attack we can just say hey right here let's do the animator set trigger and then do flag dot take damage and we'll just take a damage amount now let's give the our enemy a damage so we'll say damage let's call it attack damage there we go and then we'll generate a field for attack damage now our oops that is not what i wanted to do i hit f i hit alt enter two and enter too quick so hit f12 and i go in here you'll see that i accidentally generated a a method that took in an object of attack damage instead of generating a field for attack damage i'm gonna go back here alt enter and i want to hit generate fields yeah i did generate a method messed it up with the wrong one sometimes that happens to fix it there we go hit f12 go up here i've got my attack damage i'll copy serialize field and paste it over private and i'll just assign it as a value of one for now so my first and my default enemies will do one damage all right we'll go in here and uh see is there anything else i need to do let me think i think that that is probably oh no we have an error so let's check out the error so hit clear an error saying the flag position doesn't exist ah okay flag dot transform dot position there we go there's one spot where we were referencing the flag position variable that it renamed to the flag or changed and hadn't updated all right let's go back in here hit play one more time and come on you should come over there attack our flag and kill it in a couple hits i should be able to just turn up his damage in a second let's see uh how much damage he's doing though or see if he actually does damage to this thing kills it in fact i've got the target selected i'm gonna switch to debug mode here so we can watch the health value there we go it's at nine eight we're gonna go to seven there we go it looks like it's counting down all right looks like it's working i think it's almost done oh i know it's almost done because i can count but you get the idea right i'm gonna eat one more milk dad take a drink and uh i beg everybody to hit like and share the video one more time oh and it reloaded all right um i think it's time i think it's time to kill the uh the bad guys right time to make them go launching off the edges and stuff let's do that let's set up a player character all right so we're gonna go let's see i don't know which player character i want to go with i am going to let's see pull in a couple of them let's pull out a couple and see what everybody wants to use so i'm going to take out this uh let's see what does this medusa look like drop her out um maybe not the serpent version of her i'll take the human version of her that looks usable or i could go with um maybe the mummy or the other guy that i was considering was the anubis one um let me go pull that in too and i guess uh let me pull up the anubis and the mummy and the the medusa right here and we'll see what everybody wants to use we'll go with whichever one you guys want to see as our player character we'll make that at the character and then we'll uh start killing some zombies and stuff um oh there he is anubis right here okay we're killing some skeletons i guess they are all right so we've got a character set up let's see oh no we've got it imported we're never talking about it all right so where is he where's our anubis let's grab him into the models folder just take this anubis dude no not that one let's go into the prefabs folder we'll just take this anubis dude and drop them out all right so i'm gonna use one of these two i think as our character which one do you guys want to see go ahead and pick just uh vote really quick in chat which one you want to see if you want to see the anubis dude or the medusa be the player character and then we'll just set that one up we'll make him run around we'll make him knock the skeletons off and make those dudes go ragdolling and flying and everything else so if anybody's got a preference uh vote now or yeah or i'll just pick but it looks like there's already people in there voting so give it a couple more seconds and see what everybody says by the way once we get up to i guess a thousand likes i'm gonna just put up the code here so somebody whoever is quick can grab the uh the asset pack that i'm using here for all of these characters like 14 of them they're pretty freaking cool um all right let's see watching the chat now oh it's a little bit contentious on which one to go with now i don't know okay um i'm going to let the boating go until i finish uh eating this milk dead real quick and then we'll we'll go from there oh okay now take a drink and uh it looks like i think we probably have a winner here yeah anubis seems to have won by uh probably a two or three to one vote here so we'll go with him first um anybody you know obviously if you're following along and you're copying this you can just go grab medusa pull it in and try it too or maybe we'll get to it and have time to put him in as well so let's set up this anubis dude um oh he's got a script on him that it can't be loaded whatever i'm gonna remove it because i don't care about that i don't want a script on there i just want the character set up and want him running around animating actually i'm gonna switch to debug or out of debug to normal mode too all right so now i've got uh i'm voting for milk day all right so now i've got my anubis set up and i think that the way that i want to do this guy is going to be very similar to the the skeleton i'll set up a parent object that will have a nav mesh agent and then we'll just use like a click to move style system and then if i click on the enemies it'll kill him i was thinking about maybe going with the playstation controller but i've done that quite a few times recently and if anybody wants to know how to move with the controller it's very easy to adjust or adapt so i think i'm going to go with click to move setup form so i'll right click on here on the anubis dude hit create empty and we'll make this player and i'll drag it out and make a new vista child again just to get this thing positioned exactly where anubis was then i'll go on to the anubis player or announce player not anubis and we'll add the nab mesh agent that should there we go line up right around our player and make it so he can move on the navigation mesh now we'll create a script for our player so i'm going to go into my scenes folder or not my scenes folder while i go into there i want to go into the scripts folder and let's right click and just create a player script player in fact you know what before i do that though i'm going to update the enemy and the flag scripts into that just real quick so that everybody who's following along can grab these two scripts they're both very very small and very simple and if anybody is curious what it looks like it's essentially just like this just this little just where you can grab the files and copy them right out and it is a site i love using i use it all the time and i i highly recommend people get used to using it to share files this or something like that so here i'll paste in the flag right there update it oh and i want to hit add file i meant to do that oh actually no i don't need to add a file i've got the enemy got the flag i need to update the enemy though so let's go to update go to the enemy copy that and i'm just going to paste it in here and paste and update it all right anybody following along now has the latest code all right so let's set up that player script we'll go back into the player script and here what i want to do is check to see if the player clicks so if we click anywhere on the nav mesh or on the ground i just want to move to that point and then if we click on an enemy i want to make him attack the enemy eventually first let's do the movement though we'll set up some really simple movement in our update i guess i can get rid of start here i don't think i need it yet get rid of these two using statements and just zoom in and start filling out our update method all right so we want to check to see if we are um or if we've left clicked first so say if input dot get mouse button down zero that's left click uh right click is just mouse button one so if we have left clicked then we wanna just see if we've clicked somewhere that's on the nav mesh so we wanna do a raycast into the scene so i'm gonna use the physics system so say actually what do i want to do i'm going to say int hits equals physics y-s-i-c-s dot ray cast non-aloe so i want to do the non-allocating raycast i could also just do raycast but the non-allocating one is generally better to use in most cases and probably a good habit for people to get into then i need to give it a raise so i'm just going to put in the word ray because i don't want to shove this all into one line and then the results so i'll say underscore results this will do a raycast giving a ray i give it array and then it's going to fill up an array of results and give me back the number of things that it hit so first i need to generate an array so i'll well generate a local for it it says ray ray equals default i'm going to use camera dot main dot screen point to ray and we'll pass in our input dot mouse position this just gets us a ray into the game or into the scene using our main camera obviously i should cache this camera but for now i'm gonna just leave it as is and then we'll change it as we go so we're getting a ray here and i say obviously the reason is just that this is a it's generally considered a bad practice to call camera.main in code that gets called often all the time if performance matters your performance doesn't matter because we're not doing anything else it's just because it's slightly slower call than caching it all right so we're giving our ray that's the first parameter into the raycast non-aloe the other thing that we need is this array of results so i need to generate a field for it because the reason that we use the non-aloe one is that it actually creates this set of memory where it's gonna put the results and then it just reuses that set of memory so that we don't allocate memory that's why it's non-alloy so it's not allocating memory essentially so you don't end up with garbage collection or garbage allocations that you don't need and get rid of that keyword though and we need to allocate it once manually because we're not allocating it automatically we're just going to allocate it once at the creation of our players so say equals new array cast hit array and we'll just give it a size of like 100. we could hit up to 100 things any more than that we're going to have a problem we're never going anywhere near that so i don't think it matters all right so now we've got our hits array let's scroll down and let's see what we want to do we want to just check to see if one of these hits is on the ground and we're able to set our nav mesh to go to that position so we'll say four and hit tab a couple of times it should give us a for loop we'll go from zero to hits which is our number of hits or number of things that our ray intersected with because it could have intersected with one thing most time it probably will it could intersect with like 10 things if we have a bunch of props stacked up enemies and other things we're going to go through all of our hits and then we're going to see if um any of them have a point that works as a nav mesh destination so our player is going to want to set its nav mesh agent's destination i'm first going to cache our nav mission actually you know what let's let's write the code and then we'll cache it so we'll say um if nav mesh agent dot set destination guest ination i think it's definitely spelled destination wrong so i'm going to create the nav mesh agent so i don't have to learn how to spell let's go up here and we'll add an awake and we'll say underscore nav mesh agent equals get component nav mesh agent and then we'll add the using statement for the nav mesh agent and generate the field okay now i can get rid of that private keyword go down here and let it auto complete my set destination there we go so now if the set destination call on our now cached nav mesh agent fails so well first we need to give it a destination so what's the destination going to be it's going to be hits at i dot point i believe that's right right oh not hit sorry results results at i that point remember results is a raycast hit array so it's a collection of raycast hits we're going to loop through all of them most of the time it's just going to go through it's going to be one of them it's going to look at his 0 which is the only one that we have it's going to look at that point set that as our destination and this is going to return true or false depending on whether or not it can calculate a path to that point so if it can't return that point so or let's say if it can let's say it's able to set that as the destination then we can just break out of this loop because we don't care we don't need to do anything else in fact we could probably just return right i think breaking out is probably good though braking will just stop the loop and stop trying to set the destination anything else that should um i think that should do it that should move our player to wherever we click very simple click to move script let's zoom out real quick let everybody get a quick peek of what it looks like and then go try it out so jump in here and hit play oh we've got an error message what did i miss miss something uh here clear on the console oh no something in the wardrobe manager what is this error i don't know what's going on in here why this is giving me an error i'm not sure i'm going to uh comment this out and bug andrew badly i don't i don't feel like debugging and figuring out wardrobe stuff that um i don't need to worry about i think it's just from having that character out in the scene and something else going on i'll figure that out later though let's uh hit play now and see if it actually works though now i should be able to click oh come on oh an animation event not a problem okay go to the game view and click and oh no what's happening so nothing's moving i think it's because i didn't put the script onto the player oh or because i'm in not in play mode probably both of those things so let's uh stop playing i'm gonna uncheck the error pause the reason that i'm getting an error here is just that there's an animation event on some animation here that's set up and not hooked up it's not a big deal it's just something that i probably need to rip out of an animation that i probably don't want playing so let's um let's go add the script to our player and make him so he actually moves so here's our player you see that he did did have the navmesh agent but he didn't have the player script this is usually what happens when i'm playing and i have scripts that just don't work usually that they're not actually attached i click there we go like that he moves and he just kind of goes to wherever i click i can click all the way over there i can click on the enemy and it'll still click through and go to the ground even though i clicked right on an enemy because it's doing that where that iteration where it says hey the enemy is not a valid target so then goes on to the next thing that's below it which is the ground all right so looks good i can move to the enemies um now i think i need to make him either animate or make him attack and knock them off you guys want to see the player animate first or do you want to see him do the attack and uh knock the enemy back go ahead and uh just vote in chat real quick i'll take a quick drink and everybody can hit like real quick while i do that good stuff all right um and uncheck error pause and we'll go take a look and i'll just wait while everybody votes and start thinking about what we're going to do here so we're going to make this dude start walking around which is pretty pretty simple or uh make him knocks actually you know i'm going to make him start walking around before anybody even votes watch this so we can make him walk just by in our update saying hey animator dot set bull walk comma nav mesh agent dot velocity dot magnitude greater than zero then we copy the animator part here animator equals get component in children i like how everybody voted for attack so we're gonna do that by the time uh by the time everybody is done voting we will be on to attacking that's how quick setting up the animator is that's it that's all the code we need for the animator then it's just a matter of making an animator controller form so let's make our animator do the attack and and the uh the walk because we're going to need them both in our animation so let's set up the attack animation all right we'll go into here and we're going to create a well do we need let's think about it for a second for our animator controller um we really just need an attack and idle and a walk right we don't really need to change that up we don't need to have like a different flow for our player right we um we want to have walking and we want to have attacking i don't think we need anything else so i'm going to try this we're going to try using an animator override controller and then we'll see if we can just go that route instead of setting up a separate animator if not then we'll set up a separate animator but this might be useful for anybody who hasn't used an animator override controller sorry about the vote thing it was just too funny i saw all of the attacks come in after i was like alright i just gotta code this this walk up real quick because it's so simple and then the votes came in that's the delay of it of the youtube stream all right so right click create i'm going to choose animator override controller this will let me do is use that same animator but swap out the animations i'm going to call this player i'm going to rename enemy to character or actually i'm going to rename it to humanoid because it's a very simple humanoid type of animation and then i'm going to make the player override that one so i'll take the humanoid one that used to be enemy a second ago and just drag it in there now you see that when i have the player selected it shows me the three original animations on there so let me set it up real quick without overwriting them put them on the player and then watch it and then we'll switch it up so that it actually places his correct animations so i'm going to go select the player and we'll just take the player controller here oh i need to actually select the one with the animator the child here i'll take the player and just assign that right there oh you know what i want to do is just remove this blind shape manager let's remove that component because i don't need it right now i don't want to customize this guy i'm just going to use it the way it is all right now if i save and hit play let's watch what anubis does uh he just kind of acts weird and bugs out right the problem here is that he's trying to play the skeletons animation which doesn't work he needs to play his own animations because these aren't retargeted humanoid animations so to do that we'll just go over to our animator controller or the override controller right here this player one i'm gonna hit the lock button to just lock it and then i'm gonna go into the anubis folder you'll find that character and expand it out and then i'll just take his walk the anubis walk assign it to walk here on the player and then i'll assign the um attack one to attack one and then i'll take the idol wherever that is it's in alphabetical order so i don't know why i'm having a hard time finding it um does he not have just a standing idle let me see oh guard idle that's probably it i'll take that and assign it there and then as i think about this because this is really tied to that character model type i'm gonna actually rename this and i'm gonna rename this from player to anubis and i'm going to rename the humanoid to skeleton because i think that it's better if i just name them to match what the actual animations are now i should be able to hit play and see the same exact behavior on my anubis dude so if i go select anubis here go select the player go to my animator window you can see that i have the same controller here it's just swapping out the animations but i can switch them to a let's see select them switch them to a walk state let's see isn't it oh he isn't switching to walk because the code's already doing that they switch him to walk by just clicking around and making him walk he's acting really really strange we'll have to fix that some root motion offsetting going on and i can also well here let's stop playing hit play one more time and make him attack and then we'll go fix him up real quick so here we go we hit attack and you can see the attack works as well so let's fix up that root motion movement actually let's hit play watch what was happening real quick and see why why it's broken and then how we can fix it so i'm going to unlock the window here i'm going to stop this real quick turn the skeleton off go back to the player with it unlocked and the player selected i'm going to select actually the child here look at the little child object here and i'll put the game view in the scene view side by side so if i click and move this let's see what's happening watch as the character moves look at the z position here on the child and look at the player so the player object is here but the character is actually moved off the reason for that is that apply root motion is on and we're using the nav mesh agent to move it so the animator is also moving the character on top of the navigator or the navigation system moving the character i need to stop playing uncheck that box and i should make sure that it's unchecked yeah it is unchecked on the skeleton warrior it just happens to be checked on that one so that's why he was moving all weird let's hit play one more time run back over there and see if we can go attack that skeleton or get over to the skeleton so there we go i can run over to him i can kind of block him and almost stop him from getting getting to the flag but i can't quite attack him yet so that'll be our next step is setting it up so that he attacks and plays an animation that makes the dude go launching and maybe kills the skeleton so he can't attack our base and kill us all right let's do that now let's make it so that he um attacks and i guess just kills kills that skeleton so um let's see how do i want to do this let's think about it do you guys i this one i'm going to let everybody vote this time and i'm going to count your votes and we'll go from there so do you guys want to have the enemy um just like play a death animation and fall down and kind of fade away or do you want to have them go to like a rag doll and just go flying off the edge kind of down away and then they just poof after they've um ragdolled for a little while go ahead and just vote in chat and i will wait for your votes and we'll go with whichever one you guys prefer and once we're over 500 likes there um and we have the votes in we will uh we'll we'll do the one that you guys wanted to see that will either animate them or ragdoll them and knock them off the edge go ahead and pick and let me know which one you want to see and then also hit that like button and i will take another drink while we do that okay some anime ragdolls ragdolls ragdolls ragdolls okay a lot of a lot of ragdoll stuff um the assets that i'm using should be in the description they're also right at the beginning of the video too if not i'll make sure that they're in there but they should both be in there and if we get up to a thousand likes i was just gonna give away a code for this uh character here too so if we can just get a bunch of people to just share the video hit like and stuff and subscribe get there quick okay so it looks like yeah we're definitely going with ragdolls it's there's ragdoll ragdoll everywhere so let's do that let's set up a ragdoll for our skeleton now anybody that's not familiar with a ragdoll it's essentially just a system where you can turn the character into like a doll that you could toss and the body flails and flops around right it looks kind of like a realistic body going launch not a super realistic but like a doll body going watching right so to set it up it's actually extremely easy a lot of people don't know that there's actually a system built into unity to kind of automatically generate them there's a ragdoll generator i'm going to go to select the skeleton here and choose game object and i want to choose 3d object and choose ragdoll it pops up the little create ragdoll editor where i can expand out the skeleton here so i'm going to hold alt and click on the skeleton part this is the skeleton the other part was the mesh there i'm going to clap that down a little and maybe drag this over and we just need to assign all of the different pieces here we need to make sure that i assign the correct pieces so i'll make sure i can see my character in the scene view too so i'm going to go up here and we'll start with the pelvis and just drag the pelvis right over and i want to click on it too and just make sure that it's right sometimes bones aren't named exactly correctly um in this case i expect that they will be but it's always good to just click on them and check to make sure so now i've got the let's see left hips so if i click on that human thigh i expect that that's going to be the hip yeah that looks like the hip so i'll just assign that as the hip then i want the knee it looks like if i click on that this one right here left calf that looks like the knee so i'll just assign that as the knee and then the foot is probably the foot yep there we go we'll assign that now i'm going to collapse the left side and do the same for the right side so take the right hips it's just that one right there and then the right knee just double check it yep and then the right foot double check that one as well yep looks good so now we're halfway done we'll just go into the spine and we'll we need to get let's see we've got head a middle spine and then elbows and arms so let's find the middle spine let's see that's um maybe or let's see where's the spine piece that's up higher i guess that's probably about the middle of the spine right about here i'll take this piece right here and assign that as the middle and then let's find the head and the arms so we need a let's see a left arm and a left elbow here we've got let's see left collarbone not what i wanted i really want that left shoulder area right there i got the upper arm and then the lower one is the elbow got it selected you can see the forearm it's going to go in the left elbow do the exact same thing for right and then i think we're pretty much done we'll go into the let's see that's left left um where's right left collarbone here we got neck and head so let's get the head assign the head collapse that down we'll get the right hand side we got right upper arm and right elbow all right looks good i think everything's selected i can click through and see all the pieces and just double check real quick everything looks good right right right right left left and left and then i'll hit the create button and watch what happens so it looks like everything just broke a window went away and i got absolutely nothing right but if i collapse this down you'll see that um let's see did it actually create my ragdoll where's my ragdoll oh it should have created my ragdoll let's see i don't see it though let's see oh search in here it did where did it put it where is it as a chat oh it actually assigned it ah okay so it actually set it up on my character that's fine so what happened here was that it it created the ragdoll on my existing character instead of creating a new copy i was thinking it was going to create a new copy because it used to do that it looks like now it just created its own um or it really set it up on the existing character which is totally fine so if you look here i've got a rigid body now on the pelvis and i've got a bunch of different colliders as i expand things out if i save and hit play let's just watch what happens expect he's probably just gonna walk along and animate yeah just kind of walks along and animates as normal but watch if i stop playing and i'm gonna uncheck the actual let's take game view make it side by side go to the skeleton check it out if you're ready to see him ragdoll i'm gonna uncheck his animator and then i'm going to unpause bam and look at that he acts all weird so what's actually happening is the animator stops him from ragdolling because it moves his bones around it you know controls exactly the position and rotation of each of his bones when we turn that off the ragdoll mode just kind of kicks in so the body parts all fall with collision um and the joints are set up so that you see the little arms and stuff fall down and flap around but we also have the nav mesh agent dragging it along so the thing starts to act really really weird so what we want to do now is set up some code so that we can make this guy die and actually go launching with it so i want to turn off his animator and make him start ragdolling and flying away so i'm gonna stop playing and then we'll go over to our skeleton and i think for the for this code we just want to have like a a way for our enemy to die like make a public die method on him that makes his navmesh agent turn off and he'll just go flying back and ragdoll we'll start that way and then we'll make it so the player can do that death thing to the to the actual enemy so i'll open up the enemy and let's add in a method for dyeing and then we'll add a context menu to just excuse me to cheat killing him so i'm going to do that let's do it right down here at the bottom and we'll say public void die i'll zoom in a bunch and we'll add a context menu item and i'll just call it die this will be something that we'll be able to right click on on the component wait oh no it's i think it's context menu right context menu right click and then we can die so what's the die gonna do it's gonna turn off the nav mesh agent so we'll say nab meshagen.enabled equals false and then we just want to add some force to all of our rigid bodies or maybe add some velocity and launch our whole body in a direction so i want to get all of the rigid bodies on this enemy and then just set their velocity to maybe like up and backward for our player so let's get all of our rigid bodies we'll say far rigid bodies equals get components in children because remember we have multiple rigid bodies now if i can find the right one get components the plural one in children of type rigid body to get us all of our rigid bodies in an array let's say four each for far rigid body or let's say rb in rigid bodies let's say rb dot velocity equals underscore or that's called no underscore launch velocity and i just need to create a vector for my launch velocity and i'm thinking that that's going to be my transform back plus my transform up so just like back and upward at like a 45 degree angle so i'll just copy this i'll say var launch velocity equals transform dot back or transform dot forward negative transform dot forward really um plus transform dot up so that'll be our backwards plus our upward um i think that's probably good i might need to adjust the velocity and maybe give it some more death power but that should make it at least launch backwards now obviously i probably want to launch like from the direction of the player or something when we're doing a real hit but i think that for our quick debug hit this should work let's try it out so hit play right click hit die and uh what happened there okay so the nav mesh agent stopped and the velocity probably applied but remember i didn't turn the animator off so we need to turn that off as well let's go in here and say animator dot enabled equals false all right let's take a real quick peek at that die code one more time see the whole thing and then we'll go back into unity and try one more time all right we're in i'll go select that skeleton right click tell him to die bam and he died and look at that he just kind of fell backwards he didn't launch backwards very hard but he just did kind of die and fall backwards which is pretty much the behavior that i wanted i just wanted to be launching a little bit further so i'm going to go in here and let's adjust that launch velocity let's call let's um add in a launch um power so that we can maybe adjust it on the enemy and then maybe we could pass it in later or something uh i'm gonna go up here and we'll just add a serialized field for launch power i'll copy one of these floats paste it right down here and we'll replace this second attack delay with launch power and then i'll scroll down here and just multiply our launch velocity times that so we'll take our launch velocity and go launch velocity star equals let's launch power so we can multiply it and power it up a little bit the guy will go flying a little bit harder let's try that play on a right click on him and watch him die bam he goes flying off the edge all right i think that's looking a little bit better all right now i want to make it so that our player can actually do it so we'll run around we'll click on them our player will attack and then it'll launch the enemy um in the direction that we attack so let's i guess set that up we'll go into our player code let's go to our player script and right now our player doesn't have an attack right so our player just has an update that checks to see if we should move around and then sets a destination so let's make it so that we can um well attack by clicking on an enemy so we don't just look for destinations that are on the ground but we look for destinations that are on oh targets that move around as well so i want to make a way to cache our target oh thanks for the super chat by the way oh and it looks like there's a question about right clicking on a function that is with the attribute i've added an attribute here this context menu one it allows you to right click on things and call methods it's great for debugging and coding and testing things out all right so let's go through setting up a way to set a target and lock on to it i want to add in an enemy field here for our player that could be like our current target and then we'll set that if we've clicked on it in fact let's do that let's do the setting code first and then we'll generate the field for it so when we loop through our current hits right now we do a raycast into the screen see where we click we look to see if any of the spots are valid destinations first i want to check to see if any of the spots are enemies so instead of doing this call here where we loop through i want to loop through all of the enemies first see if there are some and then set a target and if there aren't any then fall back to selecting a ground position so i'm going to take this little chunk of code here from 25 to 29 hit alt enter and extract the method and say set ground target so this will try to set a ground target in fact i'm going to rename it to tri-set ground target i want it to try to set a ground target if if it's able to but the thing i want to do before that is try to send it an enemy target so i'll say try set enemy target and i'll pass in hits here generate a method for that and i'm going to do the same thing in it so what i want to do is look here to see if i can set an enemy and if not then i'll set a ground target instead so i'm going to say when we loop through triset enemy target or to implement this i want to loop through all of my hits see if any of them are enemies and then if one is set it as the target and then return true i'm gonna copy this line here that does the loop paste it right here and then i'll add in some braces and we'll get the object with a git component or we'll get the enemy component if it exists so say var enemy equals and we want results at i remember just like the code down here where we look at results at i dot point i say results at i dot get component nope dot collider dot get component not in parent though i'll get that auto complete and we want to get the enemy component so this will get an enemy from the thing if it has an enemy if we click on the ground it's going to be null so we'll say if enemy is not equal to null then underscore target equals enemy and i'm going to add braces here because i want to do two things i want to set our target to the enemy so this would be like how we selected and we've clicked on it we got that component it wasn't null that's our target we also want to return true because we want to return that we were able to get a target now i want to wrap up that loop or the statement there and then i want to say hey if we didn't get a target so if we went through all of our hits we didn't find one we'll return false i get two errors or three errors now once that finishes one is that target doesn't exist so i'll hit alt enter and just generate a field for it we'll take a look at that in a second there's that return doesn't work because our method is returning void or our return type is void i'm gonna change this to a bool though so we can return true or false get rid of the extra private keyword and then we can go up here and use that true or false value so now when we try to set the enemy target if it gets a target we don't want to set a try to set a ground target we'll say if try set enemy target is equal to true or actually let's say if try set an enemy target then return that's easy enough then we just won't do the code after it here i'll say like if it's false then try to set the ground target but i think that that's good enough that'll work that'll set our enemy target the other thing i want to do is when we set a ground target if we do find a ground target i want to clear our or we find like a ground destination i want to clear our enemy target so that we're not having two things set at the same time so i'm going to delete that private keyword again and just add in a little line here right before the break and we'll say target equals null to just clear out our targets that way if we did have a target and we clicked on the ground we're clearing out our target and moving to the ground instead so i think that's enough to set up a target but that's not enough to actually move us to the target right if i run this right now it's going to run it's going to move set a target in our data but it's not going to move to it um so we're going to need to make that happen in fact let's just go try it out real quick i'll hit play we'll look at it in debug mode and you see exactly what i'm talking about so hit play i'm going to go to debug mode here in the inspector just this little drop down and then watch when i click on the enemy there i clicked on him oh actually it didn't even set him as a target let's stop playing and see why let's go select the skeleton and if you look at him the part that has the enemy script on it right now i'm in debug mode so it looks a little bit weird the part that has the enemy script doesn't actually have a collider so if i try to click on him i might click on some of these little colliders but the get component call isn't going to get the enemy because our enemy isn't at that level of those colliders so i have a couple options here i could either add a collider to this guy which is probably the right way to go or i could go into this code here and just check to say when we try to set an enemy target let's expand this out when we get the component for an enemy we could just do a git component in parent which i think i actually undid when it auto-completed that way but this will make it so that it scans up that hierarchy so even if i click on one of these colliders that's underneath one of these ragdoll colliders as a child of it it should select all the way up to the enemy let's hit play and see if that actually works so i hit play you'll click on the enemy oh i can't see the guy so i'm going to pause go back to debug mode select our player and look at our target our target right now set the skeleton i'll stop playing hit play again watch it should be none and i click on the ground it stays at none but i click on the enemy if i can get him selected i thought i would be able to click on him and get it selected it was selected right okay well i had him selected for a second there i think you may have seen it so yeah wait i am able to kind of click on him i don't like the way that that feels so i'm going to put a big collider on him and make it a little bit easier to use so i hit add component and we'll just add a capsule collider and then let's see oh if i'm on the wrong object i'll right click and remove that i'm gonna go out of debug mode to normal mode go to the skeleton add a capsule collider for real we'll move it up just by moving the center up to one and then set the height to two make it a nice big tall capsule it's kind of hard to see it because it's got all these other colliders on them but those are all little tiny things and the other one the big one is nav mesh agent which isn't the thing i can click on i'm going to check the is trigger box because i don't want this guy colliding with stuff hit play and let's try it one more time the git component in parent call should work fine for this so it should be selecting actually i need to stop playing so select my player go back to debug mode one last time hit play let's watch the target as i select him bam goes to the skeleton i click off it's not the skeleton goes to the skeleton again but it doesn't move to the skeleton so let's make him move to our skeleton now to do that we'll just go into our update method and right now we never set our destination outside of the first um call right well actually where do we set our destination we set it whenever we do a click sorry i lied so we only set our destination in the try set ground target what we want to do instead is if we have a player or an enemy target and we haven't selected a ground target or we're not changing to a ground target we should set our destination to that enemy target's position so i can just go right up here and in fact basically if we don't click the button is probably when we want to do it so i'll say hey if we have clicked the button to do a raycast and set a target then we'll try selecting a new target so i'm going to take this little chunk of code hit alt enter maybe not let's see control shift r am i not able to just refactor this out let's see alt enter it does not want to let me refactor it out interesting so i'm going to take this little chunk of code and i'm going to cut it and it'll say um handle click i'll generate a method for that and then i'll just paste the code in some reason the refactor didn't want to do it automatically so i've got two little bits of code here the first one will handle a click whenever we do it and then we'll say else move to target so now i can get rid of these extra braces here generate the move to target method and then we will uh come on there's something really weird going on it sounds like there's a a weird party happening outside my window right now i have no idea why so our move to target is going to say navmeshagent.setdestination and we'll set it to our target dot transform that position um give me one second i have to figure out why there's a party happening outside my window all right i have no idea why there's a party happening outside the window but apparently there is i think it's ending soon though it sounds like it's gone away all right so this should move us to the target sorry about that oh so what we're doing here is checking to see if we've clicked if we have we'll handle the click otherwise we'll just move to our target but we actually should only move to our target if our targets knows no so say else if target is not equal to null then move to target otherwise there's no reason to set a destination to another target so let's save that off let's go back in hit play real quick and see if we can now follow around an enemy target by clicking on it we click and he runs over is he following him let's see i think yes yep he's gonna follow that skeleton looking good let's uh make that bigger in fact let's make it full screen we'll maximize you can see that he just runs and follows the bad guy looking good so now we just need to make him do the attack he follows him he gets up to him he just needs to perform his attack play that attack animation and make that guy do the death so let's set that up next we'll go back into code and let's find the part where we're doing our attack well where would we do our attack i guess it would be in our update right so in our update right now we check to see if we should change destinations or change targets then we try moving to a target but then we also probably want to check to see if we should attack our target so maybe we want to move to the target here i think that's probably right but then after that we'll say if should attack target then we'll attack our target too now it's starting to feel like that these are a lot of scripts that probably should be split into multiple or multiple scripts a lot of things but we're not quite at that point where i want to split it yet so i'm going to leave them in here but if you're thinking about it we are kind of getting close to that point where i think like maybe this this attack stuff should be separated out so let's generate a should attack target method and an attack target method should attack target method is going to be pretty simple we just want to check to see if we're in range and we've met the attack timer which is essentially what our enemy does let's go take the should attack here from our enemy take a look at it scroll out or ready to attack is what i called it where we do a distance check and a time check let's just take this little bit of code and copy it so i'm gonna take the ready to attack from enemy take it into player paste it and i'm gonna replace it over attack and then i'll copy that and replace should attack just reuse the same name and reuse that same convention i think it makes more sense now the distance to target check shouldn't check the flag it should check our underscore target's position and our attack distance well that probably makes sense to have as a field on our player as well i'll just generate a field for it hit f12 and replace private with a serialized field attribute and then give ourselves an attack range of maybe like 1.5 meters i think that's a fine default i'm going to get rid of that extra private keyword as well oh and add the f here so that unity stops complaining about my f missing from my float all right now i need a next attack time to finish off the ready to attack here let's collapse this out of here another quick look so we want to check to see if we're in range if we're out of range we return false we're not ready to attack also if our time hasn't met our next attack time so if the current time isn't greater than or it's less than our next attack time then return false so we'll generate a next attack time field f12 go get rid of that private keyword and move it right up here just so that it's in line and separated out from our serialized fields i'm gonna get rid of that extra private keyword too and then we'll um let's see i think that finishes off our ready to attack which is pretty much literally just a copy paste from the enemies ready to attack and then we'll go into the player and set up its attack target so attack target just needs to say hey target dot um what do we call it like take damage or die yeah target.die um that's it right i think so so i'll get rid of the private keyword and i think we're good so that should kill it so if we're ready to attack we'll kill the target if we're in range let's try it out let's hit play and see if it oh somebody call that cool down thank you thank you when we attack the target we should also say next attack time equals time.time let's zoom this in plus attack delay which i believe is the name of the variable on enemy let's go check that out um so we set up an attack delay right here yep there it is attack delay of three seconds the reason that we want to do this is so that we don't attack every frame otherwise the ready to attack would be true constantly we'd be telling this thing to die over and over and over and over resetting its velocity and stuff we don't want to do that we just want to do it once so we're going to go up here and add that attack delay field right after the attack distance just by pasting it and i just copied it from the enemy then we'll go in and hit play now we'll see what it looks like all right so now i can go click on the enemy bam he went over there and he killed it he killed it um and you can see he's killing it multiple times attacking him a couple times but he's not playing his animation so let's fix that and then let's fix the direction that he's making it fly off in so first we'll go into his animation or set up his animation so in the attack we'll just tell his animator to play that attack trigger so go to attack target here we'll say animator dot set trigger and pass in that attack zoom in a bit here so you can see what it looks like just setting that attack trigger remember that was on the player's animator controller which is really overriding from the skeletons controller go to the animator window here drag it up here it's just this trigger right here that forces us into an attack we're using that same controller just overriding with our own attack animation so that should make him do the attack animation um what else do we need to do oh we want to launch him in the correct direction so let's um now that he's doing he'll do the attack animation let's also fix that direction so when i right now make the enemy die we're just calling die and passing in a um oh really we're just passing in nothing we don't have any indication of what direction or really want this guy to go launching in so let's add in a vector for the force like a direction that we can kind of launch the character in i'm gonna say vector three in fact you know what we can do is just take this launch velocity make it a parameter vector three launch velocity uh would just be our parameter and we'll pass it in instead then i don't need a launch power i don't need to do this calculation i do need to however figure that out on the call instead so i'm going to save this off we'll go to the part where we reference it so i just click on the one reference here and i can actually click right here double click on it to go to the part where we're calling the code and when we call the die i'll just pass in a launch velocity so say launch velocity but we need to generate that launch velocity and i think what i'll do is say var launch velocity is transform dot forward plus transform.up so i'm just going to launch it in my characters forward and up direction and then i'm going to multiply that by some launch power in fact let's see the launch power is already there i'm going to get rid of that minus then i'll just move the launch power variable from the enemy to the player and i think it makes more sense there having a like how hard it gets launched seems like thing that would be like on the weapon or the player or something like how hard they knock things back so delete that and then move it over to the player of course we could have like a multiplier on enemies too for things that are hard to launch or something but i don't think that we need to do that right now so i've got a launch power moved over there let's save that off too let's go try it out i expect now that i can walk over and launch enemies off the side of the wall or something right so like if i walk over from this angle and i click on this guy bam i kind of knock him off and yeah he goes flying all right i think that's um starting to look good let me try it one more time though and go launch one more dude go launch him bam and well you see the one of the issues that we'll have is that even though his rigid body is going flying his actual body is staying here so the visual part of it is doing exactly what we want where it goes flying away but the actual character if i pause right now and i just click over to the scene view and we go over to our skeleton or where's our skeleton that if we look at our skeleton right here you'll see that the actual skeleton here is still in that same position with the nav mesh agent with the enemy script and the collider so we need to do um a little bit of work to really just turn this guy off completely and make it so that he is not hittable anymore so that he doesn't die again but once his body goes flying he's no longer a valid target i guess so we just um stop playing and let's um what do i want to do with this guy i got a couple different options i'm thinking that we'll just when an enemy dies just turn off their um their collider completely and then we'll do a co-routine to just make them disappear over time uh we could probably just time them out and make them disappear since they're already falling or we could have done a fade or something if we wanted to make them fade away over time but i think we'll just go into the enemy here and in the die method we'll just um say hey when they die we'll start a co-routine to destroy the game object or actually we'll just say destroy game object and we'll pass in like a5 so we'll destroy ourselves after five seconds and we'll just get all of our components or we'll get our collider component that's on us and just turn it off so say git component collider question mark dot enable equals false or no not question mark just dot enabled equals false we'll turn the collider off that we have on our game object and that will make it so we can't be used or we can't attack that dude again or can't click on that guy again and then we'll um destroy ourselves after time the other thing i guess we want to do is make sure that we can't die multiple times so if our nav mesh agent is off or if we've already died we should probably just return out of this so we'll say if dead return and it will say dead equals true and then we'll generate a field for it now we could have just checked to see the nav mesh agent state or the animator state or something else but in my opinion it tends to get messy when you start to do that when you start to look at random components in the state of them or other things that are somewhat loosely related as a check for this kind of stuff it turns into a mess later on because then you want to change it and then other things unexpectedly change adding a dead variable makes it very very simple we can only die once and uh that i think is really going to clean things up so let's try it out so hit play we'll run over here and we'll attack bam he goes flying and looking good so we can't attack him twice right there's well we can't attack twice it just doesn't actually do anything but now i think what we want to do is set up a bunch of enemies make them start moving over to the flag and then maybe i can build out a level and we'll start setting up some traps and things that can actually kill our enemies so let's uh let's set up a spawner first so we can have a couple different dudes or we think yeah i'm going to set up a spawner because that's going to take just a couple seconds and then we'll put the code up real quick and then we'll go through the process of making traps and towers and all of that fun stuff um while we do this though make sure that you hit the like and subscribe button or just share if you don't mind i really appreciate it it does help a lot get stuff out there and just get more people in here and like i said once we get to a thousand likes if we get to that i'm just going to give out a code for um some of these this character set it's a really cool set and i i forgets it should be pretty happy i bought it and i love it all right let's set up a spawner now i'm going to go into the scripts folder we'll right click create a new c sharp script and call it spawner spawner is just going to load or it's just going to create enemies um every so often so whatever will have a timer it'll spawn an enemy every so many seconds out of some collection of enemies we'll start with just one and that's pretty much it those enemies will just run over to the flag and try to kill us so we'll let's see get rid of our start method and clear up just the update and here's say if ready to spawn spawn oh there we go gotta control z a little bit and clean that up so generate these two methods get rid of the private keywords that i don't need the ready to spawn check can just say return time dot time greater than let's see greater than or equal to next spawn time so if our time is greater than the next spawn time we're ready so we'll generate a field for that turn this into an expression body method that's nice and tiny here and i'm actually going to take this and move it right up above spawn so that it's in the same order that it's actually called so if we're ready to spawn meaning our time has met that time then we'll spawn so we'll say first thing we want to do is set our next spawn time equal to time.time plus our spawn delay whatever that's going to be some number of seconds we'll generate a field for it real quick hit f12 replace private with serialized field and i'll have to fix that spelling and then give it a default value of like i'm gonna go with like seven seconds now i'm gonna see if i can spell this right serialized field there we go get rid of that private keyword again all right so now we'll spawn an enemy every however often but we need to actually do the spawning we'll call the spawn method but that's about it so let's do the instantiation instantiate it we'll say var enemy um or let's say um our instance because maybe this isn't just spawning enemies i think it's probably just spawning enemies but the instance is going to be equal to gameobject.instantiate and we want to instantiate our prefab which doesn't exist yet at our transform position and our transform rotation this will respond at our current position our spawners position and our spartan's rotation and we'll create this prefab i'm going to copy the prefab here go up and create a serialized field for it i'll make serialized field of type game object and just use prefab that's probably going to be an enemy i'll probably do something with an enemy here and not just allow generic game objects but until i get to that point where i actually use something on the enemy there's zero value in actually saying that it's an enemy only in fact there's really no value in keeping the return value of it or doing anything with it so i'll just instantiate the prefab at that position every so often clear out all the extra space all these gray unused lines and that's the entire code let's upload this whole code real quick i'm going to put it into that gist so if you're looking at the file down below you can grab it and i'm going to update all of the other files in here and then we'll go try it out and see how it works so i'm going to hit add file here i'm just doing this right in here by the way anybody that's kind of curious what this looks like just go in and add file and paste in my spawner code put in spawner.cs and then we'll add another file for let's see what do we have we've got our enemy and maybe i don't need another file i've got my spawner i've got my enemy and my flag so i'll copy the enemy oh i need to paste in the player i'll paste that over the enemy we'll take the flag code oops control z by code control a control c copy it all paste that all in over here so control a control v and then the last one is going to be the player so select that player code i'm going to go down here i'm going to add the player code so drop it in put in player cs by the way the reason that i like this so much is like i don't have to do any of the formatting i just paste it in put in the file extension it's going to format it and then it's going to give it to you all nice and neatly on this page so i just give you this page and um hopefully you were able to see it there on on the page linked below you can see all the code all right so we've got our player set up and um let's see what was i doing i i lost my train of thought for a second i was going to hit play and actually watch the spawners in action we'll create a spawner and then watch it in action now somebody's mentioning health bars too it's definitely something we could add we could put health bars in for our player or for our enemies if we want to give them some health first i just want to kill them though and set up all the cool traps that's a lot more fun than counting down their health we already have health for the flag too and health bars are pretty common thing there's lots of different ways to set them up so maybe we'll get to them though all right we've got the skeleton i want to do a spawner so i'm going to create a new game object i'm going to i usually like to start with like a cube or a sphere or something for a spawner just so i have a default thing where i can see the object at first and get an idea of where it's at then i'll just remove those things so i've got my cube here i'm going to rename it from cube to spawner i'll add a spawner script to it and then i'm going to remove the collider or just actually let's just remove the collider completely and uncheck the mesh renderer because i know that the position right now is right down here and then i'll hit the little uh icon button and i can just hit this to get an icon that shows up i guess i'll turn on the mesh renderer if i want to see where this thing is but i'm just going to leave it off so i've got the spawner there and now i have a feel for my prefab this is the thing that's going to spawn but i don't have an enemy prefab so i'm going to take my skeleton and make him into a prefab we'll go to the assets folder right click create a new folder and make it our prefabs folder and be our first prefab so we'll go into that folder take the skeleton and drop them into the prefabs folder hit the spawner select it and assign the skeleton as our prefab hit play and watch the magic occur right we should now see skeletons spawning and spawning every seven seconds or two because there's already one place but i can click around and knock them off come on die okay acting a little bit weird on the death there but interesting i'm not sure why they're they're they're ragdoll in a little bit strange that guy did a great job though some of them are acting a little strange with their animation um but we'll figure that out later i think right now i've got these dudes launching off and spawning i want to set up traps so so far i think um things are looking good it's time to build up some traps right um is there anything i missed i guess in chat if anybody's got anything that i missed before we set up some traps let me know otherwise i'm thinking that we'll set up a way to allow our player to replace a block or maybe a place a trap on top of a block i'll have to go through what the different traps are and see what the options are and then maybe build out some more stuff let's take a look ah sorry i had to take a drink there oh yeah the colliders probably are clipping through um on the ground and everywhere else and hitting each other i'll figure that out though it's looking at let's see what's going on in chat how's everybody doing by the way thanks everybody for coming out here i appreciate it for just having a bunch of people in these streams it's kind of crazy seeing so many people just join and watch and and give a bunch of cool feedback on stuff to put into these things and how to build these so it's been a it's been fun stuff i just have a blast at least all right so i think um i want to go through the traps now take i took a break there for a second to think but what i want to set up now are some of these different traps and see what would be interesting like uh that we could put down that will kill the bad guys right because i could build out a cool level and stuff but i think any any of us could build out a cooler level than me i just want to set up the code and make the code cool so let's uh take a look at these traps that are available there are a couple things that they already have by default there's this spike trap this swinging trap and a trapdoor i think the spike trap makes a lot of sense as a default one so i'm going to take the spike trap and just take a quick look at it let's hit drag it out into the scene and see what this object actually looks like and expand it out and oh actually here it's got an animator on it it's got an animator controller i'm guessing that it probably just plays the animation when we hit a trigger let's hit play and see got play mode on oh i'm gonna get out of maximize oh i can see it actually animating already that's promising so i'll go out of maximize on play hit play again and then let's hit the uh open button if i open actually it forces it the up it looks like and then close goes down interesting so i think what i want to do is set up a separate animator controller it just pushes it up and then um pushes it down i kind of add at a rate that i want or let me think i don't want to do that yeah i think that's maybe i'll just use the animation that's already on there so let's set up a way so that our player can first place this trap i'll make it so that a player can drop out a trap on the ground they can create an object that spawns on the tile on the ground and then we'll do something with that maybe it'll be this trap and it'll pop up the spikes maybe it'll just kill everybody that walks over i don't know we'll start with something simple and then we'll expand on it as we go so let's create an object that we can spawn and a way for us to spawn it let's think about really quickly how i want to make this spawn so right now we click to move around and i think that that that mostly worked so i would just click and move maybe if i just hit um i'm thinking maybe i'll just hit like one on the keyboard select the thing that i want to build and then that will give me the item on my mouse and i'll just drop it into the scene i think that that will work and it'll be relatively simple so i can hit one to select like a spike trap put it out there onto whatever block i want and then it'll place it let's um do that now let's create a i'm thinking i want to make a new script for this a trap placement script that's not part of the player script because the player script is moving around and attacking and all that and this is a totally different type of behavior so i'm going to create a new script in our assets scripts folder and let's call this a trap placer and we'll open that script up oh like that we get a new instance of visual studio gotta love when it does that so our trap placer script is gonna do two things gonna keep track of what trap we wanna place well we'll start with just a single trap i guess and we'll make sure that when we have that trap ready we can place it maybe i'll place traps with a right click so we'll look for a right click and we'll place a trap whenever we right click and then we'll be able to switch through the different traps that seems like a good plan so let's get rid of the start method here and zoom in the update in the update we'll check to see if we have right click so we'll say if input that get mouse button down and we'll check for mouse button one that's the right click if we right click then we will um well i guess we'll do a raycast see what tile we clicked on and then spawn the thing at that tile so we've already got a raycast set up right here in our players let's just go to the player code where we do the check for the raycast where we do our handle click we do array right here we do our aloe or our raycast non-alloc i'm going to just copy these two lines of code go back over to our traffic placer and paste them so we'll create our array and we'll do our raycast i'm going to generate the results hit again or the results array so generate this variable here which is going to be a field and again the reason that we're doing this is so that we don't allocate memory when we do the ray cast because we don't want to x well if we're doing this often we don't want to be allocating memory that we don't necessarily need to there's a good habit to get into so we're going to make the raycast hit array up here and we're going to pre-allocate it say equals new raycast hit array and we'll give it a size of i went with 100 before so i'll go with 100 again and then we'll say actually you know what i'm going to get rid of the non-outlook i'm going to change this up because i i know that it's it's good for performance but i don't want to confuse people too and make you think that like you really need to worry about the performance when we're doing this right click let's just do a simple raycast let's say var hit equals physics.raycast and we're going to do a raycast in in there and we're going to say um what do i want to do let me think about it i'll say math f dot infinity and we're going to give it oh actually no we're going to do it out var hit info just trying to think of what i wanted to do okay so what this is going to do because this is another way to write this and i think it's important that you know more than one way to write things don't just think you need to optimize stuff all the time just because it showed the non-outlook one doesn't mean that we need it every time we're right-clicking so when we're right-clicking we're gonna do a raycast this hit will now be a bool instead of an inch the raycast call just returns back one thing it's gonna give us the one object that we hit i'm just going to look to see if we've hit the ground and then here we'll just get a um actually let's do a layer check so we'll do a check against the layers so we'll say layer mask dot get mask and we'll use the word ground here as our layer mask so we're gonna do a raycast only against the ground because realistically when we're placing a trap we never want to click on an enemy we don't care if there's an enemy there we want to ignore it completely so we'll just make the raycast only hit the ground so i've set up my raycast now to use that as the layer mask and i actually need to make the layer exist too i'm going to go into my floor here go select it i'm going to select layer and then hit add layer the ground layer doesn't exist yet so i'll select user layer 8 which is the first empty one and i'll just type in the word ground with capital g i need to make sure that these match then i'm going to go back to the floor because when i did that it added it to the list but it didn't assign it so i need to go hit ground and then allow it to assign it to the children as well so what that's going to do is go into all of these little children here all of these little blocks and it's going to assign them to that ground layer so my raycast will hit that ground layer and hit those objects only won't hit the npcs all right now that i've got that what i want to do is say if hit so if i actually hit something in fact another way to write this is just say if our physics.raycast was successful let's clear this up a little bit so if the raycast actually hits something it returns true then we'll have the thing that we hit in this hit info object or this is a raycast hit named hit info so what we can do is just say um var position equals hit info dot point this is like the place that we want to spawn the object at we're going to say instantiate uh we'll say underscore trap prefab let's see if i can spell that right and we'll spawn it at our position or our hit info dot point and then we'll spawn it out quaternion dot identity so the quaternion dot identity is just a default it's our default rotation so we're just gonna spawn it essentially as if you put in zero zero zero on the rotation and not rotate it at all now we might want to set up a way to spawn these at different rotations but for now we're just going to leave them at their default and assume that any object placed at a zero rotation or non-rotated will look right in our game we need to create a trap prefab and i'm going to get rid of line 14 here too see let's scroll down just a little bit in case my head gets in front of that stuff and then let's um generate our trap prefab so generate a field for it hit f12 go up here and say game object and then replace private with serialized field again this will probably become a trap later but right now we just want to spawn any object that we have assigned whenever we right click so get rid of lines one and two get rid of that extra line there at the bottom go back into unity and then let's set up a trap object that we can actually spawn with our trap placer so i'm going to go back over here to our player which doesn't have our trap placer script we'll add our trap placer and then we'll assign a trap prefab to it so we need to actually create a prefab for this i think i've got this spike trap already created as an object i'm going to turn it into a separate trap or a separate new prefab so i've got the prefab selected this is the one from the asset pack from this dungeon pack but i'm going to select it i'm going to go into my prefabs folder i'm going to drag and drop it into here and i'm going to hit original prefab and make it a new prefab so that it's totally unrelated to that asset pack i mean related to it but it's not part of the asset pack then i'll rename it to spike trap with a space in there so it's my slightly differently named version delete this one out of here then i'll go to my player and assign the spike trap as the object now what i expect to happen is if i right click on the ground i spawn a spike trap now that spy crap shouldn't actually work or do do what i wanted to do or be right but i expect it to spawn and appear let's try it out not bad right so i click spike traps just appear i can click and spawn as many as i want just anywhere i want obviously there's some issues like i can click on the edge and spawn them way off to the side spawn them down here and they just keep popping up and not actually doing anything but hey it works right we've got spike traps and they're they're able to spawn relatively simply right so let's uh make the spike traps actually work um while i think about how we're gonna do that if everybody could hit the like button or just share the stream and really appreciate it because it helps again we're almost up to like a thousand likes and i can give away this asset pack and i'll be super excited about it we only need a couple hundred more i'll take another drink and then we'll um we'll make the first of all i think i'm gonna think i'm gonna talk out loud and think out loud for a second but i think we'll either spawn the um traps at the correct position so they kind of get centered onto a cube pretty easy to do or will um make them active i think i want to make them spawn onto a cube first and then we'll make them um activate and i'm thinking that the reason that i want to make them spawn onto a cube is because i it's such a cubey world like it's so easy to do that i could just take one of these cubes even make the trap like a child of it and then offset it to its trap position and i think that would work right i think that would probably be fine so um let's try it out oh did you know you had an sf tab to auto complete serialized field let's try that nope it did not work for me sf tab made a blend shape manager so no unfortunately all right so let's uh let's make these things snap into position so the first thing we'll do is we're going to instantiate this trap prefab at that position but i want to um well actually i want to get the object that we hit get that thing's positioned and then get it's offset so instead of using the hit info dot point we're going to say var hit object equals hit info or actually no we use the hit info dot collider.position that transform.position plus vector3.up so i'm going to call this a hit point or placementpoint and then we'll copy that and paste that in here now the reason that this is going to work at least i'm pretty sure it's gonna work is because my things are two units tall because my cubes are two units high if i take the center point that's right in the middle of that cube and i go up one meter it should be right at the center right in the middle so i'm using my transform position plus one meter straight up i think that's going to center it let's try it out real quick i'll hit play and see if it works click oh right click bam look at that now it puts them into the spot that i expect that's actually pretty cool oh except look at that did i click on the guy what did i click on there i'm not sure why that one went up there hold on let me click on these bad guys it seems like it is so for some reason my layer mask check is not working why is that not working let me double check so the floor is set to ground the enemies should not be set to ground right there it wouldn't make sense to be set to ground so is my layer check not working what did i do there um let me see oh i'm using the wrong uh the wrong okay this happens all the time by the way to a lot of people not just me so if you've ever had it happen to you before and you're freaking out like don't worry it's not just you so what happened here is i rearranged things and i messed up my call order here so what i'm doing is my ray is correct that's the first parameter here my second parameter the hidden post correct my third parameter is using max distance but i'm passing in a layer mask so actually because there are 16 overloads for this used the wrong one i wanted the one that has let's see i'm thinking math f dot infinity here and then a layer mask there we go now i've got a distance and a layer mask so i'll save we'll go back in hit play try it again and i think that that's going to fix the issue let's try it now if i right click yeah there we go now my layer mask check is actually working of course you might also notice i can still put like a ridiculous number of traps onto this thing kind of an issue i think i'll fix that real quick and then um we'll make it actually kill the things so let's make it so i can't put multiple traps on there to do that i'm gonna say var instance or let's say var trap equals that we'll instantiate our trap and then i'll say trap.trans trap.transform.setparent and i'm going to set it to the hiddeninfo.collider.transform so what we're doing here is moving this trap to be a child of the object or the block that i place it on because i'm using this weird block system for the game i think it's going to work if i was using like a regular terrain i'd have to come up with something different but i think that setting these as a child here is gonna work because then all you have to do is say hey if i already have a trap on me as a child then just don't i can't use this block as a trap it's not a valid trap block so don't don't try to use me so to do that i could just say like um well how do i do it let me think for a second actually i mean i could even turn off the collider on there there's a lot of different things i could do but i think what i want to say is well first i want to create a trap script so that we can assign a trap and make that a component so i'm going to go up here add a public class trap and make it a mono behavior and then we'll move that to its own file so hit alt enter and hit move to trap.cs now i have a trap script that i can assign to stuff and then i'll replace game object here with trap and then i'll replace the word trap here with trap as well so we've got trap trap equals instantiate trap prefab and then when we do the raycast and we get the object what i want to do is just check to see if it already has a trap child if it does then i won't spawn one if it doesn't then i will spawn one so i'll say if hit info dot collider dot get component in children trap is not equal to null return and i think that's enough right so if we have a trap on us already then we won't do the code to spawn a trap otherwise we will in fact let's explicitly call this out select it all alt enter and call this spawn trap so that will actually spawn the trap so we'll either spawn a trap or not do it if we already have one in that spy so now if i go back in and hit play should be able to right click on the same spot a bunch of times and not see multiple traps appear oh oh actually i can't spawn anything because i lost my trap script or i lost my trap object so my trap prefab right now doesn't have that empty trap script so i need to collapse all these down just add that script that i created remember it doesn't have anything on it i can just open it up totally empty script right now and then i need to reassign that to my player so go select the player go back to that prefabs folder assign that spike trap again hit play and let's see now i can right click place a trap i can't place a whole bunch of them in one spot though just one per block oh it's actually quite a bit easier than i'd even expected so let's stop playing and let's figure out um how to make the enemies actually die so lots of tips here by the way um checking to see if there's colliders yeah there are all kinds of different ways that we could do this by the way or just determining whether or not a trap could be placed we can mark something on those blocks we could add a script to them we could change the tag we could swap out the layer um we could even add a collider over the top it makes them unclickable lots of lots and tons of different options really so i'm just kind of going with any random one um but if you're if you're coding it up and you're trying to figure out which one to go with it whatever works for you should be fine so let's see what we want to do next i think the next piece is going to be to make the trap actually activate right the trap should play um play its animation and then kill the enemies when it animates so how do we want to do that i think what i might do is just use an um enemy or not so we can use the enemies die method which is somebody just called out in chat thank you but we could also use um the animators animation callbacks so i think we'll use an animation callback and make that trigger off something in the trap that kills all of the enemies that are inside of the trap so my thought here is we'll set up a collider or a trigger we'll keep track of the enemies that are inside it and then just kill the enemies that are inside it whenever um whenever the trap goes off seems simple enough right so let's take a trap and drop it out into the scene just to get it get it placed and get it looking right and i'm gonna add a collider to it so i'll add a box collider and i'm gonna make the collider a little bit taller so i'm gonna instead of being 0.18 let's make it like one meter tall and let's move the position up a bit so that it's nice and tall we have this actual actual cube here we'll set it as a trigger and then we'll open up the trap script and what i want to do here is add in on oh let me think you want to add an ontrigger stay or an ontrigger enter i think what we'll do is keep track of all of the objects on the inside the trigger um as they come in and out and i'll just do this so that we can have a list and just for fun so let's say on trigger enter and we'll say um enemies oh actually here let's get an enemy from it so we'll say var enemy equals other dot get component enemy and then if the enemy is not equal to null we'll add it to our enemies list it's the enemies that add enemy pretty simple hit generate field for it and we'll create a field that's going to be a list of enemy now list didn't auto complete it gave me auto audio listener because i don't have the using statement here's some put list again hit alt enter and add the using statement for collections.generic i'm going to get rid of private and just replace it with serialized fields so we can see the list in the inspector without switching to debug mode and then i'm going to go into um or go down a little bit and just add an ontriggerx in fact i'm going to copy the ontrigger enter paste it replace enter with exit and then replace add with remove no reason to write all of that out so now when we enter the trigger we'll add ourselves to the list when we exit we'll remove ourselves very very simple um and that should be enough so that when we fire off the trap we could just kill everything that's inside of her call the die on it so let's um actually let's do that too let's make it so that we can trigger the trap um let's say public void trigger trap and then here we'll say for each far enemy in enemies enemy dot die and then we need to give it a velocity so we'll say um vector three dot up times five we'll just launch them straight up in the air they won't launch back they'll just go straight up all right so that should be it for our trigger trap we just need to make a way to call it so i had a context menu say trigger trap and now i should be able to go into unity watch the enemies run over it and then watch them i guess why let's try it out we'll hit play oh whoops i i need to um actually update my trap so let's stop playing i need to update the prefab so i i modified that spike prefab but i didn't actually apply it so i'm going to hit apply all here it was just off the screen so i went over here and hit a pile i totally just missed it you see let me just change this real quick so you can see what it looked like again so it was like that and i hit apply all let's change that back to a two and i don't think i have any changes there we go apply it all again now i've got my my box actually updated and then i should be able to right click on it and hit trigger trap once they're inside of it so i'm gonna hit play one more time and i'm just gonna watch the enemies go through this trap and then i'll hit the trigger trap button once they're on top of it oh they're not actually inside the trap okay we're gonna try this one more time i'm gonna duplicate my trap because i'm terrible at playing really fast i'm gonna hit play i'm gonna watch them come into the trap so we should see the enemies list go up once they enter it we did not see the end oh okay why didn't we see the enemies list go up i think that the reason here is because we don't have a rigid body on our skeleton so we're going to go to the skeleton the enemy add a rigid body and then we're going to make it kinematic uncheck that has gravity and then we'll apply the override and play again so that we're actually going into the component to enter the trigger we need to have a rigid body on one of those things there we go now you can see that there's an enemy in it there's two enemies in it if i right click and hit trigger trap and un pause you see that they went flying and they went launching up in the air so now i just need to make it so that that code isn't called by me right clicking and is instead called whenever the animation fires off so whenever our animation triggers and the spike goes up i want the enemies to die now i don't think that i really want to have that completely controlled by the animator like it is right now in this animation controller so i'm going to make my own animator that controls the opening and closing real quick and then we'll um we'll use that as our as our control point and then we'll set up the code to actually trigger it on and off so let's go into the project view and let's find this trap this spike trap right here i think it's this is our controller i'm going to duplicate that controller drag it over to my animation folder right here and then just rename this to spike trap with a space in it so i know it's mine i'll open it up and then i'm just going to add an open and a closed state that we transition between instead of two triggers here i want to have just a bool i'm going to add a boolean parameter and i'll say open i'm going to delete the open and close triggers here that that were already on this one and then i'm going to make a well let's make um close the default so i'll set that as the default state delete this empty one i'll make a transition from close to open and a transition from open to close i'm going to delete out these any transitions here there we go i think that looks better and then what i want to do is just set up the condition so that open makes it go to open and close makes it go to close so click on the open one open true um i don't know if i need has x i probably maybe i need house extra time on i'm not sure how these are set up i'm going to leave them i'll add the condition for open to false on that one and save it off so now what i expect is if i use this controller i should be able to just check the box to turn them turn it up and down i have no idea if that's going to work i haven't really played with this animation so we're going to find out i've got the spike trap selected i need to go swap out the controller take the new controller that i just made assign it there go select it again go to the animator now i should see the correct one i hit play i'm just going to hit the open box and hit that yep there we go it does exactly what i want so if i check open it's up if i check close it's closed so i'm going to stop playing or yeah i stopped playing save it off and i'm gonna go into my spike trap code right now and then make it just say open or close or you know open and close doesn't really make sense i'm gonna call this active because i think like i might want to have a bunch of different traps and they're all going to want to set the active state so i'll set it to active to true so when i trigger my trap um actually yeah when i when i fire off the trap how do i do i want to set the animator to active and i want to call trigger trap in my code okay yeah pretty simple so let's add an update method here say update i'll say if should trigger trap uh or let's say if um should trigger let's say it should toggle trap i like that better so if should toggle trap then toggle trap so we'll generate a method for if this should toggle trap and then another one for toggle trap i'm going to move the should one up here since that's what i want to deal with first get rid of that private keyword get rid of all these private keywords really and then let's figure out how we determine if we should toggle the trap i'm going to say if the time is greater than or equal to next toggle time then the answer's true we'll say return time dot time greater than or equal to next toggle time pretty simple so we'll just toggle on and off at a time generate a field for that and turn this into an expression body method and then we'll get rid of that private keyword too now the next thing i want to do is say hey when we toggle the trap let's set our next toggle time equal to time dot time plus um maybe a toggle rate so say underscore toggle rate generate a field for toggle rate and hit f12 make that a serialized field and give it a value of i'm gonna go with like five seconds no let's go with three so it stays for three seconds turns up and down every three seconds um i'm gonna put that right here i think no i want to move the toggle time up trying to figure out where i want to place these things so my serialized fields are next to each other so that's enough to determine if we should toggle and then set the toggle time but the next thing i need to do is actually turn on that animation right so let's set the animation to either true or false based on what state we want it to be in if we want to be toggled on or offer active or inactive we'll say git component animator not animation animator dot set bool and then what did i name this i already renamed it to active instead of open so i'll switch that to active and we want to set it to whether or not it should be active um this is a underscore trap active so this is going to be a bool that we'll just turn on and off in our toggle trap so here i'll copy this and say trap active equals not trap active that'll switch a bull so if it's true it'll switch to false if it's possible to switch to true but i need to declare it first so i'm gonna hit alt enter generate a field for it go up to it and let's change this from object to bool because it's a bull it's true or false only and get rid of that private keyword so now we've got a defaulted to false trap active variable it's going to be off by default and then every so often or every toggle time this will return true we'll call toggle trap which will update our toggle time to the next whatever three seconds or whatever it's going to be three seconds from now it'll switch that boolean state and it will say hey set it to either trap active or trap not active now the last thing we want to do is when we activate the trap make the enemies go flying so say if trap active then trigger trap so that will make the uh trap launch the enemies up in the air if uh if the trap is set to active in this toggle so here we go let's try it out i think that um honestly we should have just working traps now i don't think that we're missing anything let me make sure i don't have anything to apply in overrides there we go got that set up i'm going to delete the two traps replaced save hit play and i'm going to see if i can kill enemies now with trap i drop out a trap drop out another trap come on traps i want to hit the enemies in time i don't think they're going to time right okay well what happened there watching there we go now enemy i saw an enemy die like i expected let's see if another one dies all right looking better now i could add a little bit of a delay so that they don't um go flying up right away and maybe like a tiny bit of a delay so they kind of look more impaled or something but i think that on the stream it's probably even hard to see that there's even a delay there look at that my traps are working i'm able to launch them i can run over here knock the dudes back i can run around and right click and place traps i think i want to add um at least one more trap type before we wrap this up i also want to see if we can get at least like 750 likes maybe we'll get to 750 and i'll just show that code here i don't know if we're gonna get to a thousand but get to 750 i'll put the code up and then somebody can grab it and we'll have a lot of fun with it but first let's put in at least one more trap so let's go through um trap section here and let's see what the options are they've got a swinging trap and a trap door that are already created what else is in here um a little fire thing and a fire any other cool traps a cage lots of cool props here but i don't know if there's lots of cool pre-made traps so i think i want to go with one of these too and i'll just let everybody in chat decide so we'll either go with a um swing trap here's this one so it'd be like this thing that's going back and forth and maybe smack into enemies and launch them flying one way or the other or a trapdoor that'll just drop them down and kill them so if you have a preference go ahead and put in the one that you prefer right now in the chat and then we'll go with whichever one gets the most votes in just a second we'll drop that one in we'll build it up and hopefully we'll be at 750 likes before we even get to that point ah and i'll take a drink and um eat more milk beds while we wait i'm trying to think of whatever close up would be funny i think i i'm going to build out some levels or a little bit more map while uh everybody talks about what thing they want to see added there we go we're in grid snapping mode just duplicate out some more i feel like my level is a little bit lame and i'm not a great level designer but i probably make something a little bit cooler so may as well hmm i see lots of talk about the swing trap in there a little bit about the trapdoor and some flamethrower give it another second or two do a couple more of these uh little blocks and then ooh watch this be kind of interesting because of how this game is set up maybe it'd be like a some alternate paths that that might make sense that we could set up traps on right like that i have no idea i'm like i said a terrible terrible level designer my beautiful level design work so okay i think um i'm going to go through the answers here lots of swing trap a bit of swing trap door stuff too i think that we'll um ooh a trapdoor that teleports back to the front too that's not a bad idea either um maybe we're just doing both all right well let's start with the swing trap since it got the most boat so actually first let's go and rebake our nav mesh because i just added a bunch of new terrain let's hit bake and see what we get all right so now let's see how do i want to set this up i'm going to take um my spawner duplicate it and move it over here so we have two spawners we have enemies coming from two spots and then we'll make our swing trap now that we've got um multiple enemies coming in and obviously we don't have any costs on this so we're kind of overpowered but i think that that's fun for now um adding in costs and limiting ourselves is easy to do um killing things is a lot more fun so let's stop playing and let's set up our swing trap now so our first trap is this little spike one and it's just got a collider that checks to see if the enemy is inside it and then when it triggers it fires off and hits all of the enemies i think that the swing trap is probably going to be a little bit different because it's really just like a swinging object going back and forth that should smack enemies and if it hits them i guess just kill him right i i can't think of anything else it should do right now so let's do that so we'll go into our dungeon pack we'll go into our traps prefabs and traps take the swing trap and i'm gonna drag it right out here i'm gonna set it up as a big giant trap and turn it around there we go so okay this is gonna set up a little bit different so i think this through so i'm not sure how i'm gonna let the player place it yet so i probably will set it up um pre-placed and then we'll figure that out right after that so let's hit play and see how this animates actually okay so just kind of swings back and forth it does swing kind of fast i think i want to slow that down a little bit so go to the swing trap i'm going to change the speed to 0.5 hit play and try it one more time okay i think that's better i'll give my players a little bit of time to walk through or do the enemies um in fact i might need to even modify the animation a little bit more it seems like it's going to hit a lot but whatever we'll go with it the way that it is so let's expand it out and let's set up a collider on the blade but what i want to do is make it so that this blade whenever it hits an enemy it just kills the enemy so i'm going to right click on it and we'll hit create um i'm going to create a cube hit w move it down here and just make it right there as a child i'm going to hit play and just make sure that this is animating the way i expect it to so the cube is in the right spot it looks good now i'm going to take that cube and shrink it down a little bit because i want this to be the collider that the enemies are hitting but i don't want it to be anywhere near that big i want it to be a little bit smaller so it's not super simple to just kill enemies let's make it like 0.5.5 and 0.5 a little bit smaller here i'm going to hit correct transfer edit mode again i'm going to shrink it down even more i'm going to go with this small cube so if you hit the little edges there you're safe you're not going to die to just everything now i'm going to leave the box collider there enabled but i'm going to turn off the mesh renderer and then i think i'll save that off now i want to add in a component here on the box collider or on this little blade that's gonna kill the enemies so let's call this um a blade in fact i'm gonna go into my scripts folder create a new script for it and i'm just gonna call this um blade trap i'll open it up and then we'll add an on collision enter method to it so say on collision enter we'll get an enemy component see if there is one so say bar enemy equals collision dot get component equation.collider.getcomponent i got the inparent actually you know in parent makes sense so get component in parent because we may end up hitting one of those other colliders and we'll look for the enemy so if we get an enemy we'll kill the enemy so we'll say if enemy is equal to no just return otherwise we'll say enemy dot die and maybe we'll do something else that's probably it we probably won't do anything else but we could do something else make them kind of go launching actually now we need to um determine which way to launch the enemy so i'm going to make them just launch in their backward direction right now we can make them launch in the direction that we hit them in but i don't want to deal with that right now i just want to make them launch kind of backwards so i'm gonna say enemy dot forward or enemy dot i'll do exactly what we did for transform dot forward negative that plus enemy dot transform up let's just launch them up and backwards for now i think that that'll probably end up looking the best at least initially so save this off get rid of these two using statements up here save one more time and we'll go back in and let's see we need anything else we'll go on to our blade we'll add that uh blade trap script to it and wrong spot i'll remove that and drop that onto the cube where it goes and add this i'm going to rename this cube to um trap blade or it's called blade trap that's the actual blade part so now when this piece hits an enemy i expect the enemy to just go dying and uh that should fix it let's try it out bam one enemy two enemies three enemies okay so this thing seems to just kind of uh chop and kill all of them which was kind of my concern was it it seems um because it plays so often you know what here's what we'll do let's change up the animation on this thing so that it's not constantly playing because otherwise it's going to be too powerful of a trap and we won't actually be able to use it so let's see how we would modify that up a little bit let's go into the swing trap and take a look at its animation so it looks like it's animation right now it's probably just an animation that swings it back and forth let's go double click on the animation and then select the trap and see it in action so here you can see the actual animation we actually modify it and kind of change it up i think what we'll do is i'll take this keyframe here copy it paste and i'm going to drag it um oh right to about here and then i'll take this other the ending keyframe copy it go over the same where did i go two spaces paste and then i'm gonna zoom out so right now this entire animation is set to one second but it's got a keyframe here so i added a little tiny pause that pauses before it goes and then it swings across if i select the whole thing now with this with the setup i can drag it out and expand it and now i should be able to see it kind of sit and wait and then go it's a little bit slower i'm going to expand out the weight so so now what i can do is take this little section here make it wait like um let's make it wait one second and then i'll make it swing for a second here let's zoom zoom zoom so it'll swing at the two second mark it's halfway there so it'll go sit still for one second it'll swing and then it'll get all the way to the oh it's getting to the other side in one second let's make it get to the other side in two seconds no i'm gonna go to half a second so it'll wait for a half a second and it'll swing for one second one way then it'll wait for a half a second and then return i think that that is the timing that i want let's try this out there we go so it waits starts to swing starts oh it doesn't wait i need it to wait here i'll copy this paste and then swing for another second and then get rid of that keyframe there there we go this is closer to what i wanted okay so now i play bam swing bam swing there we go that's better hopefully that made sense to everybody we're essentially just expanding out or modifying this animation and the reason that we can do that is because this animation here is just part of the project it's something that's recorded in the project and if you haven't ever made an animation before you can just go to an object go to the animator window or not animation window click on this little thing right here and hit create new clip if there isn't an animation you can actually just hit the button it'll be right there and you give an animation name and a path it'll create an animation you can record it so this i think is going to make it a lot more playable so that my enemies can walk through and they don't always die let's try it there we go so now it's a trap it takes up two spots but it's not completely deadly in that it's gonna kill everybody all the time so i think that that's pretty good now let's uh make it so i can place this trap and then we'll crank up zombies spawn maybe add one more thing and see if we can get to that um 750 or a thousand likes if we just hit the button or go drop it on facebook or instagram or whatever you uh you guys use nowadays um stuff all right let's do this um so let's make this trap spawnable i will go to my player and right now my trap prefab options or just one i have a single spike trap and i want to make it so i can spawn between i guess two different traps from multiple i'll make it so that we can just hit a hotkey and pick the trap that we want to use i'm going to turn the trap prefab into an array and pluralize it so i'll replace that prefab with prefabs and then i'll say um well let's add an end for our current trap index that'll be the trap that we're using it'll start off at zero and reference the first trap in here and then we'll say if input.getkeydown keycode.1 alpha1 um trapindex equals 1 or equals 0. and then we'll just say hey if we hit um alpha two it'll equal one now i don't like this code at all obviously like if i'm gonna do more than two i'm gonna change this up and i'm gonna make it so that we just look at the key code loop through them all and then check it um let's do that four like four one to ten or let's go let's just go to nine what we're gonna say is if the key code of that plus i then current trap index equals i and then break okay all right sorry i i lied i was going to change it anyway so the reason i'm doing it this way is so that we don't have to set up an if check for each statement and so that nobody sees that ugly if statement for each one i don't want to do an if we pressed one check one if we press two check two if we press two three make it three so what we do instead is loop from zero to nine so just think of the values zero to nine getting added we're checking to see if the key code for alpha one which is one on my keyboard plus zero so and not adding anything to it so we're literally checking alpha one if that's pressed then we set the index to i which first time through is zero then if that's not true we just check the next next iteration of the loop we say hey if alpha one plus one was pressed which is literally alpha two if i put the mouse over you see the value is 49 plus 1 it's going to be 50 which is alpha 2 and we set the index to the next one so that way we don't have to write the code for um setting up a bunch of them or copy and paste it just loops through all of them this will let us select the one that we want to select now we just need to instantiate the prefab that we want so instead of instantiating trap prefabs or trap prefab we do it at current trap prefab index and that's pretty much it now we should be able to select multiple traps and right click in place them let's try it out so go back into unity i need to reassign my trap prefabs because that got cleared out so we'll go to the prefabs folder we'll take our spike trap drag that in i don't have a trap for my um my swing trap so i'm going to drag that down here make it an original prefab rename it to swing trap and then we'll assign that swing trap from the prefabs folder to our player so go to the player assign it right here oh i can't actually assign it because it's not a trap so i'll add the trap script to it and then we'll assign it then we'll go oh see that's an issue that's the thing that i don't really like i don't like that my trap script right now has a bunch of stuff on it that my swing trap isn't using so that's probably something that um if i'm gonna work on this any longer would want to go back in and clean up because i don't like having the um the trap script on things that were just doing stuff for no reason it doesn't necessarily need to be a trap there we go i can drop out my traps i can right click do that one so that's the first trap spike one i'm gonna hit two on the keyboard right click and bam i now have this weird little um well i have this trap that doesn't actually work right because like if i place these i can place it but the position and the size is all wrong so it's not actually where i want it to be or kind of the way that i want it to work so i'm going to stop playing and we're going to just change this one up a little bit i want to change the way that the spike trap places now i could make the spy trap really smart so that you have to pick two blocks and place it in between those two blocks but i think what i'm going to do is make the offset of it be like down here at one of these positions so that we just place it on a block and it's just kind of offset and sideways always i don't really care because this isn't a real game that i'm going to launch that i need to worry about getting it perfect on so i'm just going to make that a child so right click we'll hit create empty make an empty child drag that out make the swing trap a child of that object and then i think what i want to do is take this position it down here so that the object is right there on the block this game object and then take my trap and move it back i'm just going to move it kind of into position so now that the pivot position is right here so when i place the object it's there but it's offset and kind of in the right spot obviously it could hang over the edge or something but i don't really care because again not something that i need to deal with right here we could always figure it out if we wanted to and perfect it if we need to later so i'm going to take the trap script move it up one level rename this to swing trap and then i'm going to delete the prefab down here and then just recreate this prefab below so take the swing trap oh drag down oh no i've broken it so i'm going to what have i done but when i broke that when i deleted the prefab down there i actually broke the child prefab reference so i'm gonna go in here and just break that up so right click um i can't remember if it's in here prefab yep and hit unpack completely then i'll take the swing trap and just drag it in there we go now i've recreated the prefab from scratch we've got a new prefab i'll take the player assign that swing trap one more time hit play i'm going to delete the trap that's out here play and now i should be able to hit two and drop out a swing trap there we go and i can hit one and drop out spike trap now obviously my rotation on my swing trap is a little bit strange and the positioning is not perfect but i think that you can get the idea of exactly how we're placing these things out i can also click on my enemies and just run around and knock them off the edge um i think i want to do one more trap real quick and then i'm gonna do that giveaway and start to wrap things up it's been going for a while and i wanna you know we're i don't think we're gonna get to a thousand likes but we can get to at least 700 i'll put up that code but first we'll do that trap so if everybody just hit the like button and get us at least like 700 um i'll put up the code in just a little bit i'll let you guys all know before and somebody can go grab this art pack and you know build this and see whatever if they want to build build this or build something else out of it i think it's a really cool pack that's a lot of fun to work with so let's set up the um that little trap that lets enemies just drop down through the ground i think that that's a kind of a fun one and an interesting one and it's gonna well i think require a little bit of a change to the way that these things work so i'll go into the traps folder there's a trap door here and i think if i hit play on it it's got an open animation let's just hit play and watch and see real quick so we play and yeah it looks like it's animating it looks like it opens and closes right so let's um take a quick look though and see how we'd get that to show up because right now if i open that up and we look down like we're gonna we're not gonna see through the um we're not going to see through because there's a ground piece down all right so if i have this piece down there you're not going to see underneath it because there's there's ground so you can't see the guy falling down i think what we want to do is make it so that when we place one of these traps they place a trap door trap it'll actually replace the ground piece um completely so i'm gonna have to make a little bit of a change to the code but i don't think it's gonna be too much to do so let's set it up let's make our trap door into its own prefab so i've got my trap door here um let's see what do i need to do with it i want to just add a trap script to it so i have the trap so we can assign it it's got an enemies in range i think that makes sense i want to add a box collider and i want to make the box collider match up with this object so i'll make it bigger resize it and make it kind of match up with my my thing so my thought here is that any enemy that's in it when it activates will turn off their nav mesh agent turn on their rigid body and just start falling to the ground so we'll make their rigid body not kinematic and they'll just start falling to the ground i think that's all we'll need to do but we need to make sure that when we turn on the trap um or that we control its activation with the trap script and that we um first we need to do oh disable the tile below it so let's set up a way to control the animation real quick so we'll open up that trap door script and it's just like the other one so this is just like our open and close script on the uh or our activate script on the other animator so let's just go in and create an animator override like how i said animator or weird that was strange so i'm going to make an override controller for our trap door trap instead of a new controller so hit create animator override controller and i'll call this trap door and then we'll make it override the spike trap which just has a single animation that it plays open and closed i think that's the way that this thing was set up right let's open up trap b we've got trapdoor and md playing in positive direction or negative direction so that's it trapdoor and d is the one that we need so i'll go back to my animator override controller again for the trapdoor and we'll find the trap door i'm going to drag this over so you can see it just a quick search find trapdoor nmd assign it there and we'll go to our trapdoor assign that animator controller save and now we have control over it in our trap script i didn't have to change anything else actually i want to remove this trapdoor demo script i don't want that on there at all but i didn't have to change anything else because our trap script already triggers that active animation or that active bullet toggles it on and off we're using the animator override controller so i didn't have to do anything at all just reuse the stuff that i've already got so let's watch it um i should see it open and close like that opens and closes relatively fine seems like it's doing its job now let's replace one of these tiles real quick with this animator controller i'm going to take this i'm going to take this tile right here i'm going to just turn off the box collider and the renderer and i'm going to move this over here and then i'm going to hit play and just watch and see if the dudes fall through it oh nope nothing they don't fall through yet and if i move my spawner over i expect that you're not going to see them fall through either so here let's hit play just watch and see should expect that they're not going to drop through the through the trap right so they're going to walk over it just go right past it the reason for that again if i hit pause and go to navigation is that they're using the nav mesh so they just walk past the place so what we need to do is make our trap actually deal with um knocking the enemies down so go to the trap door trap open it up and then when we trigger the trap instead of um well doing our trigger trap and setting all the enemies dead actually this should probably be a spike trap um what we want to do is set the enemies to um fall so let's change this up a little bit let's make a new trap script and let's do a little bit of inheritance and abstraction so i've got a trap here and when it should toggle and then the toggling should trigger the trap and then the triggering should do something but what the trigger does should probably be somewhat abstracted and i want to set up a spike trap and a um trap door trap or door trap let's call them both of those so i'm going to change this up i'm going to make this an abstract class no i'm not going to make it abstract yeah i am i'm gonna no i'm not i'm deciding ah up in the air i'm not gonna make it abstract but i am going to inherit from it so i'm gonna say public class spike trap and i'll make a trap as the base class now the reason for this i'm going to take this trigger trap method and i'm going to make this well first i'm going to copy it select the whole bit of code here copy it and then i'm going to make this virtual and then i'm going to delete out the implementation so now i've got a virtual void trigger trap that doesn't do anything by default on the trap i'm gonna go up to my spike trap and i'm gonna say override and then i'll put in my trigger trap method and then i'll just paste in the code for trigger trap there we go so right now i've got a couple things going on i've got a class that's inheriting from my trap that's going to override my trigger trap and an error message here saying that enemies is not accessible reason for that is that enemies is not protected it needs to be protected or public to be accessible from a subclass so i can change this to protected and suddenly my error message is going to go away i'm going to move my spike trap to its own file so i hit move to spiketrap.cs and then i'm going to create a door trap and then you're going to see why i did all of this because it doesn't make any sense until you see the second part so let's go up here and let's create another trap a public class door trap we'll make that inherit from trap as well and then we're going to say override trigger trap and then in here i want to loop through my enemies and i don't want to kill them i want to make them fall so i'm going to say for each bar enemy in enemies enemy dot simple enough i'll move my door trap to its own file hit ctrl shift b and get my build error and then go to that file and fix the error message so let's see oh there's my error list i'll double click on the error we need to generate a file method in our enemy so it's not going to work until i create a file method so i'll generate that with alt enter hit enter f12 f try it again alt enter generate a method f12 and it's not going to it so let's just go to the enemy and see it i'll go over to my enemy and let's see if i can add in the fall method for some reason it's not generating my fall method okay so we'll just create a fall method on our enemy script here so what i'm going to do is instead of dying i want to make the enemy fall down to die so to do that we're really not going to do a whole lot different it's essentially the same as dying i think but um is it is it the same as dying just without a launch velocity let me think about it for just a second it is so what i'm going to do is go back and i'm not going to add in a new script i'll just say die and we'll pass in a vector 3.0 so we just won't give it any um any velocity at all oh i'm missing using statements using unity engine statement that's why it wasn't generating it wasn't finding my enemy it wasn't finding things because the using statement was fun okay so um now i'm thinking hey maybe my door trap code is a little over complicated because now the only difference is what what the vector i'm passing in here is oh maybe i need to switch it back maybe i should um refactor them into a single class again but i'm thinking that it probably is going to make sense to have some inheritance here and have some separation perhaps not though we'll see though let's hit um play and see if this works so what i expect is that my enemies should walk into there if the trap triggers it should force it to animate and then they should fall down and die see if it's actually the case though oh so there's an issue the issue here is that if the trap is open the um enemies don't fall right like they they don't fall if they're in it at all so what we can do is change this to um let me see i guess it would have to be like an on oh wait you know what we also need to add make the body faulty here let's let's do something real quick i'm going to take a couple of these floor components disable them and i'm going to put a couple of these traps next to each other so we can see what's actually happening there and then we'll see that i think what i expect to happen is when an enemy is over one if it does the trigger it should actually start to fall oh interestingly it did not which is a little bit confusing why did it not fall so this trap door has it set up i'm gonna just watch as watch the enemies i expect the enemy count to go up once that guy walks into it okay and then if i hit trigger trap it hikes oh oh oh sorry i see the problem this is what happens when you go around changing classes so i swapped out the class i left that trap class in here the trap class is not abstract and it allows me to do it allows me to put it in here but when i toggle the trap and i actually trigger it it doesn't do anything now so we'll say um debug.log error no implementation so right now i'm doing nothing and not even warning myself about it so now i'll just log out a little error to say hey you're not doing anything dummy you should probably fix this so let's fix it real quick by swapping out the trap script so right here on my trap door i'm going to go assign the trap door script so i'll go to my prefabs folder find the um oh let's find the spike trap first let's assign the spike trap here so i'll take my trap script click on it go select it and just reassign the spike trap script instead we'll remove the trap and then we'll do the trapdoor as well so we're going to turn the trapdoor into a prefab go into the prefabs folder drag it down here make it an original prefab rename it to trap door with a space so that i know it's mine remove the trap script and add a trapdoor script or i think i named it door trap script there we go now i'm going to delete out my trap doors that i have already dragging this fresh one right here set its position up and let's get this positioned right duplicate duplicate duplicate and play now i expect to see that it should at least drop when the enemy is there but i think it's probably not going to fall because he is kinematic still on right oh no there we go he falls and he actually dies you can see the enemy is actually falling down and dying oh i think it's it kind of works so let's make it so that we can place these traps now the next step for that is going to be i guess just setting them up as a placeable object and then making it so that when we place the trap it turns off those tiles on the ground so let's delete out these trapdoors that are placed we'll go to the player it looks like we're only three likes away from 700 once we hit 700 i start getting set up to give away that code that everybody can go in and get the art package there's 14 different art assets um 14 different characters really cool stuff and whoever is quick with it we'll be able to get it for free like i like it it's a cool pack so okay we've got the spike trap assigned i'm going to assign the trap door as number three save that off i'm gonna hit play let's watch what happens real quick um oh you know what i might not even have to do much with uh with these positions now that i think about it so let me put down with some blocks real quick get these all positioned out so we have the ground actually working and then we'll hit play i'm gonna hit three and then drop down a trap so hit play three and drop down and trap and see it actually dropped one there it's really hard to see because it actually left that block there so let's actually make it so that the block does turn off so when i place that trap with our trap laser script there we go let's um make it so that the ground piece turns off and we'll do the giveaway thing in just a second once we finish this little trap let's get that going so when we spawn the trap what i want it to do is on this trap spawning um maybe just have it turn off its parent actually you know what i just have it turn off its parent collider and its parent renderer if it's that um the trap the door trap yeah hey let's do that so we'll say on enable um let's see bar parent equals transform dot parent and then we'll say well actually i would say transform.parent.getcomponent collider dot enabled equals false and then we'll do the same for the renderer um i think that's it right so let's try that that should just disable our render on enable i think that second happen let's see we go to three we right click we drop it out but i think um let's look right here the error that we're gonna get is that we're gonna spawn this we're gonna actually call our on enable before we set our parent so we need to do this a little bit later let's just do it um let's let's make a method let's say uh spawn actually no let's do this watch this we'll do an ie numerator return no i spell that right let's see we'll wait a frame and then do it so we'll wait until we've already assigned it we've moved it to our child and then we'll we'll do the uh toggling so hit three right click bam there we go so the reason that that worked just for everybody to clarify real quick is that if we add i enumerator here as our return type for start we can actually use it like a co-routine so i can do the yield return null statement here to wait one frame after our spawn happens so what happens is our object spawns code comes in here calls this and then later on we've set the parent we move the parent and then the next frame this resumes and it actually gets that parent object and turns those off so now our door trap turns the parent off nothing else does and our code doesn't have to be too smart about it the trap can really handle it um i think that kind of handles it right let's see i'm gonna go through and place a couple traps so got a spike trap i'm gonna place one of these traps place out a door trap maybe another door trap and a spike trap and run around knock some dudes off the edge if i can watch some guys fall all to their death or get launched up and stuff i think i've got um a good chunk of the functionality done so i'm gonna jump over to giving away that code in just a second so that everybody who's interested in it has a chance to grab it and then i'll probably start wrapping this up and then maybe do some more of these later maybe build on this and build out some levels and waves and different camera views and stuff right now we've got a lot of the different functionality of the traps placing the enemies um we just need like resources and health and stuff but those are really common and about the same for just about everything so if you're interested in getting the um the pack let me just make sure that you know how to get it so that everybody has an opportunity to grab it it's just this low poly monster pack right here um you can see it it's got a bunch of cool stuff in it um i don't know how else to explain it there's a lot of cool stuff like i said i got an extra code for it so i figured i'd give it away on the stream and see somebody else can grab it and use it for their stuff so i'm going to give out the code in just a little bit i'll put it on the screen so go ahead and get up the redemption page to redeem a unity code and then whoever types it in fastest i guess we'll we'll grab the thing [Music] so i'll give it a second i'm gonna um just pull up the uh see if i can pull up that that page for redeeming it too there's a there's a code or asset redemption page somewhere on there there's a page everybody go find the asset store redemption thing if you if you want to find it right now or if you want to put in the code and i'll give you the code in just a second so i'm going to give it like two minutes everybody go ahead and find it pull it up and have it ready so they can type it in and then i'll just do a quick countdown i'll flash it on the screen and somebody else can uh somebody can go in and grab it um well while everybody is doing that i'll just sit here and blab for another second about um other stuff looks like i had an error message what was that about an error message on probably a dead target is my guess yep target was dead and i wasn't checking so we'll say hey if the target is no then we're not ready to attack we'll return false there we go error message fixer error fix bug fix all right so um everybody go ahead and i guess just keep getting ready for that link hopefully everybody has got it figured out by now if you're ready to put it in just go ahead and say that you're ready in chat and once i see like a page of people say that they're ready in chat then we'll start and i'll just uh flash that sucker up there also um if you guys are interested in just these kinds of streams i think i might just kind of make them somewhat regular and just do them maybe weekly every saturday go through different game types just build out different stuff maybe expand out some of them across a couple different days in addition to just regular youtube videos plan on doing like some heavily edited ones of this stuff too but if people really like the live streams because i have a blast doing them and they seem like they're relatively popular um i'll keep doing them as well so just let me know make sure that you like subscribe and share and all that stuff though because if the streams don't get a lot of views then i just wish doing other stuff but so far seems like they're relatively popular and they're going pretty well looks like a lot of people are starting to say they're ready um let me get ready in just one second and start to get ready to flash up the code so again the code is just like one time thing you'll grab it and then um once you redeem it it was a little bit different like you redeem it and then all of the other packs become available in your thing so you have to go redeem them individually it was a little bit different confused me at first but note to whoever whoever wins it and gets it um that's how you use it it's really cool pack so um thanks again for the freebie and letting me get this thing out all right um i'm gonna drag it over in like three and oh drag it over in like 10 seconds and then everybody can start typing and see if they can get it and yeah congrats to whoever does ten nine eight seven six five four three two terrible countdown one all right there's the code whoever can grab it first uh congrats redeem it enjoy i hope you like it um i hope it's helpful and you can make some cool stuff with it um again thanks again everybody for coming out and i guess um i don't know if i had anything else to say i think i just kind of wanted to wrap it up there i just wanted to say thanks again everybody for for watching subscribing also the code um is going to be available down below on the link i'll go updated um in fact let's go update it right now while everybody goes through and congratulates whoever won or whoever got that code and uh we'll put it up in here so that everybody else can at least win with the source code for all this stuff and use it in their own project so let's see let's update the player script player is updated we'll take the flag script make sure that's up to actually i haven't touched the flag script so that's not going to change at all same with the spawner script hasn't changed but we've got a door trap here so we'll add that in or trap.cs and then we'll add in the bladetrap.cs i'm copying this so just adding these all in right here on this uh on this just so add in the blade trap and then we need to get the actual trap file updated so copy that whole thing again it's just control a by the way to copy or select a whole file and grab it um hopefully somebody won um oh cool look if somebody has claimed it awesome congrats hopefully you really like it and it's super useful for you um let's see oh i got to add in the trap script so add a trap paste it right here trap.cs and then i don't have the trap placer script so put that in trap placer in fact watches go up here copy double click copy paste in dot cs all right anything else um let me just make sure that the player script is updated i'm pretty sure it was but i want to make sure because it would suck it wasn't there's the player script and then um is there anything else oh the enemy let's double check the enemy is good too paste that in and we're good to go so now the whole gist should be updated with all of the code so you can go grab that as well and then um yeah have fun all right uh thanks again everybody for coming out again don't forget to like subscribe share and tell all your friends about this stuff and uh if you have other suggestions ideas recommendations for streams you want to see in the future just let me know drop a comment down below uh be happy to hear them i got quite a few good ideas coming up that people recommended this was just one of them that i really liked so we'll keep going with that and um that's all thanks again everybody bye have a great day really appreciate it and i think i'm out of stuff to say and start and run out of breath so bye you
Info
Channel: Jason Weimann
Views: 42,352
Rating: undefined out of 5
Keywords:
Id: lXNUP77-QPk
Channel Id: undefined
Length: 183min 40sec (11020 seconds)
Published: Sat Dec 05 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.