Unity Tutorial 2021: A beginner guide for idiots

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi so this video is quite long as it is so i don't want to waste your time here's what you need to know up front one my name's adam and i make a youtube devlog series about how i'm currently making a game two the fact that that game is a point-and-click adventure game is totally irrelevant to this tutorial video don't worry three this is me i don't know how to code i don't know how to use unity and i'm basically an idiot 4. this is jeremy he's very much not an idiot jeremy has almost finished both a sci-fi point-and-click adventure game called dexter stardust and a platformer sequel to that game both made in unity 5. jeremy has very kindly offered to teach me an idiot remember how to use unity 6. there will be follow-up videos to this one about how to set up and use the adventure creator asset for unity for people making a point and click adventure game but in this specific video we're just going to cover the real real basics so that's what happens when you first set up unity what each window does and means and then in a very basic sense how to make a 2d platformer we've done this tutorial as a screen share video course so that jeremy could teach me as i went along and so that you can follow along too i've done a really light edit but please be aware that it's not exactly as polished a video as you might find on skillshare we jump about a bit at times and make the odd mistake but here's the thing we're gonna go at an approachable pace there is no assumed knowledge here at all and it's free if none of that sounds useful to you then absolutely stop watching right now if however like me you're a bit of an idiot but want to learn the basics of unity go grab yourself a coffee or a cup of tea get comfy and follow along with us here we go so um before we talk about adventure creator it's extremely important that we know what unity does on its own because adventure creator has a plethora of features and it can be extremely easy to get lost in those features and then not really know what what's unity doing and what's adventure creator doing so today we're just going to make the absolute most basic platform game two scenes one will have a menu just we'll start the game and one will quit the game and then the other scene will be just jumping from platform to platform we're not even going to make a goal we're not going to make collectibles we're not even going to implement dying so if you fall off a platform you will fall forever okay so it's it's going to be extremely basic i have i shared a script with you i shared a player movement script we're going to write a script that changes scenes and quits the game and then we're also um going to you know work with like maybe like an animator controller and things like that but we're also but first we're just going to look at what unity does so let's this is the unity hub and do you know why unity has a hub and why you just don't open each file individually um like literally this is as far as i've ever got with unity is opening it and installing it and i think excellent so right there when you click on installs you can see that you've installed the lts which is i think it's like long term uh whatever it basically means that they they support that over the long term in this install you can see that it's the 20 20 point 3.2 um you can add another one so why don't you click add we're not going to do this now but if you click add you can see all the different ones that you can add there's some official release releases a 2021 release but you notice it's not lts yet so if you are not looking to give unity feedback because unity wants the thousands of developers that you know like like they're like okay we we need feedback on this on this on this release this beta release but if you're not looking to give unity feedback i would just stick with the lts versions yeah i think feedback is bit bit beyond my pay grade at this point so no worries but i i actually did have a version i used one of those versions unknowingly and i had like an issue with box colliders like changing nodes on a polygon collider or something like that so um you definitely want to steer clear if you're not looking to give them feedback so why don't you click x we don't need to we're not going to download a different version let's go to your project let's add a new pro uh do new and what we want is a 2d project yep and then why don't you just call it um block game yep very good and then choose the location um [Music] very good okay all right excellent create um here is unity so there's a lot of different things here we might notice that on the left there's the hierarchy in the center we have scene and game why don't you click on the game window uh yeah at the very top game oh sorry again very good so this is what your camera is seeing in the game okay so the difference between scene view and game view click back to the scene the the scene is actually where you'll be placing your objects just putting things into the game okay they're gonna go into scene view and then if you want to see what that cropped version looks like you go to the game view okay um and when you press play at the top the little triangle there's play pause yeah the game is playing but why is it why isn't doing anything well there's nothing to play so you can you can press play again and it will stop it okay okay um now you might also notice that in the scene view at the very top you have it says shaded and then to the right of that it has says 2d right yeah click click 2d and oh it changed to 3d mode right now you can do that that will not break your game if you accidentally click that you might think but i created a 2d game yeah it's true you did create a 2d game but you can switch between 2d and 3d view so you're not going to break anything okay so why don't you click 2d again we'll keep it to 2d and on the on the right we have the inspector the inspector shows the details about the component or the object that's selected in the hierarchy or in your project folder at the bottom of the screen okay now you can move all of these around actually why don't you try dragging the game the game window over to where the inspector is so now you can have it over there um so and then drag it back all right now here's another thing the game is in free aspect okay why don't you click where it says free aspect yeah i like to make my games personally in 16 by nine i know a lot of people choose an actual uh an actual pixel uh amount they'll do like 1920 by 1080. i personally this is personal and again people can disagree with me in the comments i find um but i do pick 16 by nine because it's the aspect ratio and you're not limited to a specific number of pixels okay does that make any sense so yeah my name personally is in 4k so that allows me to not worry about that so i i think that and the same thing with you i think it would probably be best if you chose 16x9 now you can zoom in you see where it says scale if you if you pull it up it'll actually zoom in the game view but you don't really need to do that you can leave it all the way at the bottom and then also mute audio that's something that might be good when you're when you're play testing your game you can mute the audio so the game just doesn't play any audio while you're playtesting it especially if you're hearing the same song over and over and over and over again you know okay project folder the very bottom you have the project folder you can see that there are scenes automatically created why don't you click on the scenes folder yeah yep so this is the sample scene in fact this is the scene that's open right now is your sample scene um yeah and actually is it possible to to to stop full screen mode because mac actually cuts something off so actually just make the the thing the full screen yeah that's better because we actually see it at the very top it says sample scene okay um now this was automatically created when you created your project another thing that was automatically created in this project was one thing a camera because you don't have a game if you can't see anything so the very first thing that is that is created by unity is a camera you can see that on the left now the camera look in the inspector it has a background you can change that background color let's change it oh oh oh that's because we're recording okay why don't you click the the actual in the color in the color area oh yeah let's change it to a nice uh purple color we'll give our our game a purple and yellow theme there you go wonderful love it get rid of that and now if you go to the game view it's purple okay so let's go back to the scene the scene view and let's click on the main camera again on the left yeah yep another thing that we see is its size the size is actually going you can you can pull it out and pull it in pull it out and pull it in um yep and you can see that size is changing so that's what you will use when you when you start placing things in your game to actually dictate the size of that camera okay now a component that you see on the camera is extreme that's extremely important is the audio listener do you see that uh show me it's pointing to me away sorry yeah so yeah i wish i could point but i can't yeah do you see on the k where it says camera in the inspector um yeah and then directly underneath that it says audio listener oh yeah that got it yeah so that means that that camera now can listen for audio if you were if you'd remove the audio listener there'd be no audio in your game okay so um the camera itself is listening for the audio so for example if if the camera camera's here and there's some audio playing over here and it's in a 3d space and you tell unity to use uh use the camera in a 3d space then it will play that sound as if it's over here not as if it's in the center does that make sense so you can kind of create like a panned effect yeah um another thing that's important is um where where do you see the z position look at the the camera as a transform at the very very top in the inspector uh yes and then its z position is negative 10. it has to be negative 10 when you're using a 2d camera or else it will not display what is being rendered because because click the 2d button again in the cv scene view 2d 3d you see that is actually it's actually negative 10 okay so you can actually see like the position of that camera if you were to change change the negative 10 to zero [Music] okay so if we were to put some sprites in you wouldn't be able to see them now they'd be invisible so keep that so keep that at negative 10. that that's one thing on your camera on your orthographic camera which is for 2d that you do not want to change okay okay let's click 2d so now we're going to um check one other thing out i want you to click on file at the top of the screen yeah and you see build settings yep build settings so that i know does not look um tools just tools uh i don't think so so this is where all your scenes are okay all of your scenes are held here so if you have a new scene you have to when you open that scene you're going to click add open scenes but we don't need to do that right now and then also when you're building your game you're actually making the application this is where you build it from and you can see the target platform is mac os you can change that to windows or to ios i don't know if you've downloaded the other uh yeah i downloaded downloaded windows ios and android i think as well as right so basically when you switch it if you switch it from mac os to pc to windows it's going to actually take if once your game is big it's going to take a little while to switch all those assets over that you've imported into your game to be able to be built on a windows computer so sometimes you know when you're switching making builds you know just make a switch it to windows and walk away for an hour okay i know i can do depending on how big your game is so then you wanna you you can click the x you can get rid of the build settings okay so very first thing that we're going to do is we're going to import some things into the project folder okay so why don't you click where it says assets at the very bottom on the like the project folder and why don't you right click and create a new folder create folder folder very good and we'll call it sprites okay good so why don't you drag and drop the two sprites i sent you i sent you a white square and a black square yeah inside all right very good and then correct another uh create another folder and call it scripts and i cannot type when people like it's okay okay very good so that that script that i sent you were you able to download it um downloads folder i am doing it now yep sorry oh no worries uh yeah downloads okay yeah and put it in the scripts okay very good so first thing we want to do is we need to create a player so why don't you open the sprites and let's drag in the white square just into the just drag it into the hierarchy into the hierarchy yeah okay now you might notice immediately that a sprite renderer component in the inspector is is placed on top of it right it says sprite renderer yeah okay you know that you can also add that component you see it says add component down hey yeah yeah so click add component and you can actually if you type in sprite [Music] so you can see sprite renderer is one of those components so had it not already been there you could just create a new object and then add a sprite renderer let's try that a different way go over to the hierarchy on the left and then the plus icon at the top of the hierarchy and click create empty whenever you create an empty child sometimes the transform's all all crazy it'll like give you crazy numbers and you can just reset it to zero but game object let's call this one player [Music] and we can delete the white square now because we're just going to replicate that delete it right click delete actually this is important if you change something in the hierarchy you can undo it if you change something in the project folder you cannot undo it okay okay so if you delete something from the project folder like if you delete a scene on accident from the project folder well go into your trash or if you're on a windows computer recycle bin go there and then just drag it back into your project folder because you permanently deleted it from the project there's no undoing okay um so we've got a player so let's add the component let's add sprite renderer sprite vendor yeah very good a couple of so let's now drag the white square into where it says sprite in the sprite renderer so from here up to here yes yep boom okay very good now a couple of things we might notice we notice that it's using the default material sprite default so sprite's default doesn't it can't do anything fancy like that you can't like respect a lighting system or anything like that so if you end up doing lighting systems in the future you'll have to actually change the material on all your sprites there is a way to do this in mass but we're not going to cover that now another important thing is the sorting layer you say sorting layer default that's fine but the order in layer so what is positive will be in front of what is negative okay so remember how we were talking about eventually will be layering your scene in in adventure creator yeah it'll be actually using this unity system of ordering layers so if you have your foreground it will be you know 20 and then your player will probably be zero and then what's behind them will be like negative 10 and then you can place things in the middle that to be in front of or behind him sure um okay now let's add another thing um actually let me go and just make sure that i'm doing everything right um sorry about this i'm actually going over to my own duplicate project here um okay very good so um we need to also let let's let's zoom in on the in the scene view we're going to zoom in very good zoom in as far as you can uh so i have lost where disables where's the zoom you could just um actually do see you can actually zoom i think if you just um you just are on your mouse two fingers if you're using a trackpad oh yeah okay yeah zoom in zoom out very good yeah why don't you zoom in yeah let's zoom in until we see that block oh there's that block and you're like oh that black is so small why is it so small well why don't we click on the white square in the project folder in the project at the bottom yeah so we see that the pixels per unit is a hundred but how how big is the white square look at it at the bottom at the very bottom on the inspector uh 16 by 16. so it's it's just 16 pixels by 16 pixels but we want to make sure that that sprite is bigger it takes up a full unit we we want to make us like let's say this game is like a pixel art game and we want it to be 16 by 16 blocks well do you see where it says pixels per unit on the inspector change that to 16. all right very good and then click a click out of the inspector and it'll click apply great oh now it's bigger and you can actually see now that it takes up a full unit do you see the the grid yeah so now it's the it's a complete unit so click um why don't we click the play button again so what sorry just as a question there why is it was set to 100 by default but why was why is 100 make it appear smaller than 16 okay so we're not changing anything in unity we're actually just changing how our sprites appear according to the the units the units that are displayed in the scene view so you see in the scene view the grid yeah one square is one unit one of those units before they that one of those units um equals a 100 100 pixels okay but we are actually telling our sprite okay for that 100 width we actually just want to say that that's that's 16 pixels so we're kind of like forcing the sprite into into the the determined unit by by unity yeah okay einstein yeah yeah it's a good question it's a good question instead of changing your project you change your sprites yeah okay so um let's do another thing um if you press play and start the game i just think it might take a moment there we go fancy that we have a square in the middle of the screen it doesn't do anything okay let's add some physics to it okay so let's um click the player i'm in the hierarchy and we're gonna add a component the component we want to add is called a box collider so search box collider box code to td or box collider box collider 2d yes all right so a couple of things here if you do not want if you if you want this this this box collider to react physically with the world meaning it's a solid object leave it as it is if you want this box collider to be a trigger you you you tick that is trigger box what what does the trigger mean basically basically games are just boxes interacting with boxes so if if or circles interacting with circles or capsule colliders colliding with capsule colliders it's just boxes colliding with boxes so like if this box goes over this other box let's say you have a coin in mario well mario is probably just a box and he collides with a coin which is a trigger which isn't a physical box it's that means it does he doesn't physically stop when he hits it he hits that trigger and then that trigger tells the system to play an animation that he collected that coin and then it tells an integer or it tells an integer to increase by one that he's correct collected one more coin right so that trigger will probably be used when your player is like walking over an area okay and you want oh when when the player walks into this area i want this to happen okay so that's called a trigger it's literally triggering some type of an event okay but that's not enough we need one more one more component to have this this object react to physics and unity we need a a rigid body 2d let's do ridgid an add component rigidbody2d okay yeah okay and let's make it so it we we're going to keep it as a dynamic type let's make sure that um let's change the gravity scale to three and then we want to make sure that the constraints it should be the click constraints i just want to make sure i think and do freeze rotation z okay okay now i'm pretty sure if we were to press the play button our player would just drop into just thinking infinity it yep bell it's gone if you go to go back to scene view actually press play yeah and go into scene and then once it plays go into scene view okay and then zoom out as far as you can you might still can you catch it is it still falling yeah oh there it is it's still falling it will fall for infinity okay so press play and we'll stop it how do i sorry this is a really stupid question how do i center back on the oh that's a great question i have no idea how to center back but i always just click option and i drag you can drag okay all right yeah that's uh i'm sure there's a button on windows yeah press play will stop it oh yeah very good excellent and also all those controls at the top at the very top near the near like the the quit button in the in the window where it's like there's the hand there's the four directions those all can like do all of the things that there's like keyboard shortcuts for all that stuff but the move tool is probably what you want by default so again we have a player object it falls now but you can't control it so let's go to the our let's go back to our player and let's add a component now and let's at let's type in player ah and i and i have a player movement script that's the one i gave you right cool yeah all right let's click it so why don't you click on where it says script in that click on it and then you see this now it tells you where it is why don't you double click on it and we'll open it up on the icon here or on ac on the actual script on the left yeah okay so it oh yeah okay very good you don't have visual studio yet so we should probably down you download your visual studio at some point but okay we can see we have a player movement script so right here um you could see that it's super simple it does look probably crazy if you've never done this before um but it there's just a couple of different variables um and this is this is the script that we're using to move the player let's get rid of the script we can press the yeah you get rid of that all right very good so why don't you go back to the player object in the hierarchy yeah and go down and then let's change the movement speed to 8 and then jump force to 15. okay very good now if you press play it's just going to fall again it doesn't have anything to fall on so we need to give them a platform so let's give them a platform let's go back to the sprites folder in our in our project and we'll drag in a another white square we're actually not going to use the black squares today we're just going to use the white squares uh so just the y squares yeah drag in another white square excellent so we let's the position you see is like x negative three y you can change that to anything you want let's change it to zero zero zero very good let's make the platform big so on the scale let's on the scale let's change this the x to um let's change it to five okay and then well let's change it to ten we'll give them a bigger platform okay and then we'll change the y to 20. ah it's big okay very good so let's drag it down so why don't you hold down command and press the and then and then drag it and then press and then hold on to the green arrow uh oh sorry okay and what we're doing when we hold down command is we're actually moving it by half units or full units okay the reason i told you that is it's for especially for pixel art like sometimes you want to you want to pull things instead of just like pulling it you want to grab it by units or half units so let's pull it so let's pull it almost down to the bottom like like right about there yeah and then let's press uh oh actually it's not a platform yet [Music] so we need to add a component to it so what component do you think we need to add to it to give it physical properties what did we add to the player that gave it physical properties the very first thing that we gave to the player box collider yeah let's give it a box collider okay all right and by default that should be all we need so let's press play yay it stopped press spacebar he jumped press left press left right you made a game okay very good pretty that was like that was pretty simple right yeah okay so press play again let's let's we're gonna the last thing we're gonna do for this is we're gonna change the color and we're gonna create a prefab so let's change the the title of white square in the hierarchy to platform okay very good so let's now go to the assets folder yeah and let's create a new folder let's call it prefabs [Music] very good let's take the let's open the prefab folder and then take the platform from the hierarchy and drag it down you just created a prefab why would you create a prefab prefabs help save on memory so instead of creating all these different unique objects in a scene okay because the hierarchy will change based on each scene if you create a new scene the hierarchy will be blank okay so we want to create prefabs in order to save on memory so for example let's go back to the mario again mario is a prefab a player prefab that gets called into the each scene he there's also other play prefabs like a goomba is a prefat would be a prefab because it's just repeated right it does has the same exact movement it does the exact same things but you can place it at different places in the scene a coin would be a prefab because it just you just need one coin you just need to make one coin and then you can just duplicate it in the scene as many times as you need right so that way it's only drawing from one file in your project okay now why don't you go up to this the hierarchy and delete the prefab uh yep literally delete this yeah yep okay it didn't delete it from the project though did it no okay so it's still there so so you can create a prefix and this is one of the things that we're going to learn when we start using adventure creator you'll create a player prefab in any scene you make it a prefab and then you just delete it from the scene but it stays in your project folder okay and and an adventure creator will will basically spawn that player into every single scene drawing it from your project or your project folder so let's let's draw in a couple of platforms why don't you draw on maybe three platforms so sorry this is a stupid question is it do i drag them into into the scene you could drag them right into the scene or into the hierarchy okay it doesn't say either one is fine right if you do yeah okay great exactly why don't you why don't you just position them how you how you'd like imagine you want to jump from platform to platform they can overlap each other it's not a problem okay should we try jumping that gap yeah let's try jumping that gap nope press play and then [Laughter] i mean it was a good it was a good effort oh that was white i pressed up instead of jump sorry this is the level this is the level of idiot you're dealing with no no no worries okay i mean that is a game isn't it yeah that's a game right so so basically now basically think about it you have another you you let's say you create another script and you put it on a coin and every time your player your player character passes over that box collider which is a trigger it tells an integer to increase by one you've you're collecting coins yeah you know that i mean like that that that that sounds super it is is very very simple so press the play button again all right so another thing that you can do the hierarchy is you can create you can create folders um so why don't you press uh press the plus button again and create a game object and create empty create them oh sorry yeah and then you could set you can uh change the name to platforms [Music] and then you could the platforms actually change the change the transform for platforms because you could see that the it was crazy you can actually just click the three vertical dots on the transform on the right of the transform three vertical oh right there yeah and click reset okay zero okay and then then drag the two platform prefabs underneath that to parent it like right on top of it you drag them right on top of it yeah and then can yeah and then you have a little folder there you can keep things neat and tidy on the left okay great okay very good so um and then you can also move them all together if you click platforms and you were to move them left or right you know okay so let's let's actually do one more thing go to the player uh yeah and then you see the color of the player yeah yeah yeah let's change him to a nice yellow color okay something that will go good with that purple get gold there we go nice and then click on the platforms you can actually click select both of them at the same time believe it or not that way nope the other way selecting both of the actual objects very good and then you could change the color of both how do i sorry right am i doing that by i don't know where you'd like i've done shift is that that's selected in both right yep that yep you can see on the left in the in the hierarchy that there is oh yeah sure okay sorry yeah so change the color to something nice all right let's go over to our game view let's see what that looks like that's what it looks like now okay so um very good yeah press play we're gonna play it yeah great don't stop me [Laughter] masterpiece great masterpiece game okay so black game so one one last thing that we need to do is you may notice the camera does not follow the player and you're like oh my gosh do we have to code some complex system well unity does this great thing where when an asset gets really good and a lot of people use it they just buy it from the developer and integrate it into unity and one of those things that they did several years ago was something called cinemachine cinemasheen is an excellent uh add-on to the camera that has a lot of functionality that you'll never even have to program or worry about so that's actually in something called the package manager so let's let i think it's up in the i always forget where to open the package manager um go to window and then go to package manager oh yeah all right package manager so there's a lot of different package managers right and one of the things you're probably going to want is visual studio editor so let's do that one that that one is the one we're gonna want um do let's do update oh actually you already have it somehow i wonder why it's not being used by default we might have to change that um well let's let's let's search for um where it says packages and prod project up at the top of the package manager let's go unity registry yeah and then we'll we'll search for cinemasheen [Music] ah there it is let's do install cool okay so we're not going to be using cinemachine with adventure creator but what i'm showing you is how to download a package which is important okay so you can actually the package manager window once it's done compiling these scripts and importing cinema machine you can actually put the package manage manager window down by your project or console windows at the bottom or your your inspector tab or place it where you want in in the so you just have it you know accessible on demand oh okay i can trim this down when we come to it's okay it takes a while i recently watched this devlog by a guy who's making a 3d platformer game which has which which can have extremely complex cameras and he was like coding his camera and he was like so worried that you know like all this clipping was happening and he's like no i don't want to use cinemachine it's gonna it's it's not good enough for my project and he imported cinemachine and everything worked perfectly yeah okay so let's let's slot that package manager near something you can just drag it bloop yeah very good all right and then go go to your go now let's go to um the main camera in your hierarchy and i want you to add a component and search for cinemachine brain brain brain yeah boom put it on there boom good excellent okay i don't think we have to change anything on this but why don't you go to your player yeah and now you want to add a is it here no no no we want to create a new object in the scene hierarchy okay yeah make sure that the position again is zero and then call that object um cinema machine camera one or something doesn't matter it actually doesn't matter at all yeah okay and then let's add a component cinemachine virtual camera [Music] there you go very good excellent so let's take the so we can see that actually we need to change the z position to negative 10 just like our other camera oh there our game comes back now very good so we can also see it kind of made it go out a little bit more so you can always you can always there's all these different things that you can adjust but one of the things we want to do is we want to make it that it follows our player so do you see where it says follow uh yeah so why don't you drag the player into that yeah oh nice sorry yeah go back yeah no worries then drag the player and the from the hierarchy you you don't you don't like click and then release you just show it yep okay yeah click and drag it where it says follow boom now oh it's his body it should say framing transposer oh where's that side body do framing transposer there you go okay and then let's press play and see what what happens all right now now now it moves in and you can actually click off of the cn cinema machine cam so it doesn't display that awful blue yeah there you go yeah there you go so now now we have it following and there's a lot you can do with cinemachine you can change like the dead zone so for example like in a game like sonic you might notice that the the the camera doesn't perfectly follow sonic there's actually a zone that he can walk in in which the camera doesn't move and then once he's reached that point then the camera starts moving and you can ease that in or out and all of that's contained in cinemachine um but cinemachine also has 3d cameras so like you might notice um in 3d games like especially when you have a player and like you can like walk behind a wall and then like the camera will like make sure that you can still see the player yeah cinemachine can do all that stuff okay um so you can start playing i don't wanna yeah um cool okay do you have any questions um no i think i've followed everything so far um it's there's a lot of there's a lot to take in because someone like me who's not very technically minded yep um this is um you know it's surprising how uh yeah got to this stage you've made a game basically but but one of the things we might notice is that there's no menu right so the last thing that we really need to know because last thing what does that even mean right but like there's no sound in our game we haven't done any of that yeah but let's let's let's create a new scene and in the new scene um we're going to create um we're going to create a menu so go down to assets yeah let's go down to your scenes actually instead and then let's change the name of this scene you see where it says we could just change the name of that scene uh yeah let's change it to level one uh yeah and then let's you cannot copy and paste anything in the project folder but you can duplicate things so why don't we click on level one and we'll press command d [Music] all right so why don't we call the new level um we'll rename it um start okay very good so let's open that scene oh save yes very good go back to level one okay very man i don't know i don't know why why when we selected st we have start start and it didn't go back to the start scene double click on start scene and why didn't it save anything that we didn't the other one super weird maybe because it's the same that like we were working from the sample scene i have no idea that doesn't make any sense but it doesn't matter click on the click on start yeah now this scene is not in the build settings yet um let's go to the go to file in the upper right and click on bid build settings you can cancel that and then we want to add open scenes okay now start is in the build settings now drag start to the top we want start to be number zero okay and in in unity all numbers do not start at one when you're dealing with code numbers start at zero so if you have three if you have four actions for example the first action is zero second action is one etcetera you see what i'm saying yeah um so that's what that's something to keep in mind sometimes you know you're like okay there's why is it say there's only three it's like no that if it says there's three there's four because zero was a number okay yeah yeah um we can get out of the scene the the build settings okay so unity has a built-in ui system that's extremely robust in fact it's far more robust than the the menu system that is an adventure creator in fact you can use the unity ui system together with adventure creator you can make a game completely using the adventure creator menu system it's fine there's just more you can do with the unity ui system now there are a lot of tutorials that you could see how to use the adventure creator system with the unity ui system but we're just going to use the unity ui system to create two buttons okay so let's go to the hierarchy yep okay and then do ui and then go let's do button text mesh pro you're probably going to have to import text mesh pro yes import tmp essentials take a moment shouldn't take too long and then import tmp examples and extras there might be something you need i don't know okay text mesh pro is also another thing that they acquired just like cinemachine right okay that is just super robust text system so why don't we click the x we don't need that anymore now one of the things you might be like what it's like so big and gross like also zoom out really far you have to zoom out really far oh so that whole box thing that it has like its bottom left corner positioned in the center of your actual game screen you're like why is this giant ui over here i want like a ui that actually fits on top of my game screen it does click on the game view oh it's just in the bottom so so click on scene view again so basically unity is like saying like this is your ui it's it lays on top of everything in your game okay it literally lays on top of even if you have the sorting layer maxed out okay you have something at the top sorry this is still over that okay and that's the reason that it hangs out up here up to the upper right now let's take that button and set its position to zero so if i'm just doing reset and that's here yeah sure yeah very good so let's also make the um width of the button 200. very good now do you see the button in the hierarchy on the left yeah okay also important to notice when you created ui it created two things a canvas a button well that's three things but a canvas button and an event system click on event system uh yep that's automatically created when you created your canvas now by default you can navigate your you your unity ui using your mouse if you want to do something like a game controller you have to set up what those inputs are okay um that's what in the event system and you can see the standalone input module event system it's all right here okay so all of that that that all of those things can be controlled right here by this event system now let's go back to the button underneath your canvas which is a child of the canvas obviously because the canvas is what the unity ui uses to display these things um so the it's still it says button do you see the text on the bottom uh uh text in the hierarchy i'm sorry it says text tmp yeah yeah let's change that the text input to start game very good okay and then let's change the button to a different size why don't you go back to button and change it to a nice size give it a nice horizontal size width and height do what you need do what you think you need to do very good that's actually perfect right so we can um if we press if we press we can actually see right now by default it has it the transitions of the button are tint changing the tint click on the transition you can do sprite swap so you can actually have like oh i want it to do this sprite when you click on it and this sprite when you highlight it and this sprite when you do that or you could have an animation play that's much more complex and we're not going to even talk about it right now um but let's do uh tint and let's change the um so normal color is what it is right now highlighted color is when your cursor goes over it yeah and then selected color is like if you're using a controller and you actually go down like like that the button is selected yeah um and the pressed color is when it actually gets pressed and then the disabled color is when the button still exists but the it cannot be interacted with okay okay so if you were to if you were to click the interactable button do you see the interactable check box [Music] yes yeah you click that it it changes to the disabled color now that button is disabled okay it still exists it's just disabled and you can enable it through the event system so click it interactable okay this this button works if you play the game you click it it should change color when you press it yeah it does but it doesn't do anything right so we've created our start button our start game button but we don't have any way to actually start the game that means to actually change it from one scene to another so in order to do that we need to create a script this is not something that unity natively does so let's go to the scripts folder and let's create a new script create script and we'll call it scene changer okay very good excellent takes a moment we can see a preview of that of that script on the right in the inspector but let's double click it and it will open in visual studio pro very good excellent so you might think oh like all like already i don't understand any of this um so it's pretty simple to be completely honest at the very top it tells you what this script is using by default a new script in unity will be using the system.collection system.collections.js and the unity engine which has a lot of different functionality so basically if you write any anything below that it has to be understood by those systems so if you and if you write something about changing scenes for example it won't understand that because we actually need to add something a using something at the top so why don't you go up to the top where it says using unity engine and press enter and then going using um dot use using unity engine dot scene oh it already says it see it already says it scene management click it okay yep okay and now you need to close that off so press do use uh the semicolon right there if you don't use the set to do the semicolon it won't work okay there'll be an error so now we can actually change scenes because it's using this unity engine scene management now you see two different things void start void update you're like what is void the way that i in my very bad i'm not very good at i'm not a good coder by any means but the way i think of the word void is i think of it as being a command of or a function so you have to kind of divorce your mind from what void actually means in the english language okay so void start all of those commands that you write in that will happen immediately void update unity updates every frame it runs at 60 frames per second so it will up it will update or it will run any of those commands every single frame now those are two things but you're like but i don't want to just write do things at the start of a scene and on every second what if i want something to just be there when i need it right well you can write it outside of void start and void update so we can actually delete that so why don't you select where from the first part where it says start is called from the first frame of the update you go all the way down and then all the way down to that last bracket not the not the very last the second to the last right delete okay we don't need it okay so we're going to create two public voids two public commands right public uh space yeah void void and then you're going to stoop another space and then capital c change and then we'll do capital s scene and then you want to do a parentheses so if you do a parenthesis it'll automatically create the other one there and you're like that doesn't that doesn't make any sense so basically what you have created is a public command okay okay that means that that you could have you'll your button when you click on your button it will actually be able to reference the change scene command so we need to actually include two brackets after this so press enter oh i'm sorry press undo that and then press the bracket key the other one yeah there you go and press enter so obviously i don't know if you've done any web development no i think you can tell though i haven't yeah basically in all all code it needs to be encased so basically whenever whether it be you know css or like whatever like it needs to have like a start and a finish for the system to know oh this is when the code starts and this is when it ends and that's what those brackets do the brackets are telling it this is when it starts and this is when it ends okay so what are we going to we're going to write scene manager capital s capital m no space yeah yep very good so what you're referencing the unity scene manager and then you're going to press dot load scene capital l capital s and then and then do parentheses yep and then in the parentheses we want to write the name of our scene since it's a string we need to do um we need to do quotations yeah and then write level underscore one that reference is the level that you that we created right and then at the end of the parentheses outside of the parentheses put a semicolon that finishes that line of code very good so this works okay why don't you press save it really wants you to install that it's cool um like command that's just saved yeah command s yeah yeah cool okay and then go back to unity you don't have to exit out yeah it might take a second to compile the code oh click on unity click in unity okay there it goes compiling scripts okay now let's go to our button yeah oh no sorry yeah button button okay do you see go scroll down you see where it says on click um well let's do add component add component underneath it add component underneath oh sorry yep and then type in scene changer and we're going to scene changer very good we want to add that script so now this component can use that script okay if it it cannot use that script unless it's added okay so this is also important for when you start using adventure creator um now do you see where it says list uh list is empty on click let's let's add an on click event yeah let's um you can actually do you see where the button is in the hierarchy you could do this two ways you can either click there and add the button that way or you could drag the button right in there okay uh yeah you could drag the button in into the it's another object and then the function click on function and you see it says scene changer yeah we want to reference that script and what what which one of these things look at look at what we have here all these different options which one do you think we want to do change scene yeah click change scene okay very good now press save just save your project always save your project press play click start game hey [Music] there we go there we go right so you can you can there's that that was like a super simple script we can we can also make a script that where you can you know add add different scene names to it because this the script that we created for scene changing is hard-coded to just change to that level let's do let's do one let's do one more thing let's press play yeah it'll go back and and pressing play doesn't go to the last scene that you're playing it goes to the last scene that you had open right okay you're right so we're back here let's add one more button uh yeah no no not like that not like that you can actually just duplicate that button say command d [Music] okay very good let's draw it right below start game and let's call that and let's and let's change the text for this button if you go to the hierarchy and you go underneath the button oh text [Music] okay very good so let's go back to our cha our scene changing script and we're gonna add another public void so go underneath the that public void after that last bracket yeah no not that bracket [Music] yep public void yeah quit game capital q capital g and then again parentheses okay and then go over press enter create some brackets press enter okay very good we need to write a command the command is simple and this is for all for unity application capital a dot quit and then to uh parentheses semicolon after the parentheses okay so that quits the game press save save that yeah okay it should take up i don't think you saved it oh you did i did yeah i got it feedback on either these things when i do command s i'd like it to sort of go yes i've saved there's no there's no sort of so actually going to the you see the console at the bottom you're the project folder uh yes if there's an error in your script it will appear right there actually go back to your script for a moment yeah remove the semicolon from af after quit and then save it oh sorry yeah yeah and then save it [Music] then go back oh and then now now try to play your game oh all compiler errors have to be fixed you're like ah okay so go back to your script add that semicolon [Music] very good excellent and then save it go back man and that that that should disappear red red things community and the council are bad bad yellow yellow things are not necessarily bad they could just be white warnings but if you have like a lot of yellow things popping up it might be trying to do things um that are actually consuming memory and you do actually want to solve those problems okay um but great so now we have a way to quit game if we were to if we were to start the game oh let's let's go to the second button button uh want this the quick game button and then we have to go down to the on click and then instead of changing the scene on click uh okay yeah and go to the right right there change scene changer quit game boom you cannot quit the game when unity is running it won't work it only works when you've built the game because if you were to quit the game it would shut down unity so like by default it just doesn't quit okay okay so very good so let's let's do one thing um let's um because if you start if you play the game and then you're in that place you have no way of going back to the start menu to actually quit the game so so let's take the uh canvas and event system and and then highlight all the way how i done and then do command copy yeah now save the scene save the scene command s save it go and let's go to your scenes and then go uh go to level one and then go up to your hierarchy click it click in your hierarchy and press command v to paste it so let's go to the canvas let's delete button one that button start button just delete it and let's take the button button that that button and draw it up into the upper right corner okay okay yeah you don't have to press the command or like and just put it over there now we can quit the game from this from this scene okay so we're done okay we're done with our game we're not going to add any sound or anything like that um we can start adding sounds and stuff when we're doing we're using adventure creator but let me just show you how you would do that if you were to add a sound okay so you can actually let's let's for example add a sound to this button so on the button add a component yeah not on the text mess mesh you're on the text mesh text uh the text i'm on the button yeah no worries add and add um audio source audio source yeah now remember your game camera has an audio listener it's listening for audio it's like giving your game ears but an audio source is like giving an object a speaker okay okay you cannot play audio without an audio source so even if somehow you were able to add an audio clip okay like you actually have an audio clip you like drag an audio clip you're like i have an audio clip here why isn't it playing it's like that's like going over to your friend's house and saying like i have some cds you want to listen to them but they don't have anything to play them off of okay so the audio source is like a speaker it literally has a little speaker icon um you can so where do you drag that audio clip you can drag it into the audio source you see where it says audio source you can you can add it in right there yep um and then go down and you can it has play on awake by default that means as soon as you start the scene it plays so you might want to uncheck that for certain audio sources in your game if you click loop it will loop okay there's all these all these other things bypass reverb zones typically you won't be using any of most of those things but you can see that there's a lot of different options here okay and then the audio mixer group that will probably be important because once you get your adventure creator game to a certain state you will probably want to implement the audio mixer group okay you're not going to just want to use you'll want to use unity's audio mixer group it will really help you adjust your your sound effects and your speech and your music and everything like that so that's for that's for future but you can actually reference this audio source and the in the button we don't have an audio clip for it but let's let's just let's just do it as if we were to do it so press the plus on the on click event for the button um above oh sorry yeah on click the button yeah do do add plus do um again reference the button so you can just you need to reference the button itself you can actually reference any object in the scene which is awesome click on the function go to audio source and then it would be play so for example you want your your button to click when you click it it goes or something like that that's what you would do but it won't do anything right now because there's no audio clip in there right yeah anyways um so let's build this game um we're done there's oh there's actually one one one one one last thing before we're done um go to um i want to just make sure it's the right the right place i want to say it's edit yes i think it's called yes project settings you want to go to edit project settings uh for accessing was fine now that seems and then why don't you why don't you stash that somewhere maybe up by the game um yeah oh hey yeah and you might be like wow that what an inconspicuous little uh option here this is super important like so important okay so look at where it says graphics on the left yep that's that is the type type of graphics that you're using so if you want to start using a different pipeline like uh like you want to be using 2d lighting and stuff you would have to put that right where it says render pipeline asset okay so and then all of these things are are under here in the graphics like like so you can control so many things right here another thing that's important is where it says input manager do you see input manager on the left uh yep okay so why don't you uh expand where it says axis so you can actually see this is where you would tell unity like if you wanted to set up a controller you this is one of the places you could set up a controller there's another way to do it but this is the most basic way to do it okay um and then you see where it says player yeah that little inconspicuous thing is where you'll change the icon for your game so when the game when the game is you know like on someone's desktop and you want it to have like your little player icon you can expand icon yeah this is where you would put those icons okay that's such a weird place to hide that really important thing you know it's a super robust system um so you can see um like there's ios there's android because and the reason that those two things appear if you go up to the top yeah and you see ios and android the reason that is there and not like xbox or playstation is because you haven't actually imported the the the the the x the xbox or like the playstation or the other things like like if you've imported that those options into unity then they will appear in those tabs okay um very good all right so let's build this game let's go to file yeah it's build settings and let's hit cancel and then do you see where it says build yeah build [Music] and let's save it as whatever you want [Music] okay so to the desktop because then we'll just right on the desktop it shouldn't take too long to build it unity builds games relatively fast um i'm surprised sometimes at how fast the builds can be of course with adventure crater if it's quite large like hundreds or dozens of scenes um you know lots of different voices and assets and stuff like that it will take you know it might take 10 15 20 minutes but you can do it pretty quick so let's go to you let's take a look at your desktop and yeah where is it oh block game let's double click it yay made with unity start game you made it quick game quick game hey i mean that's a game basically right i mean again there's like so it was it's so simple it's it's like there's so many things that you we need to tweak but obviously like like and like because we're using cinemachine and like the the event system and the canvas it wasn't it wasn't rendered properly so like the the button instead of being in the upper right corner was like like somewhere in the center of the screen like like all of those things we can we could we could polish up right you could polish up the what the buttons look like really easily just by adding simple sprites you could probably polish this game in 20 minutes and make it look a lot better especially if you know what you're doing right but that's that's basically it so um do you have any questions about this initial intro to unity um i mean i have a thousand but i think you know in terms of the getting the basics understanding you know even having never even really looked at it before understanding the windows and stuff and everything i think that's a pretty thorough um run through yeah so thank you you
Info
Channel: The Point & Click Devlog
Views: 8,991
Rating: undefined out of 5
Keywords: Unity tutorial, unity, tutorial, unity overview, unity basics, programming, gamedev, game development, adventure creator, adventure creator unity, adventure creator tutorial, unity platform tutorial, unity tutorial 2021, simple unity tutorial, Unity basics, coding tutorial, unity script tutorial, unity game development, unity introduction, introduction to Unity
Id: xOGfvtx9nIQ
Channel Id: undefined
Length: 74min 16sec (4456 seconds)
Published: Thu May 20 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.