How to make Your First Game TODAY! - (Unity 3D)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all of the stuff you see here are video games you will be able to make after watching this video making games is becoming easier and easier so you can literally make all three of these games today even if you're a complete beginner and I'm gonna show you how first of all we have to download unity so head over to unity 3d comm find the download button which shouldn't be too hard there are three different versions we're gonna go with personnel because this version is free honestly there's really no big difference between the three versions as long as you're not making more than 100k per year with your games that's pretty much the only restriction there is but let's be real we're not gonna hit that all that quickly so hit download or try personal or however the button is called during the installation process you will be able to choose which packages you want to install certainly doesn't hurt to check the following five unity documentation Android build support Linux build support and WebGL build support but honestly doesn't really matter as long as unity is checked you're good install install install this is the first thing you should see when you open unity just press the magical work offline button in case that doesn't work you might just want to create a unity account really quick we want to make a new project let's call it first game experiments or something like that let's keep this on the default 3d select a nice location and just click on create project this will take a couple of seconds this is what you should see once unity is open the interface consists of multiple windows you can drag these windows around if you want for example I could put that one over here or I could pull it back here you can change the size of these if you mess this up at any point in time you can go to the top right here where you can choose between different layouts just recent default and everything will be back to normal let's talk about what all of these windows do real quick down here's the project windows are basically the entire folder structure of your project all of the resources sounds scripts graphics your game has everything comes in here here's where you can create new folders and then when you click and show Explorer all of these folders really exist so this is basically your project folder and you can manage that right here from within unity this right here is the higher a window here you can see all of the objects that are currently in your scene at the moment that should only be the main camera and the directional light if you double-click one of these objects the camera will move towards that in the scene just clicking once is enough to select it though so we have one camera and one light and then you can see whenever we select something over here in the inspector window we can see all of the components and all of the scripts that are attached to that object so here on the camera object we have a transform every object in the scene has a transform because the transform just specifies the position the rotation and the scale of the object and then the camera also has a camera component so basically the camera script that is responsible for rendering and all that sort of stuff in an audio listener so the inspector window over here is just really for having a closer look at the selected object this right here is obviously the scene view so here you can see all of the objects you have in the scene if you press the middle mouse button you can move the camera around if you press the right mouse button you can turn the camera and look around and also if you keep the right mouse button pressed you can use WASD to move the camera around just like in a first-person game if you press the Alt key you can rotate the camera with the left mouse button and you can zoom with the right mouse button and you can still move the camera with the middle mouse button definitely make sure you get familiar with these camera controls right here because you'll have to navigate around here quite a bit here we can see a little cube that shows us where the XS are so this the x axis z axis y axis by hitting that cube in the center right there you can switch to isometric view in case you don't know what isometric view is this is a cube in perspective view and this is a cube in isometric view so all of the sites become equally long and objects always have the same size no matter how far they are from the camera you can toggle that on and off by clicking again and you can also rotate the camera in 90 degree angles by clicking directly on the axis there are three more windows right here at the moment they are hidden for one down here it's the console window here's where all of the errors and debug messages will appear once we have coded something make sure all of these little icons here town otherwise you won't be able to see warnings and arrows make sure to check this window every once in a while especially when something doesn't work as intended up here we have the game window so this is how the game will look like what's the difference between the game window and the scene window let me show you real quick the game window basically just shows what the camera sees so if we rotate the camera right here for example the game window changes so so this game window right here is what you will see once we hit the play button and then we also have the asset store right here where you can download assets and scripts we don't really need that at the moment we can close that tab once again if you accidentally close a window you can bring it back here with Windows and finding the correct thing or just once again clicking on the default layout and bringing everything back to normal now let me show you how you create a new object to create a new object we click on game object and then either on create empty so this will create a game object that just has a transform and we can add behaviors and scripts ourselves or we can also create a game object it already has some stuff on it we're gonna do that right now we're gonna choose 3d object cube now we have a cube in the scene try moving your camera around that a little bit try to practice that and then have a look over here the cube has a transform component we can change the coordinates here or we can also change the coordinates and seen right here if you want to move an object you can choose between different modes this mode is for moving the object this mode is for rotating the object this mode is for scaling the object this mode is for scaling as well and then this mode right here combines all of the handles allows you to rotate move and scale the object you can also create an object by right-clicking into the hierarchy and selecting either empty or whatever you want to create then here the mesh filter and the mesh renderer is really just for rendering the mesh and then the box Collider so the object can collide with other objects if it doesn't need to collide with other objects you can remove that one for now we absolutely do want this to collide with other objects so let's leave that in there also note that you can switch between different edit modes with W E and R that should definitely go to a muscle memory because that makes things a lot easier w e R it makes it a little bigger so we can use it as a ground now if you look in our game view we can already see the plane let's move the camera a little closer now if we click play we can see this window right here so at the moment the game is running nothing's moving so we don't see that the games running while the game is running you can still do stuff and this is actually pretty dangerous for example you can still move this around make a lot of changes edit your game same when the game is post you can still do all sorts of stuff the only problem is these changes are not permanent you need to be very careful with this make sure you stop the play mode by pressing the play button again and if you do that you can see everything goes back to the place where it was when you started play mode do not I can't stress that enough do not make a lot of changes while play mode is enabled all of that work will be for nothing none of that will be saved you can do so when you want to try stuff out it's great for that because all of your changes will be reverted but don't keep working on your game while the play mode is still enabled in fact I would advise you to go to edit preferences colors and then change this color play mode change let's change that to red so we get a really clear and obvious warning sign when play mode is activated now if we hit play mode everything will turn red this way we know ok damn I should not make any changes here as I said you still can can still move all of that around but once again once you stop play mode everything will go back to normal now let's make something that actually moves let's just create another cube and to this cube we're gonna add a new component a new script if you will for that we just select the cube if it's not selected and add component this button right here and then search for rigidbody pop this means this is a physics object when we click play now this cube will fall down I know not that spectacular but now if we duplicate that object with control D and create a couple more cubes maybe stack them on top of each other like this we already have a very nice physics simulation and we can see stuff moving on the screen very nice so this is already something that's kind of fun to play around with cool you can do the same with balls by the way just create a new object right click here create sphere here we go no this is basically flying frozen in space if we want this to fall down as well we need to give it a rigidbody not a rigidbody 2d because we're not making a 2-d game but a rigidbody so now this wall should fall down as well cool yes if we add a couple more objects this list will soon be pretty damn long which is confusing the way you clean this up is we just create a new empty object call this however you want to call it and then we can just put everything in there here we go all of the cubes for example and this way it just looks a little more clean you can open and close this like this really doesn't make a difference still looks exactly the same when you hit play just a little more clean also has the advantage that now you can move all of these objects at once you can activate and deactivate them all at once basically every object has a little checkbox right here with that you can activate and deactivate the entire object and another cool thing I want to show you is this is also the way you can make these objects a little bigger and give them additional colliders for example I can duplicate the sphere and now I can drag this sphere into this sphere now all I need to do is remove the rigidbody from this fear from sphere one from the child so the objects inside these objects are called children and obviously this years called the parent so only the parent needs the rigidbody but in here we can add a lot of cool stuff we could even add another cube if we wanted let's do that nice now we have a weird-shaped thingy let's rename that to worm and now we can duplicate that as well if we want maybe make a new folder here by creating an empty object making sure this is directly in the hierarchy and dragging all of our worms in their worms let's see how this looks in action hell yeah another project by the way if you want this to be maximized whenever you hit the play button just click maximize on play here in the game step and now when I click play this will be a little bigger now if you think this is still not clean enough you could even create another object call it something like physics objects and put your objects in there so this is how you create these parent-child hierarchies that make handling and dealing with a huge amount of objects a lot easier now let's say you want to give your objects a different color the way you do that is by right-clicking into the project folder create and then material gonna call this one material one now in the inspector you can see the material properties only thing we want to change right now is the albedo color this is my reference just gonna pick this color you can duplicate these we with control D as well I want to have five of them so I can just copy those colors here here we go now I selected some nice colors let's put all of these materials into a folder to just keep it clean let's call the folder materials select all of these drag them in there now you can basically just drag these materials on these objects or if you don't do that one by one you can also just select all of them for example I can select all of the cubes and then here in the mesh renderer if you open materials this lot right here element zero is where you drag in the material and with that you can color all of these at once then we can give the ground a different color once again now let's select all of these objects in the warmth make all of these yellow Iguala we have some colored some colored objects hell yeah you can see that was already a folder in here it's called scenes and this is probably the scene you're in right now if you double-click that you get asked if you wanna save the current scene because this scene will be loaded so yes we want us F that scene but actually the scene is exactly the same so nothing changes when you double-click it if you create a new scene here we go we can rename it so this could for example be a different level or different part of the game if you double tap that we're in a completely different scene all of the objects from the other scene are gone we only have our camera and our light but obviously you can go back to the old scene any time here we go maybe you wanna create an object in scene number 2 voila now we obviously need to save that scene for that we go to file save scene also makes you sure to hit save project every once in a while best practice is probably just doing both save scene and save project save scene really just saves the objects and the current scene save projects basically save some project settings and objects that are here in the project folder save scene probably even a little more important though ok let's get rid of all of this crap right here let's just keep the ground plane makes it even again by entering 0 0 0 into the rotation then I'm gonna create a new sphere give that a rigidbody and now let's write our very first script and let's make a new folder for scripts don't worry about the prefabs folder by the way you didn't miss anything I decided to cross that from the video because prefabs are going to get a pretty big overhaul sometime soon and we do not need them for the rest of the video then you right click into that folder click create and then you click see sharp script let's call it at constant velocity now if you double click that a text editor will open for you it's probably gonna be mono developed for me it's a Visual Studio doesn't make a huge difference for now and this is what you should see first thing you should check is that this string right here this name right here needs to be the same as this one that's the name of your file otherwise you're gonna run into problems to always check whether this string the same as this one right here most of the stuff you see here is stuffy we can ignore the only two important portions this one and this one use this for initialization all of the code we write in here will be executed once at the beginning everything we write in here update is called once per frame will be called once per frame so that's about 60 times per second 100 times per second depending on how fast the game renders so this is not a fixed time interval depends on how good your graphics card is but this will be executed constantly so far we didn't write anything in here anyway we can still attach the script to objects just like these components right here so you can find your own script at constant velocity Z I could add that right here if we click that small gear wheel we can click remove component then it's gone again and another way to add it to your object is just to drag it on here there we go so all of the things that are already on our sphere object right here are basically scripts that we didn't have to write ourselves right this one is one we're gonna write ourselves in order to make our object move we need to communicate with it with this script right here with a rigidbody that's the script that handles all of the physics simulations so we need to contact that script the way we do that is we write get component they make this weird bracket right here and write rigidbody then you open close a bracket don't worry about all of that too much yet you'll get used to the syntax as you go all you need to know for now is this returns the rigidbody of this object and now if we write dot we can see all all of the things we can do with that rigidbody all of the variables all of the functions this object has the one we are looking for is just the velocity and the velocity is a vector so the direction and the speed the rich body is moving in in case you're wondering how our vector looks like a vector basically looks like that it has an X component a y component in the Z component so this basically just makes it's the horizontal speed to do the vertical speed to 10 and then the speed in the z axis to minus six so the z axis is this blue one right here the way that looks when we launch the game is nothing because we need to save the script first now it's recompiling now if we click play you our ball flies away into this specified directory so let's just try to make it move only into the x-direction okay so we're gonna set Y and C to zero now it should only move on the x axis in theory let's see if that works yes it does but it's also not falling down anymore and there is a very logical reason for that it's because we're setting the velocity exactly to this vector that means whenever our object starts falling down this Y velocity usually gets a lot higher but we also reset it to zero so it can't start falling down what we can do about this is just changing this equal sign here to a plus equals so whenever you write an equal sign encoding that means we set this variable to this value so the velocity of this rigid body will be overwritten with this vector if we write a plus equal sign that means we will add this value to this meaning the X velocity will get to higher every single frame that will obviously be a little too fast so let's lower that to 0.1 and then we need to write an F to indicate that this is a float value so whenever you have numbers like that that contain a dot probably need to write an F after that there are different kinds of variable types different kinds of numbers and we just want to tell the program that this is our normal float number so that's why we need to write the F okay now it's falling down again very nice now putting that into the update function is a little risky because we do not know how often the update function is called so if our game is running faster the ball also speeds up faster because every time a frame is rendered we add something to the speed that is obviously a problem so the your game will basically run faster on faster machines that's not what we want at all so what we do for now is instead of coding everything into the update function here is coding everything into the fixed update function and fixed update is called exactly 100 times per second we can rely on the fact that this will always run with the same speed it's always good to code physics stuff into the fixed update function now what we want to do is reading a little settings window right here where we can specify the speed of this object we want to be able to change this right in the editor we don't want to go into the script every time you want to change the speed of this so let's just write vector 3 so this tells the program which kind of variable we want to have and now let's name our vector you can name that whatever the hell you want but usually it's a good idea to have a little indicator at the beginning of the variable which kind of variable this is so you can see that more easily later on I'm gonna call this V 3 force then just make a semicolon never forget to make the semicolon at the end of the line I forgot to mention that earlier there needs to be a semicolon and of course if we want that to be modifiable from the editor we need to make these brackets right here and write serialized field this serialized field attribute will apply to this variable now if we go into the editor we can see our variable appears right here and we can modify the variable right here in the editor now all we need to do is replace this vector down here with our new custom vector that we can modify from the editor we don't need to start even so we can delete that clean this up a bit here we go so this is our very first script all it does it is just applies a constant force to your object and you can change that force right here in the editor so let's make a couple of experiment if this works let's for example that the first to 0.1 here we go goes to the right now let's set it to minus 0.05 now it should go to the left perfect enter 0.2 yes it's able to overcome gravity now it's going upwards and all of that obviously also works in the C axis perfect our first script is hereby done next thing I want to do is make the sphere controlled by the player for that we're gonna need a new script let's just duplicate the one we already have let's rename that to add player controlled velocity I'm gonna copy that name and double click that so now it's open here and then remember to replace this with at player control velocities or it has the same name as the file and now I just want to add two more C realized variables two more of these serialized field this time the variable type is key code so a button let's call this one key positive let's duplicate that and call this one negative now if you save that script let's remove that component and at this component at player control velocity we should have a force vector right here and then we should be able to choose a positive key and a negative key and now the way I imagine this will work is I can say I want this object to move on the x axis so I'm gonna put a 1 here then we could for example choose let's choose right arrow for positive and then go with left arrow obviously this doesn't do anything yet what I want to do now is just add a new if statement if statement looks like this you write if then you open a bracket and you close a crackit input dot get key then we open another bracket and close another bracket and in those brackets we write our variable key positive then go one line down here press stop here we go so now this force is only added if we press the positive button let's do the same with a negative button only difference when we press the negative button we don't want to add the first we want to subtract the force this way we can move in both directions very simple script should work out just fine let's give it a go all right it's a little fast but I can now control the ball to the left and to the right let's make it a little slower 4.2 yeah that feels nice obviously you can also use a different axis the C axis for example let me move diagonally if we move the X component of this vector we're just gonna move vertically so basically if I want this ball to be controllable in all directions what do we need to do we're just gonna keep it like this and actually can add multiple of these components onto one object so that's exactly what we're gonna do just at this one more time and do the same thing for the C component and then select the according buttons on the keyboard up arrow positive down arrow for negative so now we have the X movement and the C movement now I can move my ball in all directions hell yeah so I'd say it's time to build the first small level cause why the hell not this tutorial is all about experimenting and having fun though feel free to mess around with this stuff as well okay now let's adjust the camera so it can see everything that's going on let's see if getting up here is possible okay yeah but you've yeah next up I want there to be a way to restart the level because at the moment if I mess up the only way I can restart is by pausing the game and pressing play again that's a little annoying so let's make a restart button real quick for that let's just make a new script and let's call it restart level with button all we need is a serialized field with a key code it's called a key restart we don't need the start event cleaning this up a little bit by the way whenever you make two slashes like this you can write a comment this will not affect the code at all after two slashes so we you can delete that sort of stuff no problem at all now how do we check if the button is pressed or just once again ask in put that get kee-kee restart now if all of this is true if the button is pressed then we want to restart the scene for this we actually need to add something up here using unity engine dot scene management and then a semicolon so this is just a package of scripts we can use and the scripts we wanna use happen to be in this package and not in those three packages so we just need to add another one now we can write seed manager dot load scene open bracket close bracket and then we want to load the scene we're in right now I see me wanna load goes in here so usually your text editor should show you what you need to write into those brackets sometimes you can write different things in there you can switch between different versions by clicking on these arrows right here we're gonna go for the string so which scene do we wanna load scene manager get active scene returns the scene we're in right now problem is this function doesn't take scenes as an input putting a scene in here is not an option that we need to add dot name this way we have an acceptable input for this function basically everything that has these brackets after it is a function by the way okay that's the script let's save it and we couldn't put that either on the sphere I'm just gonna put it on to the camera because we only have one of these yeah you know what if you want to keep it super clean just make a new object and you empty object and call it something like game manager and then let's our at our restart level with button script onto that I want to be able to restart the level with the button our here we go save seed so now whenever we hit our level is restarted next up I want the camera to follow our little sphere here so we can build bigger levels one of the easiest ways to do that is just to align that to the ball somewhat properly and then take the ramp camera in the hierarchy and drag it into the sphere also let's rename the sphere to player now the camera we'll follow the sphere there's only one problem and you'll see that it basically also follows the rotation oh my god this is horrible to look at so there is a somewhat easy fix to this if you click on the player on your sphere take the rigidbody component you can see this this one has some settings here as well if you open this down here constraints we can just freeze the rotation though this object is no longer allowed to rotate this way our ball doesn't rotate and our camera doesn't rotate either the problem being the ball doesn't rotate anymore so if you want the ball to rotate we need to find a different solution and for that we can just write a simple script let's call the script copy position and we can write that right into the update even right here we don't need the fixed update even for that fixed update is only useful for physics based stuff for this one it's totally fine if it's just called whenever the frame is rendered all we want to do is copy the position of an object so we're gonna write serialized feed and then the variable type we want to have this time is a transform I'm gonna call this trans target let's at that script right here now I can drag the player object in here and we will automatically get the transform component of this object so see this player object has a transform the transform is the one that stores the position the rotation and the scale and on our camera we now have the reference to that transform meaning we can now say transform dot position equals trans target dot position transform obviously is the transform of this object trans target is the transform of our target object so we will just copy the position of the target object very simple script we're already done now there's a little bit of a problem with that I'm gonna show you if we hit play now the camera is obviously inside the ball because we're exactly at the position of the ball in order to fix that we're going to create an empty object for that the same position as player here we go let's call this camera rig and then let's drag the camera inside our camera click camera Creely just at the moment is an empty object then we can remove the copy position script from the camera and put it on our camera rig instead then once again we obviously need to get the reference to the player transform in there and now this object right here the camera rig will always be placed where the where the player is and that means the camera will always be at a position that makes sense because see if I move this camera rig right here the camera moves along with it if this camera rig follows the ball then so does the camera you know we can obviously unlock the rotation of the rigidbody we can allow this ball to rotate again and now we are able to build a much larger level if we want let's do exactly that here we go let's hit play okay haha I did it next up let's make the game restart automatically when the player falls down there's really no point in not doing that let's just make a big surface down here here we go so let's duplicate our restart level on button script and let's call it restart level on collision now remember we need to change the name here as well we don't need that key what we need is a different event because this is not supposed to have an every single frame this is only supposed to happen whenever this object touches another object so if we need void on coalition enter then we just put our scene restart script in there and delete all of the rest here we go let's save that now if we put that very script on to our lava ground right here we start level on collision now whenever we touch that ground the level should we start in fact it works haha that's fantastic there's one problem though if I add another cube here and let's give that cube a rigidbody if this cube touches the ground I lose as well so this is not exactly what we want so how can we differentiate between those two objects there's a very simple system for that in unity that helps out with that let's give this a new tech oh there already is a player text so we could use that one but we could also create a new check by clicking on add tech then creating a new check right here so we're just gonna go with a custom player check here we go and then to our restart on collision script add a new variable there last huge string so string is basically text call it string tag and then we only reload the scene if collision that collided technique wills the tech we want to check only then we restart the scene in this very first line of these events these functions you can see which inputs this function has so this entire thing is a function as well and it has this input coalition and we can use that input in here so collision in this case is just some information about the object that touched us about how we collide it exactly and it also happens to contain the tech of the object that we had so we can check that right here if it's the correct check we're gonna restart the scene now let's say this one checks for the tech player this one doesn't have the tech player of this object right here this object right here does have the tech player so now pushing that box down there shouldn't do anything but falling down there myself we'll restart the level great time to build something [Music] all right I took some more time to finish this level up just continue building some level design elements back here also I added these stripes to the ball which are parented spheres see basically just a flat sphere that is a child of this sphere and I also removed the collider of it really just one those stripes to be optical nothing that interferes with the gameplay and also another big thing I did is I added some post-processing to the camera I can see that here this is how it looks without post-processing this is how it looks with post-processing just looks a little bit nicer but that something we'll have to say for the next tutorial for now let's export this for that click on file build settings then make sure your scene is in here scenes that you want to be included in the world just drag them in here you can also enable disable them like this at the moment there is no way to go to the second scene anyway so everything's fine and then let's just click on build and run and that should build and run our game we also need to specify a build location for that I'm just gonna go with the desktop for now then we'll have to wait for a second here we go if the build is complete and you launch the game you will see this window just click on play and we can play our game here's one issue you might run into if you make multiple scenes when the level restarts it suddenly looks way darker the way to fix that is just to go to Windows rendering lighting settings then uncheck this Auto generate button and just click on generate lighting that will take a second when that is done this issue shouldn't occur anymore when restarting the scene here we go problem solved so here we have another game I made using the exact same scripts it's a 1v1 game you can play against your friends one player controls with the arrow keys one player controls with WASD whoever pushes the other one of the platform wins and again just restarts so I challenge you to make this game as well you don't need to write any new scripts for this it's a good exercise try to make this game here's something completely different but still using the same script so you don't need to write any new scripts for this the goal is basically to get this block out of there and you can move the purple blocks left and right and you can move the orange blocks up and down so yeah you've just gotta be creative there's already a lot you can do with this and I challenge you to build this game as well a little trick you need to know is you can change the camera perspective between orthographic and perspective on the camera for this really cool casual look you just need to turn it to orthographic remember that you can freeze the position and the rotation of a rigid body on certain axis in the settings of the rigid body that is definitely useful for that other than that you should absolutely be able to create this without writing any new scripts in the next tutorial will expand on all of that even further writing more cool scripts you can play around with bringing enemies into the game making games that have multiple levels but for now I'm really happy I managed to get you to a place where you can start experimenting yourself there are already so many creative things you can do with the scripts we have so far what if the player could control multiple objects at once for example you could make a co-op puzzle game your player is only allowed to touch blue blocks and player B is only allowed to touch green blocks maybe you can't control the player directly maybe you can only control objects on the level you could build a giant labyrinth or a massive collapsible castle out of rigid bodies be creative and the joy of game development starts now [Music]
Info
Channel: Jonas Tyroller
Views: 1,087,531
Rating: undefined out of 5
Keywords: unity tutorial, how to make a game, how to make a game in unity, make a game, unity, unity 3d, unity 3d tutorial, tutorial, for beginners, make a video game, how to, c#, coding, game development, tutorial for beginners, become a game developer, get started with game development, get started with unity, easy, fast, fun, for free, free game engine, make your first game, make your first game in unity, code a game, in unity, basics, introduction, guide, programming, course, learn, beginner
Id: pCBqgREiSUE
Channel Id: undefined
Length: 39min 6sec (2346 seconds)
Published: Fri Oct 12 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.