How to make a Tower Defense Game (E09 MISSILE LAUNCHER) - Unity Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
do you know that feeling when you make an entire video and forget to hit record that feeling is what we begin with today thanks for tuning in at break ease so hello everyone I will consist video and creating a tower defense game in unity today we are going to be adding new coulthard to the game it's going to be a missile launcher we'll begin by importing the model will then be setting it up with the turret script in order to make it point towards and shoot enemies and finally we'll be implementing it into our our UI so that we are able to select it and place it on the map one thing that we will not do today is kind of changing the bullet to allow for explosions so that we will damage players in the radius and have explosion particles and all that that is for a separate video so without further ado let's delve right in to it so you can see that I'm in unity and basically what we want to begin by doing is finding some cold model to use for this chart and you can of course go ahead and create your own or you can use one that I've provided for you here on the D tower defense assets pack this is available at patron under one of the posts you can download it here if your patron are not completely free and I will of course have a link to it in the description however now that you are here you could choose to become a patron that means that you will support me with a monthly donation it gives you some cool rewards and also helps me create a lot more awesome stuff more stuff in the assets on in the assets pack more cool videos the next goal is live streaming and a game math essentials or course arm which is going to be super cool so please do that it's of course 100% optional and without further ado let's actually get to the video part here so when once you've downloaded this assets pack and unzipped it you will get this folder called the tower defense assets pack and if we double-click this you will see two folders on the models and missile launcher we have three files which are the ones that we are going to need in this video the first one is the missile launcher blend this is if you have blender installed and want to be able to edit it you can simply open this up in blender and you can also import it directly into unity if you do not have blender installed there's also an FBX file which works either way and a missile launcher texture to use with one of the two model files so I'm just going to be using the missile launcher FBX and the texture here so make sure to select both of them and then we can drag them into unity however let's just make sure that we have the correct folder structure here so under our imports let's create a separate folder for our standard turret and drag our materials and turret undo that and let's create whoops not sure and Explorer let's create another folder which is going to be our missile launcher this is a really great thing to do have one folder for each import because if you import everything into one folder unity will import a lot of materials into one folder that it generates called materials and that there can be like hundreds of materials in there and you might never notice that you're not using them and they will just clutter up the project and it's a whole mess so this is a really great thing to do and now we can just take these two files and drag it under that folder and you can see here what I was talking about these are the generated materials let's select the missile launcher and get rid of those by disabling this import materials and now we're able to simply remove this folder and it won't come back then what we can do is we can drag our missile launcher into our hierarchy make sure it's centered and let's focus on it by hitting F and shifting away from the 2d tools you can see that this is currently quite large so let's just bring up a reference here in size by dragging in that standard turret and let's our reset this as well and we'll have it be 0.5 on the Y and let's just drag it over here using holding down ctrl to snap it to the grid now you can see that this is way too huge so let's select our missile launcher and chillz this change the scale factor here to something like 0.5 and everything else looks fine so that's it apply on that and you can of course also go ahead and disable regen animations here but there is no animation on the take so it might not be too important so you can see now that it fits in scale but we still need to set up a bunch of materials so to do this let's first actually take our missile here and just drag it out and don't mind that it will break the prefab instance that is fine just to continue on that and let's just disable the missile and focus on the launcher itself so the first thing that I want to do is just bring this launcher up to actually stand on the node and let's just do that by setting the Y to 0.5 just as with our other turret but you can see now it currently floats a tiny bit above the node and to change this what we do is we select our stand and our turret and just drag these down until they are barely touching the surface it needs to just rest on the node so it does that right there and that is fine thus we are preserving the Y value of 0.5 on the missile launcher itself cool then on the stand here that is called base on the other models let's rename that and the turret here we'll call that the head let's just drag it up there so it makes sense and now we need to add some materials so you can see both on the head here and on the base there are two materials added and both of them are currently using the default material and this is because both on both the head and the base have a primary color and an an accent color or a secondary color so let's create these let's go create and let's add a folder for these materials and let's right click and create a material here and we'll call this the missile launcher and then we'll call this the primary and let's duplicate this and call this one the secondary and the primary we will make kind of black will adjust it in the second and the secondary we will make red then we can take the primary color select the head here and drag it under the second slot so you can see that fills up most of our head here and we can do and then we can take our secondary color and drag it into the first and you can see it fills out on the actual tip of the barrel here and then and we'll do the same with the base the primary on the second slot and this secondary on the first slot I know that defies logic but that is fine it really doesn't matter cool so these materials are not looking great let's compare it to our other turd and make it look somewhat like that one you can't go ahead and use exactly the same colors but I like tweaking it to fit this particular instance after all it is two different turrets so let's change the albedo here firstly to something a lot darker and let's bring up the metallic miss quad a bit and take the smoothness on down just a tad I think that looks pretty cool then under our secondary color here I want this to shine very brightly red so in order to get more saturation in here let's bring up the metallic miss and we can bring this up fairly far and the smoothness down just a tiny bit I really like the feel of that yep I think that looks super cool again spend more time on these graphical things than I do I just don't have time to tweak and and do all that sort of stuff in the video so I'll just continue here but feel free to spend more time and also feel free to not only use two colors you can of course have different materials on the head and on the base and you can also go in and create your own textures should you want to do that so let's just rename this to missile launcher in one word and let's now add to the base of this to the missile launcher object let's add a D turret script and we'll just change the range here to something a far creative something like 30 and the fire rate to something like point two five that means it will fire one bullet every four or one missile every four seconds and then we have some unity set up fields here we have the enemy tag which is the same then we have the pot to rotate if we look under your standard turret we had this empty object called pot to rotate that basically allowed us to change the rotation of our head here in such a way that we make sure it always points in the z-direction let's do the same here because currently our head points in the negative X I believe this is yes it does and our Z is pointing upwards so let's create an empty game object under the head and let's reset that so that will be centered at the pivot using the local axis here make sure you set the pivot and local up here reset that there then we can drag it out rename this one to part two rotate drag our head under the part to rotate and and then we can take our head and rotate on the and let's see what we are going to need here actually wait wait wait something is wrong okay so let's drag out the head again here we need to rotate this of course to point in the right direction here so that's 0 on the X here and let's do negative 90 on the Y there we go so now this is pointing in the right direction and then we can take our head and drag that under there so now when we select our pot to rotate or on our actual graphic is pointing in the Z direction cool and then we can go in here and we can right click create another empty and this is going to be our fire point so let's call this fire point and we can maybe just shift to the side view here shift to isometric view by clicking in centre there and let's drag this up and out to make sure that this is centered and we'll have it be spaced a bit out just so we are sure that the missile won't overlap with our model and clip through it and it will look kind of weird so now on a missile launcher we can take our pot to rotate and drag it under pot to rotate we can take our fire point and drag it on the fire point and finally we can take our bullet prefab and drag it under bullet again now in the next video we are going to create a separate bullet prefab which is going to be a missile prefab and that will have its own graphic and its own settings but for now we'll just use this standard one then we can take on this missile launcher and turn him into a prefab let's uh click and drag him into the prefabs folder to turn him into a prefab and we can now remove these two turrets from this scene the last thing that we want to do is now integrate this into our UI so we can select the turret and actually spawn it into the scene and that is very easy to do with this way that we have things set up right now so if we go into our canvas shop you can see that we have a standard third item and we can focus on this by hitting F and then shifting 2d 2d tools there and we have another chart item and all we want to do is simply instead of having this be another turd actually make this a missile launcher item and we need to change the icon we'll do that in just a second and instead of calling purchase dot another turret we want to configure our shop script to have a function called purchase missile launcher so let's just um click here to go to our shop object double click on a shop script open it up in visual studio and all we really need to do here is a tiny bit of renaming so if this will just get done loading that's the build manager the shop here you can see we have this method called purchase another chart we just want this to say purchase missile launcher it's not going to make any difference for the end user but it is good to always make sure that your naming is correct so purge or missile launcher selected and you can see that this uh calls set toward to build on the build manager and uh it our inputs build manager and not deterred prefab and therefore we want to find the build manager it's under the scripts folder I already have it open here and we want to go here and rename this instead of another turd prefab to missile launcher prefab and the way that I'm doing the renaming here is by hitting ctrl our control R so control RR if you want to be quick about it you could also go right click and then rename in some IDs it's called refraction and that will just make sure that we rename it both here and under the shop there nothing else you can of course rename it manually and that just what's all the coding that we needed to do it's already in there we just need to add a function each time we add a new turret and add a prefab each time we add a new turret cone so now that we've renamed this method we need to relink the missile launcher item button to that method it's lost its connection because of the renaming so let's find our missile launcher item let's go into the iron click event and you can see it still has a reference to the shop but it's missing shop that purchase another turret so let's change that to shop duck purchase missile launcher and now that should actually be set up finally we go to game master and we can see that we have our missile launcher prefab in here we want to drag our missile launcher prefab there we go and the final and this is the very final thing that we want to do is change the icon to something more fitting and in the first video where we implemented the UI here we discussed how you can go about creating some icons of course already created an icon for you if you don't want to go through that so again go to the assets pack instead of going on the models we go and do sprites and we find the missile launcher icon that's also a PSD if you want to edit it and we just drag it on your project panel change the texture type to sprite and the format to true color you can change the max size to 512 but it won't make a difference it's already 512 and hit apply and now we can see it has a transparent background and all we need to do is select our missile launcher item and drag our missile launcher icon under that slide and we can maybe just make a new folder here since we now have a lot of icons called icons and we can also drag our two scripts on the D scripts folder and everything looks so clean now and you might think that this icon is a bit too large you can either go in and edit the icon file or you could just go down here and change the preferred width and height height to something like 90 and I think that fits much better so that was basically all and now we are ready to play test so let's hit play and see if this is working firstly we cannot click anywhere then we select our standard turret and he should work yeah there we go he is then we select our missile launcher and click there and you can see that it's in the game and the fire rate is a lot lower and you can also see that the range is a lot higher than with on the standard turret it's now exactly double as as large a range so that was all I wanted to show you in this video I hope you found it exciting I definitely did the next one will have a look at some explosions which is also really really fun so without further adieu thanks for watching and I'll see you in the next video thank you so much to all of the awesome patreon supporters who donated in July and a special thanks to vixen famous own Andrew K and locks game TV these videos wouldn't be possible without you
Info
Channel: Brackeys
Views: 98,658
Rating: undefined out of 5
Keywords: unity, unity3d, tutorial, asset, assets, model, texture, models, textures, material, materials, beginner, easy, how, to, learn, course, series, tips, tricks, tutorials, workflow, fix, tip, game, development, develop, games, programming, coding, basic, basics, C#, missile, launcher, turret, explosion, type, rocket, shoot, splash
Id: IMhRDTf9pBk
Channel Id: undefined
Length: 16min 43sec (1003 seconds)
Published: Sun Aug 28 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.