Building a 3D Game LIVE - Start to Finish

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right hello out there everybody i think everything is up and working and sounding good so um i guess i just kind of get started i guess i'll give a real quick introduction on what the plan was for today anybody who watches this later or just jumped in knows what's going on but the plan is to just build out a full 3d game um we won't build like call of duty but we'll build something that's relatively fun um simple and playable something where we can you know shoot things blow up enemies have stuff spawn keep track of score and all that uh it should be somewhat quick i don't know exactly how long it's gonna take like i said earlier in the chat i was just gonna keep going until um well until the game's done or until my wife just walks in here too many times and says it's time to end that um you need to come hang out so that would mean it's going pretty long though so i'm gonna get going and we'll just get started with a brand new project i'm gonna switch over to a new view so hopefully you can see everything i might need to move things around a little bit um just because you might not be able to see what i'm doing in fact as i look at this more i can see like hey i probably should uh at least move that little section of me blabbing down to here somewhere get it kind of out of the way i don't know maybe i can shrink it down a little bit too okay now i'll get going with me sitting right there in the middle so plan now was to build out a shooter something similar to what you saw in the screenshot so earlier i went through grabbed some art packs try to find something that i thought looked kind of cool and it would work for building out a game and i came across this tune apocalyptic city this robot pack and this robot soldier i think one of them was free and the others were a couple dollars so i just grabbed them and got them ready tried them out they seemed really cool so that's what i'm gonna go with i'm gonna start with this tune apocalyptic city we're just in the package manager by the way so anybody who's new to um unity or like just new to game development you can get to this window with window and then package manager and it just shows you the things that you've already bought in the asset store at least the view that i'm seeing right now shows the things that i bought in the asset store you can also see the built-in packages that are all available for all of the different kind of built-in unity systems but i'm looking at the package manager or the asset store stuff instead so here i'm pulling in my tune apocalyptic city i'm just going to import it and then i'm going to import in these other two packs so this will just grab the entire pack and pull it right into my project i bought these again on the asset store which is now in that unity or it's just in a web version only you can't access it through the unity editor anymore i don't know if that's permanent or if that's going to change and come back or what but right now you have to go buy them on the web and then import them like this so i'm going to import in the robot pack i think this one was actually relatively large this one might take a second let me look at the chat real quick um oh questions about the video so yeah the video will be available after offline and um when you start with this i started this one with a 3d project instead of urp but it could easily be urp you just have to maybe update the materials that's really easy to do it just wasn't something that i wanted to run through for everything that we pulled in right now especially since i probably won't make it look any better by switching over because i'm terrible at making things look really pretty um some other questions about that let's see is it going to be single player or network it'll be um it's not going to be networked but maybe it'll be multiplayer like local multiplayer i have some playstation controllers sitting around so maybe i'll use those or just um it might be single player i don't know see how it goes depends on if anybody's in here to play with me too it's multiplayer and i gotta play by myself that's not very fun so let's import in that last guy and then uh hopefully we'll be able to get started putting some things together and then people asking if it's gonna be available to play uh maybe maybe i'll just zip it up or do a webgl build or something to see if there are any issues with it um let's get going though let's go into scenes so i've imported it in oh no i want to go into the tune apocalyptic city and go into its scenes and there's an objects one i think this is just showing all the different props yeah and then the cover image one which was an actual level since i don't want to build a level and i'm terrible at level building i'm gonna just start with that actually let me turn this other light on real quick okay so let's do something with this level i i think i want to use this and just set up my player somewhere in here to be able to run around kind of as as a first drop but i want to look because i think this thing was full of cameras so up here in the hierarchy i'm just going to do a quick search for cameras oh yeah and i can see just typing cam there are four of them actually this might be a good way to pick a good shot let's see um that's definitely not one that could be okay that could be okay and that's not really good let's see i'm gonna just go into the scene view and kind of figure out where i want my camera to be and then just move the main camera there so i want to have a shot that's somewhat of like a crossing where there's stuff coming from a bunch of different directions i think maybe something kind of like this and then maybe have it so that the player has to get over to here i don't know i haven't figured out the exact gameplay we'll get it working though because like this aspect ratio is obviously not going to be normal if i go to um game and switch to standalone or like a 16x9 you can see more what the camera should actually look like but when you go into the stretched out modes and right now i've got it stretched out a little bit wider um it looks very strange there so i figured it'd probably be good to get it in there in fact what i'm going to do is go to game view and i'm just going to set up a 1920 by 1080. there we go just create one like that and hit okay and it'll just auto name it i'll set that as the resolution for the scene view okay so now i got my camera here i want to get rid of those other cameras first see i got the new one delete all of these one two and threes and we'll actually let's save this as a new scene i'll do file save as and we'll go to scenes and let's just call this level one like our first level all right um in level one we're gonna need a player so i think i was going to use the robot soldier for the player looks like there are quite a few different versions of it let's just zoom in and start dragging them out here and see what they look like okay okay there just looks like just different colors let's see um let's drag this oh there we go pivot on them is a little bit off but okay a white one a red one let's just bring them up here and just see green what do we got here camo camo are just looking at the names down here now blue and black i don't know if the black one looks cool yeah you know i'll just drop them all out here and then see which one kind of stands out and looks cool that'd be the easiest way to pick hopefully i didn't take two of the same ones that oh i did camo one wasn't there a camo too there it is get that guy out here too and just check and go to game view and see which one actually looks uh or stands out um oh the white one or the red one these other guys are too close together let's see let's stretch them out or move them out separate that guy okay um all right i'm leaning towards the white the red or the green i'm just gonna ask in chat and see what everybody thinks white red or the green one go ahead and pick and if there's just a bunch of somebody people saying one then i'll go with that one otherwise um we'll yeah i'll just pick one at random but definitely not the black one or these camo ones i don't want the dude to blend in because i mean it's their player i want them to be able to see him really well so give it a second i i already see a lot of people going with red red and white um okay it looks like red's got the most so i'll go with red and then maybe we'll add white as plate or two i'll get rid of green and then i'll just make like a red and a white player that seems good but those are the two popular ones i'll just do them both all right so to do this or to make it work we're gonna need um some sort of a script to move this player around so the guy can actually move so we'll go into the scripts folder that doesn't exist yet and well actually here we'll go to assets create a scripts folder and then we'll make a player script that'll allow our player to move around because right now if i just hit play you see like i think the guys will actually they're not even going to animate they don't have any animations on them see they just stand there and do absolutely nothing kind of boring so we'll right click hit create folder and it was down here in the project view by the way there right click and type in scripts i'm going to switch keyboards real quick i just remembered i have my super loud keyboard on so let me switch it up and grab my silent recording keyboard instead or silent or recording keyboard it's a lot quieter but it doesn't have the 10k it's kind of sad makes it hard i wish i had a full-size version that was just quiet um but also felt clicky all right so scripts now that i've got that typed out i'll hit enter and create the actual folder then a right click in the scripts folder create and choose c-sharp script we're going to make a new script for our player that'll just move it around so i'll type in the word player with a capital p and hit enter when you're making these by the way if you make a class generally it just just capitalize it and use pascal case where you capitalize each word it's the standard it's kind of the default and it's what i would highly recommend everybody use i hit enter and visual studio is going to open up now um for anybody asking you can use other editors you don't have to use um visual studio you can use writer or visual studio code i'm going to use visual studio just because it's what i have set up as the default right now for some tutorials but anything works um so yeah feel free to use whichever editor you want as you're going along there's looking at chat um jason please shout out about my channel unity 3d teacher um cool yeah go check it out i haven't seen it yet but i'm gonna do a quick look um after this i'll check it out and see but yeah anything that's learning about game dev go check them out for sure all right let's go into our player so what do we want to do for our player we want to well read our input and then move in whatever direction we push so reading input's pretty simple what we can do is just read the inputs horizontal and vertical axes this is just maps up to the controller inputs the up down left right or um wasd on a keyboard and to do that we'll read in a float for our horizontal and a float for our vertical i'm going to zoom in a bunch here though so everybody can see and then oh let's see i'm making sure everything's going on okay and check yeah my my uh thing's white i know it's it's a little bit bright i'm gonna zoom in a lot though so it'll be hopefully easy to read all right let's get going with uh reading in our input so first thing that we need to read in is the horizontal value and we can read that with float horizontal so just a floating point variable named horizontal and we'll assign it to input.getaxis and give it the name horizontal this part's case sensitive too the part right here if you get that wrong it's not going to work at all here you could mess up the casing of the name and as long as you mess it up in every spot or the spelling of the name as long as you mess it up in every spot it'll be fine here it's actually mapped to something in the project settings so it has to match exactly all right i'll copy this line the horizontal and paste it into a vertical and then i just have to replace this word with vertical so this is just giving me my horizontal and vertical inputs from a controller or wasd and then i can just move my character with a really simple call to like transform dot position plus equals or i can do transform.translate and move it in a direction so if i just well here first let's turn this into a vector so say vector three movement equals new vector three i'm gonna make it really obvious oh i just realized i'm like literally coding right underneath my head let me move my head way out of the way because it's uh super obnoxious just sitting there go way ahead and i'm gonna shrink me way way way down get nice and tiny all right there we go thank you everybody all right looking better so let's set up our movement again so horizontal um this is gonna be us moving on the left and right axis or the x-axis so this will be our horizontal that's the x and then for our y this would be going up and down and in a game like this and if i go back over to unity i don't want to go up and down i want to go kind of up down or forward back left and right really call it up down because i'm pushing up on the controller but it's really kind of back and forward so i want to go zero on the y so put in a zero there and then i need to put in my z value which will just be the vertical put in a semicolon this just give me a vector or a three-dimensional version of of my movement values that i can move my character with that then move the character i just say transform dot oh here what we'll do the easy way first position plus equals movement times time dot delta time that should move our character in the right direction and just jump over real quick hit play and uh oh actually we need to uh attach the script first uh let's attach it to the i'm gonna do the red guy first just attach the player script it's just because i clicked on him first and then hit play and let's see if it works hit play and then i go in and yep that's a right here b goes to the right w goes up that way and s goes that way all right so we're going to stop playing and um i want to well i guess first i'll just make it so you can move a little bit faster and then i want to fix the orientation because it's going a little bit weird like i want up to actually go up on my screen so that way when i'm running around it doesn't feel weird and like this dislocated first i'm going to add in a speed variable so a speed modifier and just do that by going oh actually here let's add it right here right after time dot delta time i'll do times underscore speed escape alt enter and generate a field for it and then i made a effect i knew it was going to do that do a serialized field replace the private keyword and then make this a float that way it shows up in the inspector and it's a variable that's just a number i'm gonna give it a default of one save it off and then go back in and then should get a variable now where we can adjust the speed a bit hit play and move around a little bit and he's slow and then crank this up like five and we move around and he's nice and quick all right so i'm gonna stop playing i'm gonna turn that back up to five because it resets when i stop playing if i change values while we're in play mode and then um well oh here let's just add it to the white guy too add it to the white character and he's got a lower speed so i see that they should both move at independent speeds right they go in the same direction but totally different speeds i mean maybe that's a gameplay mechanic i don't know that actually could be i don't know maybe some really terrible interesting weird gameplay mechanic all right all right um so let's get going through the next part uh what else do we need to do um oh i wanted to fix the orientation of the movement right now it's it's moving um up and down these axis so i hit w and it goes up and down that road and i want it to go up and down street instead so what we could do is change our transform call from transform.position to doing a transform. translate and then we give it our translation or our movement amount and then we can give it a relative space so right now it's moving or it's uh moving relative to um well actually right now we're moving it in world space because we're just setting the position but if i use translate it would move relative to its orientation but what i can do is choose another transform to move it relative to that thing's orientation so i'm going to make another object called direction and um that's it i'll generate a field for it generate a variable oh i don't know why it picked space oh because it wants world space or local space i change that transform and make that a serialized field um actually you know what i probably won't make that a serialized build because i think this is going to be like an object what i'm thinking here just for everybody following along and unsure if jason's completely crazy got this camera here let me drag it out of the scene section i've got the camera here and i'm just going to set up an object that matches this thing's uh rotation essentially going to match that thing's rotation and then i'm just going to use that to move my characters make it nice and easy so yeah let's just create a new game object actually let's create a cube and then i'm going to call this direction i'm going to make it really obvious anybody who's not really sure what the heck i'm doing here and then um let's see i want to set the direction of it to match this camera so i'm going to take this camera here i'm going to copy this component i'm going to paste the transform values here and then i'm just going to zero out the the z and then i'm just gonna turn it relative to uh this object right here i'll just turn off the renderer and the collider now we'll save that actually here watch if i stretch it out on um on the x there i like that better because now i can see like facing that way that's my up okay so i guess this is my up all right let's save and let's go back uh turn this back off and go back into the code if i go back into the code i just need to set up this direction object actually i'm just going to assign it right now in the references instead of setting up some code to grab it so i'll just assign it right here and i'll assign it oh actually if i don't assign it right there it would move separate so here let's try it out just hit play and make sure that this is working as i expect it to yep there we go so now i can just move that now obviously we could do the math to figure out the uh rotation and i could go through that all and explain it but i just kind of like doing it this way because it's a little bit neat because then at runtime if i get bored i can just do like hey look plus 90. and now suddenly my orientation and my controls are completely different and like the rotation of the world's nice and easy to adjust without me having to care anything about the camera i can you know kind of control it independently nice and easy oh it's kind of cool anyway we'll save that off and let's um let's continue on so yeah i probably should set up some code though to find this thing not have to go reference it so if i do this in multiple scenes or something it's not a mess but uh you get the idea hopefully all right so we got this these characters they're moving around um i don't know now i guess before i put in enemies to shoot at i gotta add some way to shoot right thinking like it'd be cool to put in uh some enemies to shoot but yeah without that yeah without shooting them like what are we gonna do and if somebody was asking about the uh the asset chunk of the asset packs it was this tune apocalyptic city um grabbed it from the asset store and then this robot pack and this robot soldiers those are the three that i was using right now um i i liked them all i think one of them was free and the other two were like 10 bucks or something so they were a great deal in fact i grabbed um maybe not on this account but i grabbed on some other accounts uh another robot pack and i was just planning on maybe like building out a bunch of stuff with them because i think they're really neat all right um so let's see let's go through this again we're gonna set up a way to shoot on our players so i want the player to like turn and face whatever oh let's think about it how do i want to control that i could do it with um thumbsticks like i could use the right thumbstick to control the direction that we're facing here or um use the mouse i think i'm gonna go with mouse just because if i do decide to like share this or anybody wants to follow along if they don't have two thumb sticks it'd be kind of crappy because then you can't copy it so i guess i'll go with like a mouse so move around with wasd and then use the mouse to um to aim and just kind of like auto fire i don't think we need to like click fire or anything i'm gonna set up like a uh an auto shooting system or a projectile launching system that just shoots out a bunch of bullets from these guys constantly and then if it hits stuff we'll deal with that after we'll set up some things to hit and continue on and we'll give them some goals and stuff after that but first let's make them shoot because that's a little bit more fun all right so if we go into the player script we could add it here but i'm thinking that setting up the i'm not sure i might want to set up the shooting system in a separate script i might want to do it in here i'm going to um air towards just adding it in a separate script and then maybe i'll mix it in and combine them or maybe i'll go keep it that route as a separate script i'm not really sure but i'm just going to start with a separate one i'm also going to delete all this stuff here the unused stuff that we have there so actually get rid of that and get rid of that right now this is really just kind of player movement um and i'm going to leave it at that and then let's make a player like a projectile shooter or projectile launcher or a weapon i i could just call it a gun i just call it a gun that's pretty simple public class gun mono behavior this would just be a gun component it's going to shoot in the update if it can shoot so let's add an update and i will move this to its own file in a second for anybody who's worried about it don't worry we're going to move it so what we do here is implement our update and i want to get rid of the private keyword just because i don't need it and then here we'll say if can shoot shoot that's pretty much the entire logic of our gun then we just need to implement whether or not we can shoot and the method for shooting so implementing can shoot is just hit alt enter and generate a field make this a well get rid of that private keyword again because done it and here we'll just return back whether or not the current time is greater than or equal to our next shooting time so say return time dot time greater than or equal to next shoot time then we'll generate the next shoot time field and get rid of the private keyword again so that's it this will just be true if it's greater than or next shoot time by default that'll be zero so it'd be we'll be able to shoot right away and then anytime um our time passes our next shoot time we'll be able to shoot again all right so how do we shoot well alt enter we generate a method for that and get rid of the private keyword again and then here um we could start by just instantiating a bullet just instantiate an object that flies forward we're obviously going to need to fix that up a bit later so let's just start that way so we'll say instantiate um call it bullet prefab and we'll do it at our um what do we want to do this don't do this at our transform position or a i think like a shooting point so i'll call this shoot point like this is going to be a position that's kind of outside on the tip of our character instead of in the middle of them um and then i wanted to say for the rotation we'll do oh shoot point dot position and then we'll do shoot point dot rotation for the uh direction so that's the plan create a bullet prefab in our shoot points position at the at its rotation don't have a shoot point yet so we'll generate it first let's just generate the bullet prefab oops nope authentic did the wrong thing hit alt enter and i want to do generate field there we go that's the one i hit generate method and it generated the wrong thing wasn't being careful enough i'm going to change this to game object and make it a serialized field oops not serializable serialize field and then i'm going to just copy this paste it we'll do transform oops not tracked transform and it's going to be the shoot point there we go so we'll spawn a bullet prefab at our shoot point in our shoot points direction all right last up we got to move this to its own file so select the gun alt enter and move to gun.cs jump back over to unity and in here i should be able to go add it to my two players so i'll add my gun to the red player so i'm just going to add it to that i'm going to disable the white player for a moment and just work on this red one for a second and then i want to set up the shoot point form because it this is going to be that transform where i want the bullets to come out of i need to go down here and find the gun and click on it so i've got the rifle here let's just um i'm going to grab the game view make it side by side hit play let's just watch where how the thing animates i want to see exactly where i want to set up the transform oh there is there's no animation that's right um okay let's just do it like this then i'll stop playing i'll right click on the um actually i think i want to do it i'm going to just make his body be the shoot point for now and then after i set up the so i get it working because i want to make sure that the animations are working and figure it out before i set it up and then have to go back through and modify it again so to set up his body as the shooting point or actually here let's do something funny let's make his uh make his head the shooting point shoot right from the top end of his head bullets will fly out of his head then i need a game object for our bullet prefab so i'm going to go back to the scene or i'm going to switch these side by side again or not side by side and then go in here and make a bullet so go to game object and go to 3d object and i'll just make a sphere for a bullet just give me a nice big bullet here i'm going to go over to his head ctrl shift f and snap it right on top so that's obviously way too big for a bullet so i hit e or no r sorry and scale that way down there we go get it to something that's i want it small but i don't want it so small that i can't see seems like an okay size that little dot right there i'll start with that um we'll turn we can make something that looks like a cooler bullet for now but now you just shoot out a bunch of shooting uh straight or straight straight uh white dots or something like kind of like a spray of bullets all right so the bullet well let's see where is it right here is named sphere so rename it to bullet and then we need to add a rigid body to it so that it can actually use the physics system and move and fly let me collapse these other things you can see the rigid body component so you got a rigid body there and we'll set the collision detection to continuous since i expect this thing to fly relatively fast i also probably don't want it to use gravity so i'm going to uncheck the use gravity box i think that's about it for that bullet setup i can't think of anything else we want other than maybe a bullet script that makes it fly and do stuff um and maybe damage things but other than that um nothing else on the setup so let's create a prefab out of it so i've got my assets folder here right click create folder and make a prefab i'll take the bullet and drop it right into the prefab folder and now i've got a bullet prefab all right last up let's go to the robot and assign this bullet to him and then if i hit play well we should see i i expect to see that yeah just nonstop bullets flying out everywhere obviously the reason for it go in here um we never make it so that can shoot would return false so the solution to this is to just set our next shoot time based on some sort of a delay because right now it's just going to shoot it's going to say hey can't shoot every frame it's going to say yes and then it's going to shoot so when we shoot copy this line here we paste right here we say next shoot time equals time dot time plus underscore delay and then add a field for delay then i'll add a serialized field for that or change it to a serialized field i mean and then give it like some default value i'm going to go with a 0.2 so that i'm doing that'd be five bullets a second if it was one it'd be one bullet a second point five would be two point one would be ten bullets a second here it's uh five bullets a second so if we go back into unity and hit play i should have a field for it now that shows up we go so i can modify the delay and i've got some bullets that uh oh they they spawn at my head but they don't go flying right that's why they're they start moving when they stack up and spawn on top of each other so starting to go um we got bullets spawning at least we got a couple more things to do with it but i want to take a quick drink and see what's going on in chat just see if there was anything um i missed that was super important it's hard for me my chat's way off to the side so it's a little hard for me to see in fact maybe i should just move that over and make it easier on the other side of the screen i can see it easier and i can tell what's going on there all right yeah if anybody's got any questions too um feel free to ask them and chat i'll try to keep an eye on them but hard for me to keep up again while i'm writing code and showing things at the same time taking one more drink oh a little bit thirsty there all the talking non-stop all right so let's get going back into uh spawning or making these bullets actually fly out because right now the bullets are they're spawning but they're just kind of sitting still so i want to change that up and make them so they fly out forward in the direction that i'm facing so stop playing and we'll go into our gun and in here we could we have a couple options here so we could either make it so that we access our rigid body on the bullet and make that kind of fly forward or something or i can um change it up and make a bullet script that moves the bullet along i'm trying to think of which one i want to do here i mean it's kind of up in the air um i think i just set the velocity here i think that makes the most sense because i'm thinking that my bullets probably don't need too much they really need anything yeah let's just do it here sorry i'm just kind of thinking or thinking in my head and trying to figure out what i want to do so i'm going to say bar bullet equals instantiate our bullet prefab and then we'll say bullet dot get component rigid body and if i i may end up just moving this around and there's chat in this and they're already about making a script i think i'm into making a script but i'm just going to start coding and then go from there i feel like sometimes i get stuck like just thinking and thinking too long and not writing code and then i'm trying to figure out what i want to do and i go back and forth and if i just write it then the solution becomes obvious i can kind of fall right into it and jump into it as long as i know what my options are so i want to get the rigid body component and then on it i want to set the um velocity to our i guess our forward direction um times some movement speed so our shoot speed so it would be like our um direction times move speed or uh let's call it a bullet speed generate a field for that and that's going to give me the wrong type we'll make it a float and make it a serialized field and now as i do that the more i write this in here i think like oh yeah this uh feels like this is on a prefab this should not be set here but maybe it does maybe it's a bolt launch speed and it makes sense and then direction so my direction i'm thinking is going to be a vector three and that's going to be something that goes like uh towards the mouse so remember i said i wanted to shoot towards the mouse so that we can control and like run around but aim towards the mouse i think that's what i'm going to do now i'll set up the direction to get the direction of the mouse and we'll launch it out in that direction by setting its velocity so go back into uh back into the code here and then let's see oh this needs to be an equals not a star so it's equal to the direction times the bullet speed so to get the direction we'll just read that in the update so just say underscore direction equals and then well we need the point where the mouse is and our player's transform point so we're going to need to um do a raycast so say if physics dot raycast and then we need to use the camera dot main screen point to ray obviously we should cache the camera.main because it uses the call to get to get it by the tag but um what's going on there um i missed i thought i saw something going on inside okay so we'll get the screen point to the right and the point that we want to use is the mouse's input position so our input mouse positions the input dot mouse position so if we're able to hit something by doing array into them into it with the mouse position and then we want to use a distance of i'm going to say math f dot infinity because i don't care and then we need uh well where's the hit info one ah oh gotta go back i always get these mixed up there's so many overload 16 of them i'm sure somebody remembers them all but it's certainly not me they need a second parameter here that's var um ah sorry not var it's out var it so this is our raycasted in fact i'll name it raycasted so if we get a hit from our ray it'll go into our raycast hit and we do it with an infinity distance check but if we actually hit something then we'll set the direction i'll take the direction here and the direction is going to be what would be our what is it our current our hit point minus our um current transform point or our shooting point really which i guess would be our shoot points position so here we'd use raycast hit dot point minus and we'll use our shoot point dot position now the one problem with this though is that our raycast hit might be up above or down below so i expect this to kind of shoot up above or down below let's save real quick and double check and make sure that i didn't reverse my math half the time i do these i end up reversing them just because i don't know it happens every time all right let's see it get in here and um oh let's see oh i'm not setting the velocity am i it's not something i'll see what's going on here we're getting the direction actually here let's see if the direction's not getting set and hit play and i'm going to go to debug mode and let's see what direction is direction is not setting okay what is going on here let's save we'll do a build we got a out to [Music] is the camera set up right is there wait let me check the errors nothing in the error log our main camera is set up as main camera um i'm gonna save let me make sure this is all saved ctrl shift b do a full build um if this doesn't work actually here let's just add a break point and debug so hit f5 we'll go into debug mode enable debugging new thing in the latest unity versions you gotta hit that first or pops up the second you start debugging all right we'll hit play and let's see why is the um oh oh i know what's happening there's no colliders so i'm trying to do a raycast here into the scene and i bet there are no colliders on any of the environment let's check it out we go down here let's go to the scene view let's click on the ground and yep just renderers that's the problem okay not an issue at all so uh we can fix that up i'll just select all of the ground pieces right here bam actually let's just do this i don't really care too much about anything in here performance wise being an issue so if i just search for mesh renderer and select them all and other than the player might be a little bit weird um i'm just going to add a mesh collider let's see if that worked if that's enough i may have to undo that for this player though i'm a little bit concerned that i may have uh just loaded him up with a bunch of colliders that i didn't want oh switch out of debug mode too okay no it didn't because it was skinned mesh renderer that's right all right we'll hit play and let's try that out a collider would definitely help i think all right we play oh now i'm hitting the break point so it stopped it didn't do anything because i actually hit my break point i'm getting a direction oh i know realize something else these bullets are shooting out really really fast like they're going in the right direction kind of and they are going um down it looks like maybe one of them bounced but um the other issue here let's see let's go back into that gun is that my direction isn't being normalized so my direction has a y component so it's going down it looks like because i'm shooting from my head that makes sense towards the ground but it also isn't normalized so it has the distance in it so let's just go look at it real quick i'll show you what i mean in fact if i slow down the uh the speed on this weapon put that to one might see it a little bit better so if i move it in close look at how the bullets kind of fall relatively slow and down to the ground if i move it out far they move faster but the reason for it if i go to debug mode is that this direction value here is the amount that i'm moving and looks at 23 on the z there and uh like 13 on the x values are really large that value needs to be normalized so the total magnitude goes down to one so to change that we just do this and do add some parentheses around here and do dot normalize what that does is really makes a new vector three out of these and then normalizes it i could also do vector3.normalize and pass that value in or i could do um here let's do it this way the other way call the normalize method on the vector that'll do it too all right so stop playing that'll fix it but i want to get rid of the um the y part too because i don't like having it go up and down i want to have it just shoot from my head or something um right onto there hopefully i didn't block too much with my camera there trying to keep uh trying to keep not showing anything down there in the bottom as for uh performance on mesh colliders they can be um i would say you don't want to have too many but in this case i i'm never gonna hit any kind of limit with this game so it's not a it's not a performance issue here if we had big giant meshes and lots of stuff going on sure here we don't so not a problem okay so let's get rid of the y component so the direction equals that and it's normalized here but i want to get rid of the y completely so after i normalize it i'll say direction equals new vector 3 and we'll give it direction dot x and then zero for the y and direction dot y z not y there we go i gotta get rid of it so now it's nice and flat save that off that should make it shoot out bullets nice and flat at the same speed no matter what direction double check that cool looks good and somebody was asking if the mouse position works with the playstation controllers definitely not to do playstation controllers uh we just need to read in another axis i think it's like comes in as like access four and five or five and six or something like that it comes in as some weird axes um so you just gotta figure out which one they are and it depends on the controller too different controllers will come in as a different one you have to set it up and then just read that and then you could aim in that direction and in that case instead of um doing your direction with this you just get the direction by setting it as the horizontal and verticals that you read from the controller all right so we got our direction here um what did i want to do next i lost lost my train of thought for a second so we're shooting out bullets and oh we want to oh i want to speed them up real quick first and then i want to make him face that direction i want to make him turn so he doesn't look ridiculous and then let's make him animate so actually let's make him turn and then we'll speed up the bullets because that's in the inspector all right so making him turn is relatively simple if we get a direction if we're facing somewhere we can just make his forward direction be that do that would just say transform.forward equals underscore direction and go back into unity how's it pretty tough right it's always funny to do those ones all right so save and i want to go in here and crank this bullet speed up for like a i'm going to go like a 13 and then it's nice and quick and hit play all right he's facing the right way and bullets shoot out of his head damn look at that i don't know what kind of weird uh alien dude shoots bullets out of his head but the idea all right i had to take drink all right so um now we got a couple things to do here one is set up some enemies to shoot and hit and the other is figure out a way to make these bullets stop spamming real quick so you guys want to do enemy setup and make a robot an enemy robot do an animation first or uh set up a quick pooling system for the bullets i'm going to wait and see whichever one gets the first couple answers in chat and then we'll go with that just why not i have a hard time picking which one to do either animating the player pooling or setting up an enemy and this also gives me a second to catch my breath take a drink and read the chat pulling bullet pulling bullet pulling okay okay lots on the pooling don't worry it's really quick for anybody who wanted to see animation or anything else we can set up pooling extremely quickly when we want to do it for um something like this so well first let's talk real quick about what pooling is so let me just hit play and show it real quick so i can explain it and then we'll make um some enemies and stuff so when you shoot out like a ton of bullets like this and you just keep keep shooting them out eventually they'll stack up forever i like you can see my bullets kind of going and flying and launching into stuff they'll last forever you can however destroy them so you can make it so they destroy themselves after a little while the problem that you're going to run into though is that if you keep creating and destroying things over and over and over eventually you start to hit performance problems so we're just going to make a really simple um actually yeah let's just make a really simple pulling system that reuses the bullets so i'm going to go into our gun and then when we shoot a bullet instead of instantiating a bullet i'm just going to make a method called like get bullet and then in there we'll pull up bullets so we'll say bullet equals get bullet and um let's see what do i want to do actually i don't need any of that i don't need any of the stuff so i'm going to cut all that put it on my clipboard hit alt enter and generate the method for it and then i want to get rid of that private keyword make this game object again and then we'll add the instantiate method here why did i add the instantiate method because um i might need to create a new bullet when we created a pooling system what we'll do is spawn up the objects and then whenever we're done with them we'll just disable them and then we can uh reuse them later on but if we don't have any available we have to create new ones so i'm going to say if pool dot count is equal to zero and i'll say add some braces and i'll say var bullet equals instantiate that and we'll return the bullet and then add in an ending brace now the pool doesn't exist and my pool is going to be a collection of these game objects or of these bullets i'm just going to use a cue because it's a really simple way to store a collection of things in an order and i feel like it makes sense to keep them in order that way i get to see them cycle through when they're being used so i'm going to create a pool i i'm just going to double click on it i'm going to type it um i'm going to type it right up here and then i'll move it up to the top of the second so put q just like that i got to hit escape and hit alt enter add the using system.collections.generic and then we add in the oops now that the type and we'll give it game object and i'll name it pool we'll assign it to a new queue of game objects and now we have this collection of well of game objects that we can grab things from there's nothing in it yet though so what we want to do now is if we had none we'll return back a new one if we have something in it though we'll just return back that one so in fact i'm going to change this up a little bit so i'll say if the count is greater than zero then return pool dot dq what that'll do is it'll take the first one from the queue or from the list if there is one if there isn't one then i'll do this code here and i'll just create a new one and return that in fact i could probably just say hey just return that new bullet whoops gotta get rid of the equals so that'll reuse them if i put them into the pool but i need to actually make it so that they go into the pool so i need to set up a way to i guess associate these bullets with our um with our gun so that when they get disabled they go back into here so let's do a um i want to do this i i like a million different ways i could create a pooling system here trying to decide on which one i want to go for um no i think i just trying to think this through and decide so i think what i'll do is create um i'll just assign something to them to tell them to re-add themselves to the pool i was thinking about just making an event fires off i feel like it's kind of over complicating it for something so simple so i think what i'll do here is say var bullet equals instantiate the bullet prefab and then i'm going to make that bullet script take a public class bullet and make it a mono behavior let's go way down here zoom in and then here what i want to do is um i want to make it so that when it gets when it collides with something it will disable itself and re-add itself back into the queue so i'll say on collision enter and then i'm going to get rid of the private keyword and for now i'm just going to assume collision with anything means i should disable myself so on collision enter i'll say gameobject.setactive to false and um i want to tell myself to go back into the queue so i'll say that hey go back into the guns queue or gun dot re-add to queue i don't have a gun reference yet so i'm gonna i guess i'll just start typing it out let's add in a gun here the gun underscore gun and then i'll say underscore gun dot um add to pool and we'll add in this we're gonna pass in our bullet object to re-add it to our gun i just need a way to assign our gun so say public void set gun and we'll say gun ah done and then here i'm gonna use um an expression body method just because i feel like it so i'll set it like this with it equals greater than underscore gun equals gun here we'll set it and um just assign it once i could of course just made this a public property or something too but i like making it a little bit more explicit that we're just setting this private thing it probably should only ever be set once it shouldn't ever get reassigned but i'm not adding in that extra logic so i'm kind of going halfway there all right we'll add it to the pool by generating the add to pool method and then oops i hit alt enter and enter did it generate yep go hit f12 to go to it and then here we just say pool dot enqueue and then we pass in our bullet now the pool right now is of type game object so i'm going to change it i'm going to make it be bullets only i'll take bullet here copy that and we'll paste it here paste it here paste it here i also need to paste it where my prefab is change all of these game object references to bullets i'm gonna zoom out real quick scroll down and i'm going to move this bullet to its own file who bullet to its own file all right so we've got a bullet being instantiated here um and it goes flying off and i think that's i don't actually oh no i need to set the gun right so say bullet dot set gun and we'll pass in this gun so now our gun is assigned to the bullet and then we'll return the bullet so whenever we create a bullet the first time we'll instantiate it we'll set its gun and return it whenever we get one again we'll pull it out of the queue leave it deactivated and then return it that seems like a bad idea so let's say a bullet or here let's get the bullet say var bullet equals that and i'll say bullet dot game object dot ah type that right set active to true and then return bullet all right i'm gonna get rid of that spacing there and then we'll make this an else just so that i can use the same variable name because i don't want to rename it and zoom in real quick so that's that's what we'll do essentially so we'll get a bullet by checking to see if there's one there if there is we'll grab it and set it to active and then return it otherwise we'll spawn it now the other thing that i'm doing though is like here we're getting the bullet we're setting the velocity but i also need to get it at the right position so i need to make sure that i move it to the right spot i don't really care about the rotation because it's a circle so i'll just say bullet.transform.position equals launch what did i call it um shootpoint 2.position i'm going to set the rotation to just even though i said i don't care about it because if i change this to a cylinder or an arrow or a magic dart or something else weird it's going to matter so i'll copy it paste it and just change this to rotation a lot easier for me to do it now than for me to remember why it doesn't work you know tomorrow or the next day all right let's move this pool up to the top i'll cut it get rid of those spaces go up to the top and put it right here and i'm gonna move this uh other private float down here too keep all the things nice and neat and organized and get rid of that extra using statement collapse out this class oh that was it there's nothing else in here for some reason i was thinking there was another class in here okay um i'm gonna change this to say public just so that everybody knows it means the same thing and i think i am done with that so we should have a working pooling system if i assign a bullet script to my bullet and reattach it i think let's try it out and see if i'm wrong i definitely could have missed something there we go to our bullet and we attach the bullet script and then go to overrides and right off the screen click apply all that'll update our prefab and go right into here and we need to reassign the bullet because it got changed excuse me it's because the type got changed by the way go to prefab drop that in save hit play and let's see if the magic works we should hit things and see our bullets um disappear and reappear so bullets kind of they hit things you see how they're getting disabled and re-enabled there they're getting reused and they're essentially pulled we've got a pooling system that auto grows for our our bullet shooting nice and simple we could of course build like a crazy generic system that does all kinds of stuff um goes even further but i don't think that there's a need for it yet so just keep going from here all right next up um let's see if we could do i don't know don't do and i think i want to do animation real quick and then an enemy so that he looks kind of cooler and then goes no let's add an enemy the enemies have animations already set up so my my character will look a little bit goofy but the dudes that i'm shooting at i think will look cool all right so if we go into our robot soldier oh the robot pack here let's see what do we got capsule robot a robot two and a robot marvin i don't know which one to do okay marvin is this weird looking little dude um let me see if i can pop this out and show everybody and then maybe we'll just do a quick uh says marvin dude as the first one or this cute robot dude that kind of looks like the dude back there and then whatever this capsule one is what's this guy look like this guy kind of looks like that too interesting so yeah um i don't know what do you guys want to do which one go ahead and pick uh to do the cute robot the capsule one or the marvin i guess yeah capsule two or marvin i don't know which one you guys want to do we'll set it up and make that our first uh first bad guy that will start blasting start shooting cute things right why not i'll take a drink while everybody decides which one you guys want to do by the way thanks everybody for um hanging out and watching it's a lot of fun surprised how many people are in here it's really cool oh and don't forget to hit the um like button and share and all that stuff if you haven't done that i appreciate it it's always good stuff i see a lot of marvin yeah a lot of marvin all right so i think we'll go with marvin which one was he marvin is okay this interesting little dude i'm gonna go with the blue one since our character right now is red or maybe i'll switch to a red and make the character white so well we can always add them all though they're really i think gonna be pretty easy to put in so let's see i got this uh marvin blue in here i'm gonna go to the game view oh yeah i could totally see him totally ready to kill that guy all right so we got marvin here let's see if he has some animation i'm going to go into his uh this thing had animations i could be wrong he meshes marvin prefabs nothing nothing nothing nothing okay um let's see if we got some animations let's see basic motions pack let's grab that i'm just going to import in the uh this basic motions free pack from the asset store um you can use you know on these humanoids you could use just about any animation so i'm just grabbing these to pull them in you could also go into uh miximo it's another great place for setting up animations but now i think i'll just use these ones so i'm going to take one of these animations go find them there we go thank you kevin for creating this pack and i'm just going to assign some of these animations to this character i think i'll take um actually what do i need here probably just a walk right i probably don't need a um an idol start them off just just walking so i'm going to make an animator controller for marvin and then we'll add a walk animation to him and see if we can get it working i'm going to go in right click create a new folder and name it animation then in the animation folder we'll right click and create a new animator controller and name it marvin and then we'll hit enter and open that animator controller and if you hold ctrl and use the mouse wheel you can go in and out and then you can hold is alt and left click to drag around you know always get them mixed up but yeah control zoom um or actually no control just just mouse wheel zoom i guess and then alt to drag around all right so let's see let's update this or create this um animator controller make it actually do something in the wrong button hit the windows key there okay so i'm going to go into my animations and i'm just going to take a walk animation and drop it right in here this has a walk and then there's a walk with root motion i'm going to delete the root motion version and just leave that in here we'll go to our scene view go to marvin and assign this animator controller to him and let's hit there we go he's animating playing the walking animation pretty simple right it's it's really cool like how amazing like easy it is that you don't have to have an animator go in and animate things for you anymore and just kind of have them retarget and work kind of blows my mind all right so we got a character now that will walk and be able to i guess walk towards the the bad guy right i'm going to set up a way to kill him real quick and then i'll make him walk towards our player is that the bad guy i guess that makes us the bad guy but whatever let's uh set up a way to kill him and then uh and then make him walk to us so let's see to kill him we're gonna need a collider first so i'm gonna add a capsule collider capsule collider is pretty common for moving characters too just because it makes it easy for them to to move around um and get over things so make it uh well the center this guy is really short so making it two meters high oh i'm just gonna go with two meters high and one there doesn't really matter that just colliders up above because we can't aim up and down so i think it's probably better that way i'll just keep it two and one i think i'm gonna stick with that for all of the capsule gliders here um i'll save but i also need a nav mesh agent because i want this dude to be able to walk towards my player i'm gonna add a nav mesh agent to him and then um i want to add in script so that we can move the guy so let's go into our scripts folder and let's add an enemy script i'll go to create c-sharp script and choose enemy there we go and then let's just sign it to mr marvin here stick enemy and drop it right on all right save all that off and now i've got a marvin enemy that's um somewhat ready to go it's not like i should be able to shoot it and the bullets will bounce off of it that's about it oh um thank you mister marty all right it's really hard to see it way over there um see so i'm shooting and my bullets aren't hitting so here's what i'm gonna do i'm gonna pause or not really pause i click over to the edge go into the scene view and look here and you can see the reason that it's not hitting is just because i'm shooting from too high so the bullets are going over this guy's head if i go expand out the capsule collider i can't actually hit him it's just because the shooting point is too high there so let's set up an animation real quick on this guy too so that he can shoot and um have his gun in the right spot so i'm gonna go back to the animation folder right click hit create and we'll create another animator controller name it player and then i'm gonna assign it to the player so take this robot guy drop it in on his as his animator double click on it and then go into that animations folder again and here i'm thinking it's i don't know exactly i don't know if there's an animation in here that's gonna work perfect for it so let's try run i may have to go somewhere else and grab an animation where he's kind of standing there running with a gun or something um so go into the scene view what's it play just see what he does in that animation real quick okay well it doesn't really help me but i'm just gonna shoot from uh here let's pause and let's select the gun here but what i think i want to do is just shoot from this point here at the end of the gun so i'm just gonna figure out where that is and shoot from that so it'll either be down here or kind of up in the middle of the air not going to be a big deal because once i get the animation working so he's holding it right there at the waist actually let's just go get an animation where he's holding it at the waist let's find a shooting animation so i'm going to go to the asset store all right here let's just look for shooting hit asset store no real reason to wait shooting animation character at shooting let's see let's see if there's a free one first nope character shooting character shooting okay now here let's see if we can grab one on mixamo give me one second i'm gonna pull it up on another tab and i'll drag it over if anybody who hasn't seen that miximo by the way it's a now free site i don't know who made it initially but it was eventually bought by adobe and then i think they were going to do something with it and they decided to just open source it or not open source but make it free and available so with it um you can upload a character so here we go upload i need to find this and get it in the right spot robot soldier here okay and then i will um drag it over here and get an idea of what it looks like so here's here's the way it works so you upload a character and then you can go through the animations here and you can just pick animations and then download them to match i'm going to take like a shoot run or just search right here for shooting and running and i should be able to find like a uh some sort of a shooting pack i think something like this might work so if i click on it i can actually preview it in here um let's do in place i don't want him actually moving and um i mean it's not perfect let's see i can adjust it a little bit and there we go i think it looks a little bit better and um and then i just download it so i just hit download and i'll choose fbx for unity that's the one thing people miss a lot here's fbx for unity i don't need the skin the skin is like the textures and stuff i don't need any of that and then i can just hit download so i'm going to click over here i'm just going to move it off here download it and put it into a folder real quick i'll drop it into our animation folder here to get to there i'm just going to go to animation right click hit show in explorer find my folder and then i'm going to just paste my save right into it save and it should just appear here in a second so now when i click in there we go so all i did there was just copy that save that file into this folder essentially all right let's go back into unity or again not back in you know let's go into um assigning this animation to him i've got the animation set up let's go to the animator i'm going to delete this motion here this default actually let's not delete it let's rename it to run click on it name it run and then just change out the motion so here it has that motion field i can just assign the other motion here the shoot rifle and drag that in save hit play and i should see him now running and running with his shooting oh nope he's not let's see let's go check this out so the shoot rifle animation should be targeting our robot soldier oh let's go to the rig and let's choose um not no avatar let's choose copy from other avatar and i need to choose my robot soldier there we go so i i picked that off screen so here let me drag that over so i picked the robot soldier avatar the reason for that by the way if i click on the robot soldier let me just go show you real quick so the robot soldier object if i pick his mesh and select it you'll see that his rig is set to humanoid and it creates an avatar and when i'm remapping or copying an animation and assigning an animation to him i need to actually set it to humanoid and i need to map it to that avatar definition so now if i hit play i didn't miss anything else he should uh start there we go now he's animating and shooting there we go look at that pretty cool um not exactly what i want because he's a little bit offset but he is kind of shooting in the right direction um he's not constantly animating though he animated once too so that's kind of messed up so let's fix that real quick and then let's fix the offset and assign the stupid bullet code or assign the the point to it all right so go to the run animation i'm just going to double click and not double click on it i'm going to go find it down here and then go to the animation tab and we just need to make this loop so i'll check the loop box and if i hit play you can see that now it's looping here and by the way if you look here you can see that little offset in his uh in his body so one option i have if i can just kind of not that one where is it at there's a rotation here wait stop playing so one thing i could do is that and i think i might just do that just rotate the orientation of his body his feet are gonna look a little bit weird but i want his gun kind of aimed towards his forward when his gun kind of aimed towards that blue arrow i think i'm just going to turn it negative 30 degrees there and apply now if i go hit play i also hit loop time there's now i expect it to be he's aimed more in the direction that my bullets are flying or more in the direction that i'm i'm shooting towards at least and um yeah i think it's not perfect but it's definitely looking a little bit better am i able to hit that thing at least almost oh yeah that's right i haven't set up my shoot point so let's fix the shooting point now all that set up and i still haven't done the shooting point so creating a shooting point pretty simple i'm going to right click on my rifle i'm going to hit create empty i'm going to rename this to shoot point and i don't actually notice that if i make it a child of my rifle let's see if i make it a child of my rifle and i put it right out here right at the point where i would want it to show up and then let's add a icon to it let's hit play and see what happens go into the scene view and look at the shooting point it's nowhere near there because it actually just stays kind of at that base area it doesn't follow the animation the part that animates is this part underneath the hips it's the actual rig so what i need to do is find the part under here that's matched up with that and if i look at it and imagine just looking at the body hierarchy it's going to be somewhere on the right under the right shoulder probably makes sense because it's going to be down here and attached to that hand so you just keep expanding and i can even hold alt and just click and expand all the way and then just drag down here and find like the hand here i can find the area of the hand sometimes let's see where's the one for the uh rifle sometimes there's oh wait that's odd interesting oh yeah sometimes there's a separate um gun one here too i was getting myself a little bit mixed up there but all i need to do really is take my shooting point make it a child of the hand here and then let's just reset the position and then just kind of move it out here somewhere like that so that it's kind of out in the front but attached to my hand and it's going to rotate with my hand another option that i have by the way if i don't want to make it really associated with my gun is to just kind of spawn it right out in front of the character but if i really want it to line up with the gun lining it up with that hand is probably going to be the best option i don't see a bone for the actual gun in here so i'm going to stop playing i'm going to take the shoot point make it just a child of that hand and then i'm just going to hit play again now that it's a child of that hand and it's in that same position we go into the scene view expect to see it right around that same position now i could of course line it up perfectly and fix it but i don't care enough to to really get it perfect and as i'm looking at it i'm thinking that it's it's still a little bit high so what i'm probably going to do is pause and pull it down to somewhere around here so that it's actually a little bit below the gun let's try that and see if that actually hits the enemy let's hit him still a little bit off hold on let me get this bullet shot right what happens when you don't pre-do your stuff oh yeah that's still way too high so oh sorry i'm being stupid i didn't assign the shoot point let's go select the robot and let's go assign the shoot point i'm still shooting out of the head bam now it hits okay stop that let me go assign the shoot point while we're not running there we go and save and and now i think that it's probably gonna be fine it might be a little bit too high i'll double check real quick to see if it's um if it's gonna work or not yep it looks like it's hitting but i think i'm gonna move it down just a tiny bit too so here i'll hit play i'm going to let it go and here's here's how i move it when it's kind of animating so if i'm in here and i just want to drop that shooting point down a little bit i'll select the shoot point and just take that and drag it down just a little that it's at the height that i want and then copy the transform component stop playing right click and paste the value now it's dropped down to that newer lower value all right so now i got him shooting um and i think that yeah that's right so he's shooting the enemy should be able to start taking hit soon but i don't think there's any reason to kill him yet so let's make him run after me and then i'll make it so i can actually kill the guy all right so we'll set up an enemy let's go over to the enemy just hitting left a bunch of times till everything collapses we'll go select marvin and we added a nav mesh agent to him but i haven't actually set up any navigation so there's no way for him to go to the player watch i'll show you what i mean by that too i go into my enemy and i just go into the start method cause right now there's nothing in here say in start i want to say bar player equals find object type player i'll just find the only player that's out there right now it'll say get component nav mesh agent and get that typed out right now i got to hit alt enter and find it so i hit using unityengine.ai so get the nav mesh agent and we'll set the destination to our players point her player.transform.position now what this would do is ideally make our character move to the player once right at the start it would say hey move to him right then now if i wanted to happen every frame i could just take this cut it and paste it in an update i should probably cache this and make it not slow but i'm not going to do it yet i'm just going to leave it because it's not going to make any difference there's no reason to optimize it just yet so we'll hit play and we'll watch the error a real reason to optimize seeing an error message right so we go over here and look at these uh oh we got a bunch of different so these are um messages about oh me adding colliders whoops don't worry about those the one that we care about is this not that where's the message i care about this one right here set destination the one that we're getting thousands of let's hit clear now you'll see it this one's one i care about yeah so set destination can only be called on an active agent that has been placed on a nav mesh what that means is i need to bake my nav mesh so the character can move and know where to navigate i'll go to window and i believe it's under ai now and then navigation which brings up the navigation window go to bake and since i've created colliders i should just be able to hit bake and then sit back for half a second and watch it bake let's see or not it's not working okay let's clear the errors real quick and um hit bake again oh yeah why is it not interesting i'm not sure why it's not baking for me now okay hmm oh i do know i know it is baking um yeah another thing again happens all the time so for an object to be counted in navigation watch this you gotta go to object there's a navigation static option and because this environment is set up to be optimized just for rendering it's not checked and it's not going to be checked on most things so what i need to do go select my props and my road and all of these pieces i'm just going to select the whole little area of all of them and then we'll go to inspector and i'm going to go click on this stat actually here if i go to navigation let's see i can't see it in an object but if i go to the inspector and if i just drag this over let's see drag this over here you can see the static button and i can click on it and there's a navigation static option i'm just going to click on that and hit yes change children so that it updates everything including all of its children it's basically gonna set that navigation static option now if i go to the navigation tab go to bake and hit bake there we go i got my one second delay and a big giant blue area so all that blue area means is those are spots where the navigation works or where navigation is happening sometimes it kind of cuts through things and you'll see that it kind of cuts through this mesh right here there is navigation across there so it's kind of underneath and setting up perfect navigation meshes takes a little bit of work and some effort and you have to set up your colliders right to make it work perfect but this is going to be perfect enough it's going to work so if i hit play i should see that the character moves there there we go yep and he moves right to me but if i move away yep he follows me looking good so now he's chasing after me and i just want to make him dead so we'll stop playing and um let's go fix this uh rigid body on the part of this what is it the mesh collider on the rigid body of the bullet i think what happened is it got yeah it got a mesh collider and it needs a sphere glider oh actually i think it got a mesh collider because i added it when i added it to everything so i'm going to remove the mesh collider from the bullet and then go to overrides and apply all which is off screen but hopefully that gets rid of that message and stop spamming the console there because i think that's kind of obnoxious there we go now it's just the uh the editor error thing that something broke in the editor that's been happening forever all right so we'll go into our i guess our enemy now and let's make him die when he gets hit with a bullet right or should we make the bullet kill the enemy i'm thinking i want to do that so when the bullet hits the enemy if it hits an enemy i'll say hey enemy take damage and then the enemy can either blow up or um yeah or just maybe reduce its health depending on what kind of enemy it is right so that way the enemies can be somewhat independent they'll just implement it however they want so let's say um r enemy equals collision dot collider dot get component enemy so we'll get the enemy component of the thing we hit and then if there is one so if the enemy is not no if not if enabled if enemy is not equal to null it'll say enemy dot take damage so that'll make it take some damage from the bullet i could make it take a variable amount but i don't have anything where i'm going to change it to like a new number so i think i'll just um make it not take a variable for now but i could always like make different power bullets or something make pass that in or something i think i won't i'm going to replace that with public just make it a little more obvious and then here on an enemy when they take damage let's um start by just saying game object that set active to false super simple i'll shoot them once it'll turn off should work really really simple then we can expand it out a little bit maybe play some particles and bam okay he disappeared pretty simple all right so let's um well let's make him we're going to do you want to make him plain explosion disable and then spawn a bunch of them and make them chase after me or something so i'm going to go into package manager and let's get any particle effects in here remember if i've downloaded any recently um let's just search for explosion cartoon effects epic tune effects these probably all have some a war effects that's not the one i wanted oh maybe i want to go with i'm going to try cartoon effects i always like these ones they're always cool so why not just try out the free ones these uh spell ones and all those they're they're really cool but they're like bigger um they're more like they're not this kind of game i guess like i don't think that they would fit really well into this or maybe casual uh sound effects oh yeah i'm gonna try cartoon effects one first see if there's like just a good little i want like a sparky explosion where something blows up oh hi um i just saw the super chat hello out there thank you very much let's go cool all right let's get going with the import and trying to keep an eye and see the chats there but again it's kind of hard seeing it all while i'm coding if anybody's got any big questions let me know but i might miss them hopefully not all right we're almost done importing this i'm thinking i just want to grab like some kind of a spark explosion or something so we'll play the explosion have this guy animate dying and then make a bunch of them come chase after me that way we can kill him and then we can start getting some points or something for killing all right so we got marvin here let's go into that uh asset pack folder jmo assets for the cartoon effects and let's see what we got here so we have hits explosions um let's try explosion what's this one look like oh it's okay fireworks one might work um let's see explosions here nope that's definitely not gonna work what about the electric one sparks pull this up restart actually this might be a good um hit impact maybe i'll do that i'll make it so they can take a couple hits and i'll make them play this spark each time and then when they die they'll play another one i'm gonna do that so i'm going to use this spark as the hit impact so i'm actually just going to make a new prefab out of it i'm going to take this prefab here this particle effect drag it into prefabs and i'm going to make it an original prefab and i'm going to call this um robot impact effect i just call it robot impact i already know it's an effect it's a particle effect all right so i've got my particle effect there um i think i'll leave the auto destroy on for now that's just a built-in thing that's in there and then i'll make it spawn on him whenever he takes a hit so let's go to enemy when he takes a hit i opened up another version of visual studio i hate when it does that okay so drag this around and get it to the right size again all right so when we take a hit when we take damage we'll set ourselves active but let's also spawn our prefab say instantiate hit prefab at our transform position and our transform rotation so now i just generate a field for my hit prefab generate that oh instantiate i generated an instantiate so i hit alt enter and i hit generate variable and generate field go hit f12 to go to that prefab and just make it a game object and then replace private with serialized field so we can set it up in the inspector get rid of the start and that comment there all of those using statements save and zoom out so that's the entire enemy script so now we gotta hit prefab we'll instantiate it and then we'll set ourselves to inactive seems cool all right we'll go back to unity in unity i'm gonna assign the hit prefab so we'll go find our prefab folder go to marvin and we'll just assign the robot impact save and now if i do it no well now we should uh play that once and blow up right bam he played it once in blue up now let's give him a little bit of health i'm going to give him like 10 hit points or let's give him like three hit points say serialize field end health equals three give me like a default and then i'll add a private variable and into current health and we'll leave that at the default value then when it gets enabled so let's say on enable we'll say current health equals health get rid of the private keywords this is like a resetting health so that way if we enable and disable him his health will reset so if we put him into a pool or something he can reset and reinitialize and then in the take damage we'll just say current health minus minus and instantiate the hit prefab and then we'll only do the destroy here let's scroll that up say if current health is less than or equal to zero then set actively false no you have to hit it however many times it has for health and then we'll um turn it off after that so it'll spark spark spark and then disappear alright we'll play try this again start shooting at marvin bam three sparks and he's gone all right let's make him um explode now i didn't actually finish picking an explosion particle so i'm gonna do that now um while we pick an explosion particle if you don't mind hitting the like and share button that'd be cool but um i'm gonna keep looking for a particle so let's see we got a oh that's definitely not going to work what about that spark nope and then let's see if there's something in four that might work sparks explosion oh that i think that's the one i was using um so i think the only cool or the only workable explosions were in the cfx prefab one pack at least in the free one i could grab the other packs but um i don't want to switch asset store accounts to get them out all right so it's gonna be i think i'll take this one now this boom one so the cfx be smoke plus deck i'll take that i'm going to make it into a prefab or another prefab in here i'm going to call this robot explosion it'll be an original prefab or rename it to robot explosion now you can just work with those existing prefabs by the way i find that like uh then i end up modifying them changing them i reimport them and it breaks stuff and i get confused over which ones i'm using a lot easier to just kind of copy them into a new prefab and use it that way all right go to marvin and we'll assign the explosion to him oh i don't have an explosion field so we'll open up the enemy we'll add in or a serialized field here and we'll call this explosion prefab and then we'll spawn it um i guess uh when our health gets to zero so we'll say hey if the health is less than zero then let's copy the instantiate line here and paste in explosion prefab instead now we'll spawn the explosion if we're blowing up we'll spawn the hit no matter what so we'll get a spark and an explosion i think that's okay i could make this like an elsa statement though so that i only spawn the hit when um when i don't blow it if i wanted to but i don't care i want to see more more particles and more explosion oh hey thanks for the super chat jason oh oh oh okay so now you see that it's not blowing up look at that i'm spawning or hitting it and nothing's happening no explosions also look at his feet that's where the sparks are happening the sparks aren't happening where i'm hitting him they're happening at his feet so let's stop playing and let's fix both of those things first issue well the first issue is that it's giving an error because the explosion prefab hasn't been assigned so just go assign the explosion i go into my prefab folder and just drag it over here that should fix it hit save should be able to see them blow up now but i still expect that it's going to be parts of the feet yep and a boom so let's make it happen right at the body or um somewhere else it could be where we do the impact or at the body so to do that we just need to pick a new position so it's a transform position i could do the impact position or the body's like center position i'm thinking i want to do the impact position though so to do that i'm going to need a point of impact so i'll need a vector 3 impact point just like that i'll need to pass that into my take damage and i'll just use that right here and right here now my take damage method is going to have an error if i hit shift f12 though i can go to the part where i have it or if i let's say control shift p to the error it says build failed um come on references control shift b build failed is it going to let me go to the air i don't know why it's not showing me the error message uh but the problem here is that our take damage let's go to it doesn't pass in that parameter so i need to pass in the point where we actually hit to do that it's really really simple just grab it off the collision do collision dot contacts dot zero or at zero so contacts is an array of all of the points that hit it's almost always one point but sometimes it can be more than one we usually i've never cared about more than one so we care about contacts zero dot point that'll be the position of the first point of contact that we have now again it's almost always going to be one point sometimes it'll be two if we like a flat thing on a flat thing we could end up with two or two points on a pokey thing that exactly end in the same frame um that could happen but generally with the bullet we're gonna get one point so we'll take damage at that point all right let's play if we get our particles to show up at the right spot and um yeah no error bam look at that so he blows up and i think it kind of works all right i'm gonna save real quick i'm gonna take a drink and watch chat for a second so if anybody's got any questions um anything you want to ask so far about what we're doing just feel free to ask away i'm gonna just keep going with this though and then we'll keep building and adding in some more features and functionality we're going to do robot spawning so you can get a whole bunch of them next and make a whole bunch of enemies appear make a bunch of prefabs of them some variety and then some scoring and stuff but um yeah if anybody's got chat anybody wants to just ask any questions or anything um now's a good time to ask while i take a real quick second to take a drink and just see what everybody's up to cool right had a blast let's see presently putting so many games now all right sorry i'm just kind of reading through chat reading out loud oh yeah i do have an error what's the error here you mentioned that i still haven't right there it's this um i don't know what it's from it's something with the layout the unity layout stuff it's not actually a um an issue in the code you'll get this in an empty project a lot of time too yeah the video will still be available after you'll be able to go back through and check out what check it out the whole thing um let's see any other questions come in oh okay i might also get going in just another second a couple more drinks and refreshing yeah if everybody doesn't mind hitting the like button or sharing this just drop it on um facebook or wherever else you like to share stuff um instagram or whatever that would be awesome really appreciate it but hey not a big deal either way all right so add blasters okay interesting what would the blasters do will you prevent robot enemies from walking inside you yeah i mean we'll have to make robot enemies kill us i think that's playing right so uh we'll blow up a bunch of them first because there's no fun in just dying when you can't kill the enemies but we'll make so we can kill the enemies and then add in some threats to make us die and maybe like a target or something to go to so um let's uh i guess let's get going also if anybody's curious that we are using i think the latest version actually there might be a one version newer of unity that's out now but um and i might have missed that but yeah just working in the latest 2020 right now so all right let's go um enemy so we'll set up some more enemies and let's make them uh spawn and start running at me because right now i can kind of turn and shoot and blast them and stuff and that's cool and all but there's only one guy so my options here are pretty simple i could just make a bunch of them just duplicate them and duplicate duplicate duplicate duplicate duplicate duplicate duplicate and then hit play and then have like this little boring thing well i mean i guess it's actually kind of cool having them there as a wave like that spawned is kind of neat it gives me an idea of how i want to spawn them but um i don't want to just like set all of these guys up and make them like really far away so they walk in at a certain time or something like that we want to set up some sort of an actual spawning system that like instantiates these dudes at runtime or re-enables and pulls them so i'm going to delete all of these marvin blues and just leave my one my one little marvin and i'm gonna check his overrides yeah he has a couple new things so i'm gonna hit apply all it's just off screen but i'm hitting apply all and get rid of those so there's no overrides left the prefab is updated and then i'm going to make a spawner so a spawner script is really really simple if you haven't made one before be prepared to see just how simple and easy they are to make so right click create c sharp script make a spawner name spawner hit enter and open that script of oh look another instance of visual studio i don't know why it's doing that it's really strange it keeps opening up a new one every time odd but whatever all right so let's see our spawner what do we want to do here well we want to instantiate an npc whenever it's time to instantiate the npc probably want to pick an npc from a random list of them and then spawn it at some random like sub point so pretty simple code to write we'll go into our update we'll get rid of that start and in our update we'll say if should should spawn how to get my casing right then spawn and that's essentially the logic to our spawner right if we should spawn then we want to do a spawning action so say alt enter and generate a method for should spawn and here get rid of that private keyword again and we'll just change our should spawn implementation too just like our shoot let's go look at the shoot anybody who was guessing how i'm gonna do this i'm gonna do it exactly like this just like our can shoot our should spawn we'll do something like where we check the time and see if it's greater than our next spawn time so i'll paste it in and instead of next shoot time we'll say next spawn time uh benefit to this by the way is that now i'm reusing a very simple pattern in my code and anybody who looks at it they see like should shoot and should spawn they're going to understand how they work they're not going to have to figure it out i'm going to have to go like hey this one works totally different by counting up and this one works totally different by doing it by using a time stamp or whatever whatever way you decide to do timers i'd recommend just kind of picking that and um sticking with it if it makes sense for that timer and just kind of picking one or two ways that you like to do them don't mix it up and do them different everywhere because then people just get confused all right so let's create a next spawn time generate a field and get rid of the private keyword so then spawning alt enter generate a method and you might have guessed the first thing we need to do is set our spawn time so copy next spawn time set it to our time.time plus some delay so say underscore delay and hit escape and generate that field again replace this with a serialized field and give it a default of i'm gonna give it like two seconds it'll spawn every two seconds all right so right now that doesn't actually spawn it just sets our next spawn time we need to make it instantiate a prefab so say bar enemy equals instantiate um let's say and actually let's just call it prefab because it doesn't need to be an enemy in fact let's say a var instance equals instantiate prefab in fact you know i don't even know if i need an instance of it i'll just get the i'll instantiate the prefab at our transform position and use our transforms rotation that's all we really need i don't think i need to do anything else so i'll create a prefab so i'll copy this and i'm going to go up here and make a serialized field and it'll be a game object of type or named prefab get rid of these using statements zoom out a little bit and that's the whole script so spawner checks to see if we should spawn an update if we should we spawn we spawn by setting our next spawn time to our current time plus the delay which is defaulted to and then instantiate the prefab at our current point now i need to add in some variation some randomization and some other things but first let's just make sure this part works go back into unity we'll go create a spawner object so i'm going to go to game object i'm going to make a cube here so my game object 3d object cube just so i can see a little visualization of the thing here i'll place it maybe over here rename it to spawner i'm gonna uncheck the box collider i don't want it to have a collider because they don't want me npc walking into it and then hit type in spawner and add that spawner component now i need to create or assign my prefab here so if i hit this i can see i have a whole ton of options not the best way to find it i can go to my prefabs folder and oh i haven't actually made my robot into its own prefab so i'm going to take marvin blue here drag him into prefabs folder make him an original prefab again because right now i'm using the prefab from that asset pack i don't want to do that i want to make him his own prefab and i'll rename him to marvin blue but i'm going to get rid of the underscore there we go i'll just name him uh actually yeah i'll just name marvin blue with no underscore i think that that's fine now i'll assign him to the spawner so go to spawner and dragon marvin blue hit save and play and let's see if it works all right so now we've got marvin's and marvin's are spawning like that i've got a wall or an army of marvin's coming and they're actually a little bit hard to kill i don't know if i can keep up with these marvins all right so let's stop playing and randomize the spawn position first before i randomize the npcs i have to make a couple more it's a lot easier to randomize the spawn position so we'll start with that i'll go to my spawner here and i'm going to right click on it and i'm going to create an empty child or actually let's create a cube that's a child of it and then i'm going to move it over here to the right in fact here i'm going to hit control z another grid snapping mode since i'm in global and just move it like a full meter over to the right and duplicate move another one over here and another one over here actually i'm going to turn grid snapping off that's not very helpful in here so i've got a couple different points here i'm going to duplicate again and move this one over here maybe up a little bit duplicate again and maybe up here and then duplicate and maybe put one like uh over here we've got all four of these children these little child cubes they're children of this spawner what i'm gonna do is just pick one of them at random to be the spawn point that i use when i spawn a marvin so that way they don't come out in a straight line so let's go into our spawner code and let's add a way to assign a bunch of spawn points so do that we'll add another serialized field and we're going to add a transform but it's not going to be a single transform it's going to be a transform array so we add the two square brackets right there and we'll call this spawn points now i'll save that and i'll copy it so double click ctrl c and then when we spawn it instead of spawning at our transform position we'll spawn at a spawn point so say var spawn point equals and i want to use spawn points at some random index i'll say random index i need to pick a random index and this random index is going to be a number between 0 and the number of spawn points that i have because spawn points is essentially assigned out as like a it's an array but you can think of it as a thing that we can index from like well one to 100 you want to get all the items except the first one starts with zero so you get the first item is zero the second one point will be one and so on you'll see a little bit better in the inspector in a second we need to create a random index though and this is going to be an integer so i'll hit alt enter and hit generate variable and i don't want it to be a field i want it to be a local variable so the random index is going to be assigned by using unityengine.random.range and we'll give it a value from 0 to our spawnpoints.link now this will just pick a random spawn point now the unity engine thing here by the way it's grayed out saying that it can be simplified but if i remove it and i add a using system here so if i do this then suddenly it goes it's no longer valid it can't be removed so most of the time i just type it in there and i leave it there even though it says it can be removed because later somebody adds the using system statement and then it breaks it because system has its own random class all right so we get a spawn point let's use that spawn point paste it here paste it there save we'll go back into unity and then we should see spawn points appear here notice how it's a collection here has a size of zero because there are none assigned i'm going to hit the lock button so that it stays locked so select all of these cubes these children here and then drag them all at once if i don't lock it it would go click on them and select them so now they're all here notice how this says element zero that's what i meant by accessing index zero or item zero that's going to be this first cube so if we get a zero it's going gonna be this cube i get a one that's gonna be that two it'll be that three that four that five that six it doesn't matter the order because we're picking one at random or completely at random now i'm gonna save and hit play i'm gonna leave the visuals on for just a moment but then we can just turn them off watch and see what happens so you can kind of see them here let's go to the scene view and you'll see that it's just spawning out of oh it should be spawning out of a different one each time oh there we go okay so it just got a little bit unlucky let's turn the spawn delay down to like point five notice it starts speeding up a little bit turn down like point one start seeing them just kind of flying out from everywhere and get totally overwhelmed and not be able to defeat them all right um that's a lot of marvin sir wow okay let's stop playing now and um i'm gonna go in and make it so there's a bunch of different versions of him right now there's just this one marvin let's make it so there are a couple different enemies and then we'll make it so they can get points from killing them and then make it so they can kill us and then see how long we can i think that would kind of get together at least somewhat of a gameplay loop so we'll start by making a couple more enemies here so go to my marvin blue and i'm gonna go to the robot pack and i think that the second best the second biggest pick was to use one of these um cute robot guys right let me unlock my inspector and i think it was these guys right here so i'm going to take a drink and let everybody kind of pick the color or the one that they want to use let's take them all i'm going to drag them all out into the scene right here let's see drag black the blue brown the green here i'm going to drag them silently while i drink all right look at all of those different colors anybody have a preference on um which version of this guy we use next all right we'll see anybody got any preference on them figure we have at least two different guys um yeah we always set up a whole bunch of different things but set up at least two different guys that move at different speeds and maybe do different things if anybody's got thoughts so green blue [Music] green about the asset store you just go to search for unity asset store you'll see there's also a window and asset store menu here you go to window and um where is asset or there you go i see but it just takes you to um the web page link essentially you go search for stuff all right so let's see lots of chat here lots of red red red red red red red okay lots of people want the red one okay i'm gonna go with uh the red one it seems like it's by far the most popular of course we could always add in any of them it's really easy to add in a bunch of different varieties so let's start with the red guy first oh hey thanks for the super chat um mitch thanks that's a great stream possible likes advice money working on my portfolio what should i focus on displaying with my games i want a developer position ah um good question i would say that if you're trying to show off a portfolio this is something i talked about a lot and it is interesting so i'm going to talk about for just a second but if you want to show off portfolio stuff i would really recommend putting together something that people can actually get in and play that's going to impress them in like 30 seconds so what happens a lot of time when we're looking at resumes and stuff hiring developers everybody is a lot of people at least have a portfolio and the ones who have these cool playable things where you can actually get in see what they did see what they built and that they finished it published it put it up it doesn't have to be published like into a paid platform or anything just be on h dot io or something but they got it up there and put it up and you're able to play it and it works and it's interesting and polished and again mostly that it works in this bug free that's the kind of thing that i would work on getting up there and showing off to people make something that's a simple but somewhat interesting doesn't have to be amazing just you know interest them and do it in 30 seconds or less don't make it something that they have to spend half an hour to understand or get into or enjoy um make it something that they can get into and have fun with right away all right let's set up this npc all right cute robot red so let's look at marvin real quick marvin has a nav mesh agent a capsule collider an animator and an enemy script that's really all this robot needs so let's go navmesh agent enemy and then what did i say a capsule collider with remember the y center at one and the height at two that way they're all just kind of uniform and uh was there anything else let's go double check marvin nope so one thing that is missing though if we go look at our robot is that the values here aren't assigned i can just go click on them and drag them or i can be lazy right click on this one hit copy component go over to my red robot right click on it on the enemy script and hit paste component values there we go now i've got my other npc set up if i hit play i expect him to just walk right to me and uh be ready to shoot and die that should be pretty much it let's hit play and see all right so i shoot the red guy bam okay but he's not animating so i need to fix his animation i'll go to animations i'm gonna take marvin bam drop it in there hit play let's watch him there we go now he's walking running at me and working good so let's rename him i'm going to rename him to cute red and then we'll drop him into prefabs call him cute red drop him down here and make him an original prefab now if i want to make some variants on it there's a bunch of different options right i could uh just go in and redo this with each one of those objects and swap them out but there's an easier way to do it if i right click on it and hit create and choose where is the prefab variant or no it's um i always get myself mixed up now prefab variant right there bam prefab variant and i just make this a different color like cute white and we'll use the white one and then we'll do like the blue one next let's see so the white one where's oh so to modify it i'll double click on it and then we'll go down to its body part here and right here where we have the material assigned i just need to adjust these to be the white material instead so i'll click on it go select the white one and drag it in i could just go through and select all of these but i want to make sure that they're all on the same one notice how a couple of them are using the blue it's interesting that they use the blue i wonder why that is let's go assign the white one real quick and see if it works here or if there's something different about the blue one so drag it in okay it works on all of them i'm just going to assign white to all of them where's that material one more time bam and now we've got a white version of that bot so if i go back and i take my white robot out of the prefab folder where's that cute white bam now i've got him set up and he should work exactly the same now i'm going to do another variant and make a let's make a blue one too so go right click prefab variant ah prefab variant i keep missing it even though it's right in front of me i'll make a cute blue all right so here we'll go to our prefab edit mode again so i gotta double click on it i get my words mixed up here and then collapse these down select them all we'll choose a material and here i'll search for blue and choose the cute robot blue bam now i've got a blue one that's it that's all i need to do to make just a bunch of different prefab variants of different robots now if i want to change the speeds of them like say i want to make this blue guy let's make him a little bit slower to do that i can just adjust his nav mesh agent so i'll make the blue guy he'll be like slow and tanky so i'll make him go at 2.5 and he's got five health seems like a good value for him the red guy i'm gonna make go like one health but he goes a little bit faster so he's like 4.5 and the white one i'll put like just kind of in the center it'll be two health and the 3.5 so now i've got a little bit of variation in the speed that they go at and um and the health that they have all right let's set up the spawner now to be able to use all of them so go back to the spawner go to our spawner script and in here just like we randomized the spawn points we could just randomize the npcs or the bots to use so we'll just do that with a serialized field and it'll be of type enemy but again not a single one we're going to do an array so that we can pick a random one so we'll do square braces and name this enemies all right now we'll go when we select an enemy or select when we do our spawn instead of using a prefab here or the prefab field we'll just pick an enemy at random so i'm going to delete the prefab field here shift delete delete the whole row by the way our whole line anybody that's not used to that it's one of my favorite hotkeys shift delete and um also control backspace to go back if you know or not control backspace control minus to go back it takes you back like to the last place you're at i have that actually bound on my mouse as one of my one of my hotkeys to just go back to the last point i was at all right so let's select an enemy at random do the same thing that we did here where we selected a spawn point in fact i'm going to refactor and extract this part out so this part here where we select a spawn point select it all hit alt enter hit extract method and make this call it choose spawn point and now i'll do another one that just does a choose enemy so say enemy enemy equals choose enemy that way my code gets a little bit easier to read and i'll hit alt enter and generate it and then we'll just choose the enemy right there or we'll assign the enemies now i have this enemy that i need to pick out of my choose enemy method i'll delete the private key word with that private keyword there too and i'm just going to copy this i'm literally just going to copy this part where i do my choose spawn point paste it here we'll replace spawn points with enemies and replace the word spawn point ctrl r with enemy that's it i don't need to do anything else again i could make it like more generic and reusable but there's really no benefit when i'm using it these two times in this one little spot so let's go back to our spawner and assign the different enemies and then see if we can go blow them up real quick so expand out enemies and we'll lock this go to our prefabs folder and go select our three cute guys and the marvin one drop them all in here as possible enemies save and hit play i expect to see a whole bunch of different enemies appearing now and spawning out of those different spawn points or a variety of them there's some marvin's there's some of that gray dude whole bunch of yeah there's definitely um yeah it's working okay so real quick uh people asking what language this is it's uh c-sharp and we're working in unity just making a shooter just going from scratch so anybody who's joining in late you can always go back later and rewind and watch the whole thing go through all of the steps kind of taking it step by step and just building out the entire thing so we've got the enemies here spawning um i'm gonna stop playing and just add a couple more spawners so i've got my spawner right now actually first i'm going to go well actually i don't want to disable the visuals yet so i'll duplicate my spawner hit control d and i'm going to move this one just kind of down the street a bit so that it comes kind of off the screen um i think it needs to go a little bit further let's take game view make it side by side and then just drag this out here so they appear just off the screen i don't want them to spawn on the screen and i'll duplicate that again and i'm going to move it so that it's off the screen down this way but i'm going to rotate it so here rotate with the e and then hold ctrl and just drag that spin them around get them kind of spread out but off the screen they're still a little bit on the screen so let's drag them a little bit more and then i need to move this other cube that kind of went off of the edge because that wouldn't actually spawn okay and man these are still they're still just barely inside my view so i think what i'm going to do just to make it easier on myself is move my camera in a little bit so let me find the camera and if i go just hit f and go to it if i just pull it in a tiny little bit or down a tiny little bit see i think that that's going to fix my issue with them being off screen i could just expand out the road too but i don't really feel like anybody wants to watch me level build because i am not a good level builder my level building skills are pretty pretty terrible but i can write some code and i can show you how to do that so stick to that part all right so i've got the other spawner there i've got that one i'll duplicate this one and put it over here somewhere and rotate again hit e hold ctrl and drag it w to move and get it kind of placed all right so now i expect to see enemies coming from all three directions and i don't have any cubes on my screen if i still had the cubes and i really wanted to spawn them on screen by the way i could just disable the renderers on those but i like having them on so that i can see exactly where they're spawning i haven't had to set up any custom editor stuff for him yet here we go we got enemies coming from all different directions um things seem to work let's stop playing let's hit maximize or just maximize on play hit play and start blasting a bunch of dudes all right here come the enemies and i don't know if i'd be able to maybe i could keep up at this rate i don't think so i'm not i'm not a good enough shot i'm definitely gonna get overwhelmed so let's see let's um stop playing real quick i'm gonna crank up my shooting rate just a little bit so that i can have a little bit more fun shoot some of them and then we'll extend out the code okay so not the spawner oh i have it locked unlock my inspector let's turn our shoot delay down to like point one i'll double my shoots hit play and see what happens the other thing i was thinking might be interesting too is i could have like a shoot a spray or something like a spreadshot see there we go getting that's a little bit better able to shoot at the enemies there's still a lot of them though [Music] all right so um yeah there's a question about serialized fields in the chat it just makes it so that the field is accessible in the inspector and in the editor but without making it um public so that you can't accidentally change it from some other code all right so i think that um now i've got a couple options i could add in score or i could add in um death i think i want to add in score before i add in player death so that i can build up my score and then see how hard it actually is so i'm going to do that by creating a new system or a score system so we'll actually do a little bit of ui work if anybody was excited or interested in seeing how to build an in-game ui well this will only take a second so we'll do it by creating a new game object go to game object ui and use text mesh pro text this will pop up the inspector or the importer for text mesh pro and i'll hit the import button and pull it in i want my text to look nice there's a question about uh at what point do you know enough to start working at a company i'd say as soon as you can build a um if you can build a little mini game on your own you probably know at least enough to start working and contributing at a like a junior level at a company so i would say if you can code a little bit you can make a game you can figure out a couple issues um you should be able to at least contribute you gotta marry like you're not gonna be the best or the the expert there at the beginning and nobody's gonna expect you to they're gonna expect you to do smaller things at first and kind of learn on the job as you get used to it every project is different every team is different and you're going to get better at it as you go along so i would say as soon as you can write some code you can build some little games and you can you understand what you're doing i start applying and i mean the sooner you get into a job the sooner you're going to get faster and faster and better all right so we got a text object here let's take a look at it it shows up right in the middle of the scene or in the of the game view if i go to the scene view and hit f it looks weird but if i go to 2d and zoom out i can kind of see what it's doing there all i want to do is dock this to the top and make it some text that shows my score so i'm going to hit this direct transform tool and hit alt shift alt shift and then click this one right here to dock it to the top now i've got text up there i'm going to rename this or change the text to say like zero zero zero comma zero zero zero and see what it's going to look like and then crank that font size way up now obviously i don't want it to stretch like that so i'm gonna make it stretch across the top with the anchor preset so i'll hold alt and shift do the stretch one and um that looks good now the reason it's over to the left is because the text is aligned to the left i've hit the center you see it aligns the center if i look at it you see here it's stretched out now because of that anchor option i'm going to drag this down just so that it matches what it's actually sized at right now it's overflowing anyway and then i'll set this to like a 160 i think that probably a big enough score it might be a little bit too big but who knows let's see i'll set it to like 100 000 as the score all right now i'm gonna change the font asset because i don't want this liberation one i want to use something like um bangers or maybe electronic highway is always one that looks kind of like a it looks like a score system so may i use that electronic highway one and then oh this one doesn't have any drop down options if you want to pick one that has some drop downs you can go like hangers and use the drop shadow or with the outline or um it's the glow one oh that's interesting and the logo i'm not sure what that one is i think i'm just going to go with the uh i'm going to go with bangers outline for now that'll be my score counter this is just gonna be some text to show how many points i have now my score system is gonna be really really simple so i'm gonna drop it on to my text object i don't care it doesn't need to link up with anything and um i'm not going to persist score across multiple levels or anything right now so i'm just going to create a score system and drop it on to this text so right click create a new c-sharp script called score system open it up and what this is going to do is keep track of a number of points and then update our text whenever we add some points so let's zoom in a little bit delete all of that extra stuff and delete the unused using statements and our score system is going to need a public method that adds points so say public void add into points so add some number of points all that needs to do is increment our total point so say points plus equals points this would be our current total points and then this is the number of points being added that's passed in as the parameter so hit alt enter and generate that total number of points get rid of that private keyword and now we've got a value value that'll stick around when that value changes we just want to update our text to say the new value we'll say underscore text set text and we'll set it to points dot to string now we don't have an underscore text yet so let's get it do that i'll add an awake method down here i'll zoom out just a little bit get rid of the private keyword again and i'll say underscore text equals git component tmp underscore text add in the open close parenthesis and the semicolon add the using statement here by clicking on it and hitting alt enter and then add the field here by hitting alt enter and generating the field now the reason that we use the tmp text by the way is just so that well if you look here let's go take a quick look at it this text object here is using a text mesh pro text and there are two different versions of them there's one for world space uis that we would place like in the world if you had it on like an in-game screen or something and then other ones for the overlay uis the tmp text is the base class so it works for both of them so that way i can have this work in like in a um in like a world space ui or in this overlay ui so that's why i use that base class plus it's shorter and i have to type out the full name so what this is going to do is get that text object here cache it and then whenever we add points it'll keep track of the number of points and then show them in here it's not going to put a comma in there though might have to do something for that later but first let's just get it working first we'll add the score system script to that text and if you're wondering like hey should i really put my score system on a text object um no i wouldn't i would probably say that i'd move this out into another game object something that stays around and keeps somewhat longer lifetime but since the lifetime of my scene is the lifetime of my game it doesn't matter and there's no reason to add the extra complication but assuming that i wanted to have more than one level this is not the place that i would keep it i would separate them out and put in some some linking some events together or something to keep track so here we've got our score system and it should work if we just start to call add now call add or where do we want to call i think just in the take damage so when we blow up an enemy we can add in some points based on the enemy's point value so i'll just say hey score system dot add and if you look there's no add method for it because our score system doesn't it's not static and we don't have an instance of it there's no way to get to this add method so i have a couple options here i could make our score system into a singleton i could do a find object of type score system dot add and just add in the points and um honestly like in this case this is probably the the best solution only because we're not gonna ever hit a performance issue here i'm never gonna blow up enough things fast enough that this find objective type call is going to matter in reality i should cache this make it a singleton or something else or make it a static method i'm going to do it i can't resist we're going to do it we're going to go score system dot add and we'll add in point value sorry i i said i was going to do it the the sloppy way but i just couldn't couldn't do it so let's add in a point value so hit alt enter we'll generate a field for it hit f12 and let's go up here replace this with serialized field give it a default of 100 points i'm going to move it up here so that it's by the health all right now we'll go make this actually work so i'll hit f12 go to the add method we're going to make it static so what that means is that it's no longer going to have references to anything in the object it's no longer going to know about its existence as an object this is actually just a method that's on score system totally unrelated to the instances of it so i need to have a reference to the instance of the object to set this point value and to set the text i can cheat though what i can do is say static end points and static mp text bam now i'll cache that text once right away whenever this thing awakes and my points value is always the same i can delete that save it off and i didn't really have to write much extra code but it's a cleaner it's at least more performant i'm no longer going to be getting multiple text objects are no longer going to be searching for that object every time all right so let's try it out so if i hit play i expect to see my score stay until i blow something up bam 100 200 3 500. 6. and so on so if i stop playing now i think it makes sense to start changing the value of these npcs because they're all worth the same point value let's create an enemy folder underneath prefabs enemies oops no wise and enemies and move these robots under it all right um and then in here we'll just modify these values so the blue one i made um really big so let's make them worth like 500. you know it may i'll just make them worth about what their health value is so this guy's worth 200 and let's make marvin seems pretty special so i'm gonna make him worth more points i'm gonna make him worth a thousand points and um not very hard to kill just so that he's fun he's more exciting to take out right all right um we'll hit play one more time see if that score stuff works if i can blow things up that scoring is working great things are blowing up all right cool um and now i think uh the next thing i want to do is make it so i could actually die because without anything killing me there's no real challenge so let's make it so the player can die to do that we'll go into the enemy and we've got a couple options i mean we could add like a on collision enter and see if he just bumps into the player let's double check our enemy has a collider on them right marvin's have a slider on them so we just do a check to see if we bump into the player let's see if the player has a collider though i can't remember if our player actually had one anymore our player does not have a glider so let's add a capsule collider real quick and let's set his position the center to one and the height two two i'm gonna go to the scene view so you can see what it looks like out of 2d mode hit f and zoom in so that's the capsule at one here and two on the height if it was at one it'd be tiny all right so we'll save that off let's hit play and see now you should see like the uh the bots should kind of run up to them and stop they shouldn't run through them anymore here let's see if they do that oh interesting i'm surprised that they're still pushing into him huh i'm not sure why they're still pushing into me what did i miss i don't know let's figure it out oh um let's go make them actually do the damage when they hit the collision injury though because now we have a collider and we have a collider on my on my marvin's and my enemies so i'm just gonna add non-collision enter to the enemy and then we'll um make it so that they die when when when i hit when i get hit they'll say um on collision enter and i'm going to get rid of the private keyword and here we'll say bar player equals collision.collider.getcomponent and we'll get the player again and if the player is not equal to null so if we actually hit a player then we'll just kill the player the easiest way to kill a player in a unity game is to just reload the scene or reload the game so i'm going to cheat and do it that way as my start soldier scene manager which doesn't exist until i hit escape alt enter and add the using statement and then do dot load scene and pass in a0 that'll just reload our first saved off scene our first scene in our scene index if i save and hit play see what happens oh the enemies have a what's going on here oh they don't have a rigid body yeah that's the problem so they need to have a rigid body and i need to make that kinematic i don't want to use gravity let's hit that no what did i miss i missed something here hopefully somebody in chat sees it i'm not sure what i've missed on my player my npc has a oh he doesn't have a rigid body that could have something to do with it missing the uh the rigid body on my actual character turn that on hit play and try one more time okay still missing something what have i missed here so my robot soldier marvin's oh wait did i add the rigid body to the oh that's the problem okay i see what i did i i messed up i added the rigid body to my object out there not to the um the actual characters let me make sure that i have it on all of them here i've got marvin here and does he have a rigid body he does marvin does these guys do not i need to add a rigid body to them and save and hit play yeah i totally messed that up get my rigid bodies in the wrong spot okay so that should work there bam and i die when they hit me so now you see that when i when i get hit i'm dying so what i missed there for anybody who was missing it or was confused there i didn't put the uh rigid body on my player and i didn't have a rigid body on my enemies and i need a rigid body on at least one of them to get the collisions between the two of them that looked like a root motion animation issue that was weird um and then the other issue that i had was that i when i did it i didn't put it on the um the prefabs so the guys that were spawning didn't come in with the rigid bodies on them um but the other guys did okay so why oh okay i need to lock the rotation and position of these guys actually you know what yeah so if i go into my characters here um i believe i can just check is kinematic on all of them i don't really want them moving or getting pushed around check that there we go now they should start moving normal yeah and is gravity was on too i having them kinematic should mean that they stopped falling but unchecking it makes sense okay looks much much better so i've got enemies here that shoot and they um ah they don't shoot they chase me though and i don't know how long i can live okay i got up to like seven thousand um let's add in a high score real quick i wanna see what my high score is and then we'll uh keep going from there oh yeah somebody asked about the monitor it's a uh yeah it's 49 inch lg and it's by far like the favorite thing that i've upgraded in a long time it's a huge upgrade from having a triple monitor set up um just because there's no bezel and i can kind of get things exactly where i want them with the triple i was always constantly turning my neck here turning my neck here trying to see things and and get it right and here's just kind of perfect um obviously it's not perfect for all games but uh star wars has been great on here too if you've got a game that works great in widescreen it's a it's a lot of fun um if not then okay not not as great all right so let's let's get going with um uh what was i gonna add before my kid just started screaming um oh i've lost it i lost it what was i gonna add here somebody remind me in chat oh high score i remember now let's go add a high score real quick so i'm going to hit f go to it in the scene view go to 2d mode and then i'm going to duplicate this text object and just make a high score text object so duplicate it i'm going to anchor it to the top right here so that it's no or actually you know what let's just keep the anchor there the same i'm just going to do the alignment here so i'll right align it i'm going to shrink the text size down to like 80 because that's the top score and then let's um replace the score system script with a top scorer script um oh how do i want to do this let me think for just a second [Music] um think i want to because i don't want to add a whole second a second script this i just want to add a high score value so i'll say static and high score and then here we'll say um if points is greater than or equal to high score then i score equals points and i want to update the um the text object here to be the highest score so i'll say that the high score text set text to that high score value so copy this paste it replace text with i score text and then replace points with high score and i need to figure out how to get my high score text so i'm going to make that a field up here i'll say tmp text high score text and then i'm going to have to replace it so i'm going to i'm going to change this i'm going to make this a serialized field and i'll make the other one a serialized field watch this we're going to move things around real quick yeah we can save the high score off permanently too why not so we'll set our text here get this but what i'm going to need to do now is just make this into like a full-fledged singleton so in awake i'll say instance right here let's make it a private one instance equals this we'll delete that and we'll generate a static field for instance so go up here replace private with static what's going to happen here let's move this awake method up i'm going to cut it move it up here and turn it into an expression body method it's very very clear what's going on here move these right up here all right so in awake we're going to say hey our static instance which is only ever one of is set to us now if we had three score systems we'd call it once we'd set it to the first one then we'd set it to the second one then we'd set it to the third one don't have three score systems that will break the system you need to have smarter code if you want to do that but since i only have one score system what i can do with this is now i can copy this instance here and when i want to set the text i can do underscore instance dot underscore text and underscore instance dot underscore high text so now i can set up a score system object in my scene and i can just assign these two serialized fields let's zoom out and take a real quick look at what this looked like so here you can see i've got this add method here that's static so i can call add without knowing anything about the score system and the score system is just going to say hey okay go and set up your your values and set up your instance or that you set up but use your instance and update those values obviously i could add in some checks to make it smarter and stuff but i don't necessarily need to and i could even um yeah i could make these not static as well i can make the high score and the points not static it's not going to make any difference um either way really be honest yeah oh well if i made it not if i made these points not static i'd have to reference them there so i'm just going to save and then i'm going to go into my scores or set up my score system real quick and then we'll make this persist as well so let's go into our score system here and right now i've got the score system on both of these text objects that's not gonna work that's a big problem i'm gonna move it i'm gonna click drag it and move it on to my canvas if i click here you'll see that it's gone from this child here but it's still on this other text so i'm going to remove it here so right click and hit remove go to the canvas again where i put my score system and i'll just set the text to this one and the high score text this second one i'm going to rename them though call this i score and let's call this score and save that off so now i've got them both assigned here and if i hit play i should see that my score goes up and actually making those not static would be an issue too because then my high score would reset every time i went into a new scene that would definitely be an issue okay so i've got a high score of 3200 oh okay i kill a guy and oh my score's not resetting let's stop playing actually yeah let's do let's make this not static so we'll make our points value not static i'm going to make the high score value stay static so points will get incremented i'll use instance dot points plus equals points and here we'll say actually i'm gonna i'm gonna simplify this i don't like calling instance dot a billion times so what we're gonna do instead is make a new method so i'll close this off i'll say private void add endpoints and what we'll do is we'll add our points here we'll remove this instance part here or remove the instance part here and we're going to say underscore instance dot add now we could of course just make the instance public and then say scoresystem.instance.add but here um what's the problem here oh there okay it's got same name sorry add points i i kept the name the same so here we've got it wrapped up so now i've got this public method to just wrap into the instance if i wanted to pull other things out i would probably make this instance closer to a public singleton where it's just the thing that i referenced all right so this should do it so now we'll get a new version of points every time we restart or every time we reload our scene but our high score will stay the same the last thing i need to do though is reset the high score text whenever we reload and reset the text whenever we reload so i'm just going to say unenable and then in here we'll set the text to points text and set the high score text to the high score text so whenever this thing enables we set up our text values right let's stop and play one more time oh cool somebody said they're 11 and my tutorials help them that's awesome bad to hear it i mean hopefully it helps everybody it's good stuff all right and you definitely should start coding early i highly recommend it to everybody start coding as early as you can so look my high score is working i got to 2 400 and now i get to 2 800. let's die again bam i die and it's still at 2800 but if i stop playing and i start playing again watch what happens oops let's see it resets that's what's going to happen you'll see it real quick and then we will make it persist because why not okay there we go that oh yeah i forgot marvin's worth a thousand all right lots of points there okay let's stop playing and let's make that persist real quick um by the way if you guys don't mind hitting the like share and all that stuff i really appreciate it or just dropping a dropping this on facebook or wherever other places you happen to visit really appreciate it um but for now let's get into saving off our score so high score i want to make it save off the high score if we get a new high score to do that we'll just say player prefs dot set int or not set float set end and we'll set the high score to underscore high score that'll just save off our high score in a value named player or named high score the way that player preps works by the way it's really meant to save off player preferences like settings inputs and stuff but it also works great for saving off simple data that you don't care about the player getting into if you care about the player hacking this high score value then it's probably not the best option or you need to do some extra work but most time we don't care in here i don't care at all so we'll set the high score value and this is going to save it off on just about any device on windows it saves it in the registry on mobile devices it's in different files and systems and it really just depends on what it is but this will save it off and to get the value i can just go to on enable and say high score equals player prefs.getint i score now if i save this off and i try it you're gonna see it doesn't quite work let's try it though there's a tiny little bug but i figure why not just show the bug real quick and then we'll uh show how to fix it and make the high score actually completely persist and safe so notice that my high score was zero right oh here actually i haven't i haven't got a high score yet let's get a new high score that's a couple thousand points all right i wanna get at least more than two thousand all right so i got a score of like 4 200. i'm gonna stop playing we'll play again and see if it reloads and shows that by this still shows zero but if i kill one of these guys watch it oh it's still going to show zero so the reason it's still showing zero let's go up here is that i'm getting the high score right after i set the text so i'm just going to move this line up here paste it delete that come back into unity and then we'll hit play again it should work check out what this error by the way i assume it's just the um oh there's something with a bullet i'll check that out in a second let's hit play see what's going on and then we'll check out the error message so come in here high score is showing up as 4200 looks good and if i get a higher score ah am i gonna get a higher score am i gonna die yeah six thousand seven thousand seventy five hundred that's the the ones and the sevens don't do very good in here by the way they look very similar that seven looks just like the one but my high score is working so i think that's pretty good i want to go look at what this error message was though oh here it says that on collision enter gun dot add to pool had an error let me show you how to debug that real quick it's probably been happening for a long time let's hit play oh i'm going to uncheck the maximize on play that's going to mess with me uncheck maximize on play then i'll hit play and let's see if we can see it so click on this right here oh you can't actually see the object where my error go come on error come back okay play and pause i don't know why i'm not getting the error message but what i expect the error to be is this bullet right here oh it's probably when i walk into it that's what it is so i bet i walk into it yep there we go i walk into this bullet like if you click on it now i got the error message again see this bullet is causing the error the reason that what i was trying to do though was show that when you get an error like this assuming the object's still around if you click on it it'll actually highlight that object and go click on it or show me the bullet so the problem here is that this bullet because it's not being spawned by something else it doesn't have a gun so gun dot add to pull doesn't work easy fix though i can add a question mark here the error goes away because now if gun is null it won't add this thing to a pool so if i happen to leave a bullet stray in the level it's not going to break anything even if i run into it let's stop play one more time i'm going to run into the bullet there we go bam error message is gone all right so i got high scores we got enemies hidden um let's add some audio real quick and then i think we'll probably wrap it up shortly after i've been going for a while now it's a lot of fun and building stuff but um why not put in some audio and a couple more things before i run out of breath and pass out also again don't forget to like and share and all that stuff all right let's go through um audio so we want to put in some sound effects make them like do a boom or something it's going to be weird though because you're not going to be able to hear the sound effects through the stream i bet um let's add it really really quickly then so if that way even if you can't hear the sounds it's not very boring so let's go find a sound effect thing i have a universal sound effects right here bam just download oh that's huge um interesting what's this free game casual sfx let's try this one instead this one's eight megabytes the other one is um 886 megabytes i think that the eight megabyte version seems a little bit better so we'll import this one and i'll pull them in real quick i have no idea what these sounds sound like or what they are but hopefully there's an explosion it says something about juicy explosion sound so hopefully that works all right so go in here we'll find some audio files casual game sounds and oh man they're not named anything useful at all i'm gonna have to turn audio on hopefully everybody can suddenly hear my desktop let's see i hit play oh it's unmute i don't know if anybody can hear that or not let's see let me double check this audio i was not planning on doing an audio setup but hey why not um desktop audio again um i'm not sure sorry i'm not a hundred percent sure this audio is showing up or working right um well if not it's fine it's only going to take me two seconds to add in a sound effect we just need to i'll find some sort of an explosion sound so go through here and just pick a um i feel like i need to get my sound effects working so you guys can hear it i can hear all these cool sounds and nobody oh you can hear wait can somebody hear it okay no people saying they can't hear or they can hear i'm a little confused can anybody hear the sounds normally force mute all of my audio sounds so let's see anything now any audio sounds if i hit play and ding this okay hopefully you guys can hear that okay perfect so let's pick an explosion oh my i wish these were named a little better oh that was an odd one i don't know if i'm gonna be able to find a sound effect in here there's so many okay i think i might use that number seven one this one oh yeah yeah let's try this it's a weird weird one so i'm going to try that out um i wish i had a better explosion sound but whatever you guys probably don't want to hear something blowing up constantly anyway let's go find the enemy here or let's let's use our cute red guy here and i'm going to check his overrides he has nothing changed on him so i'm just going to take this sound effect here and drag it right onto oh i got to reselect them let's collapse all of these so you can see everything claps all that down and let's just take number seven and drag it right onto him this is gonna make it so that he automatically plays that and if i hit loop and leave play on away con watch oh mute audio's on you can hear him constantly playing that oh excuse me somewhat annoying sound right so let's change it so that he doesn't play it on awake and he doesn't loop it so just uncheck both of those and then i'll save go to overrides hit apply all and then let's make it so that he plays it whenever he takes a hit so do that we'll just go into our enemy and in our enemy just like when we play a particle on hit we can just play a sound effect on hit so to do that we'll say underscore audio source dot play audio source doesn't exist so i'll copy it go to find our awaco we don't have an awake so let's just do it in update we'll say audio source equals get component audio source and save that off or i need to generate the field part so here what i'm doing is just caching the audio source in our on enable so that we only get it once and then we'll just play the sound effect whenever we take damage getting a little bit more efficient here but not enough that it's going to make a difference but i figured why not use some good practices so i'll generate the field there and then select private and hit enter to just separate that down and get my serialized fields away from my non-serialized ones that should be enough assuming i have an audio so if i hit play now i expect to hear it on some things and see a lot of errors on others let's try it out we play oh i hit play once i got it i got to hit it one time i keep hitting it twice all right so we'll blast some bad guys nothing well i heard it on that guy so i heard it for the one guy but nothing else and if i look down here it says value cannot be null problem is that i didn't do it on all my prefabs but first i want to make it so that my audio source doesn't give me an error if i don't have an audio source on it so in our take damage if i add that question mark again it'll essentially do a null check and make sure that the audio source is there the other way to write this by the way if i copy that and just go up here i can say if audio source do that and tap it in or if audio source is not equal to null all of these are going to do kind of the same thing in our scenario right now if i do the question mark dot then that will do the same thing here too because i'm never going to destroy that audio source component if i destroyed it then that would be a problem but i'm not going to do that so i'm going to leave the code though because it doesn't make any difference for me all right i'm going to go back into our project view one more time go to our prefabs select all of our enemies and i'm going to make sure that we have the audio source on all so the blue guy has the audio source the red and white don't so i'm gonna go select them and then i'll lock my view here hit the lock go into our casual game sounds and i'm just gonna take um i'll take number oh i'm gonna take number seven again because i don't remember what those other ones sounded like and just drop it on here that should add the component to all of them i'll un hit the lock go back into my prefabs folder real quick the enemies and just go through them you should see that there's an audio source on all three of them now why does this guy have his rigid body removed oh he has it re-added down there interesting okay so we'll save and play the reason for that is just because of it being a variant too i totally forgot that these were variants and i didn't need to um do it on all of them i could have just done it on the parent one oh you guys can kind of hear it so if you're wondering i think there's a little bit of a delay on that sound effect too is that what's going on here let's select it no there isn't i wonder why it seems a little delayed i don't know i don't i don't want to keep dealing with sound effects though because sound doesn't work very well so somebody was asking about whether or not we should cache these things in awake instead of on enable or something and uh usually i would cash in awake but on enable is already there and i'm not going to create an awake just for it so no real need to add that in i don't know if there's anything else i want to add and i'm getting a little bit thirsty and ready for a break so i just wanted to take a minute i guess and run through stuff and just actually you know i'll add an animator controller that updates our animation so that when i stop running it doesn't keep playing that stupid running animation and just see if anybody's got any questions or anything else you guys want to um chat about real quick before i wrap this up and also just remind everybody again to please just just hit the like button and the share and all that stuff it really makes a big difference i appreciate it a lot and it helps a lot um all right so let's go in and update the animator controller for our player so i'll go to my robot soldier and i'm going to go into his animator double click on the player and here we have that controller where we just set up the one simple animation just plays a run and it loops constantly but i want to make it so that he'll play a run animation and an idle animation so i'm going to go back to that miximo tab and i'm going to grab another animation that's like an idle with gun so here we are on mixedmo anybody that missed this earlier it's a free site you upload your model um and then you can grab animations and map them right onto it so you just go sign up set up an account it's all free and it's really cool i love it so i want to shoot idle like a shooting standing or something like that right let's go into the shooter pack and see what's in here click on the shooter pack oh actually it's going to play all of the animations let's say let's just find a shoot that's not walking i'll find a shoot maybe rifle i think that gunplay one looked better this one right here something like this where he's just constantly shooting okay then i'll play with the arm space value again this just allows me to make a little bit of modification and adjustments on the characters or the animations i think that looks good hit download choose fbx for unity make sure you hit that and then hit download again let's just put it into a folder and then i'll drop it or i'm going to put it into this animation folder here just like i did before so if you missed it all i'm doing is saving it into this folder right here off screen go to the animation folder and i'm going to save this um essentially this right here this little window save and it should pop up in here now go to the gun play and i need to adjust the rig so by default with uh with these characters because they're using the humanoid rig i need to set it up to use that same rig so i switch over to humanoid and instead of creating i want to choose copy from other avatar hit the search box and go choose my robot soldier avatar that already existed with the character automatically because you've set up as a humanoid hit apply and import it now i've got two animations i'm gonna take my gunplay animation expand it up get the animation part that's the little triangle there and drop it into the animator window or this animator area right below my run now i'm going to go into the um actually let's go to scene view let's disable all of my spawners real quick i'm going to disable the spawners and i'm going to kill off um these other npcs these red robots and uh the explosions by the way speaking of npcs i don't know if i showed anybody but this uh npc shirt really cool um yeah i'll talk more about that later it was really cool uh i'm excited about it anyway i'm gonna shut up and get back into the animation stuff so i'll collapse this down go back into my player animator and what i want to do is make it so that we can transition between these two but i want to see the animations in action first so i'm going to hit play and let's watch watch the guy run real quick so we should see him running right and now i'm going to make it so that he doesn't do that and he switches to the other animation so stop playing i'm going to go to the animator i'm going to right click and make this his default so he goes into gun play instead and then hit play and now he just stands there kind of playing this but oh he's not looping right so let's fix that let's adjust it so that it loops so go to the gun play animation go to the animation window and let's just preview it real quick and see if they're playing i'm going to hit the loop time button so loop time checkbox and hit apply and then let's make sure this is showing up not underneath me drag that out of the way so i've got loop time on and you can see him animating down there right he's doing this the little wiggle and i want to do that offset that i did too just like before when i did the rotation offset so that his gun looked more towards the blue the goal here is to make it so that the gun is facing towards the blue that way when he's forward his animation has him shooting the gun towards his forward animate or his forward direction just grab the offset and drag drug it to the left until lined up hit apply hit play and now we should see it show up it's funny somebody's mentioning smash tv that was kind of inspiration for this very very much a good inspiration point all right so now he's got that animation but i want to make him be able to switch between the two so to do that i'm just going to make a transition in my animator i'll go to the animator while i'm not playing right click hit make transition and drag it up to run then i'll right click on run make transition drag it down to gun play i'm going to zoom in a bit you can see these a little bit better so here are my two transitions if i hit play now you see that he's going to switch between the two go back and forth so run walk run walk run walk run walk what i want to do is make it so that he only switches whenever i'm not moving so he switches based on my movement speed essentially so to do that we'll add a parameter go to parameters hit the plus we'll add a float and call this um actually you know what let's hit delete i don't want to add a float let's add a bool and let's call this walk so i wanted i want to turn it on and off when i'm using controls and not care about my actual speed so be based on whether or not i'm pushing pushing down on the keyboard so when walk is true i want to hit or actually let's rename this to run my animations named run when run is true i want to do this transition from gun play to run so to set that up i go to conditions hit plus and it'll kind of automatically add because i only have one parameter and the default value is true so when it's true it'll switch into that run and then what i want to do is switch out of run when it's not true so i'll click on the transition from run to gun play hit plus and i'll switch this from true to false now i'm going to uncheck has exit time on both of these so there's no blending of the animations and it just kind of snaps and happens really fast save this off and now if i try to run this i mean it'll work let's try it hit play but there's nothing in code that's going to hook it up right i've got it going here it's set up if i drag my animator down and i check this box you can see that it switches between the two animations and here if i hold alt and drag around you can actually watch it in action if i select the robot see it playing gun play and i switch and it switches to playing run so now i just need to make some code that does a little call to set this boolean to set this run to true or false to do that i'll go into my player script and here when we move i'll just set that value to true if my horizontal or vertical or greater than zero and false if they're not so i need to get access to my animator so here somebody was asking about awake earlier and caching things let's add an awake now add an awake method and here let's cache the animators we'll say underscore animator equals get component animator and then we'll generate a field for it and i'm going to turn this into an expression body method because it's a one-liner and it doesn't need to be any more than that get rid of the private keyword there and that extra space and then in our code here in the update when we do the movement i'll just say hey if the movement's magnitude is greater than zero then we should be running if it's not then we should be not running now magnitude is a variable or a field on our vector three i guess probably a property actually it just gives us back or it's probably actually a field it returns back the value um the the total magnitude of all of our different distances so if we had like a one on the y we'd have a one for it if we had a one on the y and a one on the x we'd get whatever just like 1.414 i think um you essentially get the total distance of that vector so we'll say right here animator dot set bool run and we'll set it to movement dot magnitude greater than zero so if the magnitude is greater than zero run is true if it's less than zero it'll be false and anybody asking about the stream yes it'll be available after you can definitely go through it afterwards and re-watch follow along and everything else all right let's play one more time and see if the animation switches there we go and then i start running it's animating yep looking good and then i stop running and it stops animating or stops running playing the run animation i think the last thing i do is just move this dude down so he's actually on the ground right now he's his position was up above the ground so he's kind of floating i'm down to zero i don't want him to fall into that crater or anything i think this is fine if he just hovers over it for now and um like i said he's getting a little bit thirsty a little tired so i'm gonna stop playing i'm gonna turn on these spawners one more time play through it real quick and then just answer questions for the next few minutes and then we'll start to start to wrap things up okay let's blow up some more enemies okay i'm going to mute the audio because it's going to just keep bleeping and blooping at us and stuff but you can see it looks like it's working everything feels pretty good kind of cool little game and maybe i'll like publish it up or at least um share the code i guess i could just zip up the code um i'll do i'll put the code into the description below give it give a link so everybody can just grab it if they want to check it out obviously you got to go grab the assets or whatever assets you want and go through the setup and stuff but if you want to be able to compare the code and see like if you missed anything or anything like that be able to check that out all right i'm gonna um stop playing switch over to camera mode for just a minute and uh just go through any questions see if anybody had anything for like the next five minutes or so and then i'm gonna bail out go get a drink some food and uh hang out kids and all the other stuff if you just join don't worry though you can always go back through and re-watch and make sure you're subscribed i'll probably do some more of these and i think i'm gonna do a full video on how to build a 3d game um like kind of like a longer one i did one on how to build a 2d game a couple times i'm building out angry birds and practiced it and got better and better at it and i think that this is kind of a good starting point to build out a full video on how to build a 3d game from scratch with no experience so if you're interested in that make sure that you're subscribed and stuff as well um oh the shirt it's just this uh this is the hoodie um uh yeah who made the brackies logo made this and i really like it uh so i might offer it sometime soon and then she also made this thing my my debug mug that i love to send one to my buddy joe and i'm i'm i might make these available too i don't know but i i'm just excited about it i really like to say i have like 10 of them though because i've been trying to get different sizes and figure out like the right printing of stuff of cool design i just thought it was neat like it's basically just npc stuff a bunch of little npc jokes and stuff is cool um okay so let's see questions um trying to use projectors to represent what area was being selected okay so with projectors there's been a lot of changes with urp and i'm not sure what the best options are there um [Music] i wish i'd give you some really good advice on showing the the selection stuff with with urp it's been a little while since i had to do it but maybe i could put that into a video sometimes you know i want to do a couple new urp videos now that i feel like things are getting stabilized um so may i do one that shows how to do some projectors and bullets and a couple other things in urp and just setting up a project with it too let's see how do you sync list with unity networking that i'm not sure i would recommend anymore i wouldn't use the built-in unity networking stuff or go with something like mirror or one of the other um one of the other networking options out there the built-in stuff the u-net stuff is deprecated and it's going to disappear eventually they pulled it out once and like kind of put it back in because it broke a bunch of things but i wouldn't i wouldn't start using that as your base go with something else let's see could you in the future keep working on a project like this and teach us how to optimize everything um yeah i'm probably not this exact project but i definitely could do something like that hey what's up jibril just saw your message hey thanks man i'm having a great weekend man i haven't having a blast um just coding i took the week off for the most part haven't done much and um just dove in and being able to just write code and have a blast of stuff is too much fun just making games um send message versus unity events i never ever use send message i do use unity events in especially in game play design areas i did a video really recently on unity events versus events and i highly recommend checking that out if you're not familiar with events or unity events if you're not familiar with either one to know about them both and see like kind of where and how to use them there's a lot of really good use cases for both of them um let's see he's got first professional game dev job next week that's awesome um i'd be nervous too but it's going to be nervous but fun just make sure that you don't like uh overbook a lot of other things because your mind's probably going to be overwhelmed with stuff going on so you don't want to have um too many other things popping up right like going on in your life when you're starting out that new job um oh somebody wants the inventory system that'd be a cool one to build um and okay uh i think we're starting to write our message um and i'm definitely not an aquarius um how do you feel about using visual scripting i am well i don't particularly like to use it myself for things because i feel like um i can do things a lot faster a lot more efficiently by writing code i like visual scripting systems to allow designers to do light customization and light control over stuff but that's about it i try not to use them for whole game systems just because i feel like it makes makes it harder makes it harder for me to comprehend and understand things if you're not familiar with coding obviously then that's um not not always the case um let's see okay i i'm you know i'm out of breath and there's there's a lot of questions i don't have any any more good answers to anything so i'm gonna wrap it up here and just say thanks again to everybody and we'll definitely do this again um if everybody wants to see this again whenever we get like 2 000 likes or something i'll do the next one it's not like a good plan i don't know i'll do it really soon though i'll start another do another video and either um extend on this or maybe build something different so i'll put in a i'll put up a poll and see if people want to extend this thing out build some more stuff on top of it or if you guys want to go through building like a different type of game and go through that process anyway um thanks again everybody for watching i really appreciate it don't forget to hit the like subscribe and especially the share button if you just go share this on whatever thing that you share stuff on it makes more of a difference than anything else really appreciate it again all right thanks everybody i'm gonna go get a drink before i pass out bye
Info
Channel: Jason Weimann
Views: 86,754
Rating: undefined out of 5
Keywords:
Id: RCUC5-lbb2g
Channel Id: undefined
Length: 162min 30sec (9750 seconds)
Published: Sat Nov 21 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.