How to make Snake in Unity (Complete Tutorial) 🐍🍎

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello my name is adam in this video we are going to learn how to make the game snake in unity from start to finish snake is actually a game concept that originated in the 1970s arcade game blockade you maneuver around an object picking up pieces of food which make the object larger but every time you do so it becomes harder and harder to avoid running into yourself so in other words you yourself are the primary obstacle you're trying to avoid if you are new to unity or even to game development recreating older games is a really good way to start learning and growing your skills for this project all of these source code and assets will be made available to download through github there's a link in the description of the video let's go ahead and start learning let's jump in all right the first thing we're going to want to do is create a new unity project so if you open the unity hub we can create a new project using the new button in the top right corner if you select the drop down you can actually choose which version of unity you want to create i'm going to use 2019.4 because it is considered the current long-term support version for this project it doesn't really matter though we won't really be utilizing any new features that only exist in let's say 2020 for example let's go ahead and name this project snake choose wherever you would like to save the project and most importantly let's select the 2d template here this is going to be a 2d game let's make sure we set that because it will set up all your project settings accordingly go ahead and click create from here it might actually take a couple minutes to initialize so we'll have to wait for this to finish all right now that our project is open we want to start by setting up our scene before we begin scripting anything unity provides us a sample scene by default i'm actually going to rename this to snake and we'll reload on the left is our hierarchy where we can see any game objects that exist in this scene by default uni provides us a camera game object and on the right is our inspector where we can inspect whatever object we have selected and we can see the components that exist on that object so camera component there's also an audio listener for snake we're going to need a few different game objects including a camera we'll need some walls we're going to need the snake itself and we're going to need a food object too so since the camera is already here let's just start with this and all i want to do is change the color from this blue to a black it actually doesn't matter so feel free to set it to whatever you'd like but i'm going to choose black and you can see the camera preview down here you can also suck the game tab up here where you can preview your game in full the other property i want to change on my camera is the size here from 5 to about 15. if you see as i change this now you can see this white outline is increasing or decreasing so this is indicating the area that the camera can see by setting it to 15 it's effectively making it so the camera is sort of more zoomed out or in a sense further away from the origin this is important because at the default size of five our objects are going to appear pretty large and 15 is a little bit more appropriate for this game but feel free to adjust that to your preference so that's it for our camera next we want to set up our snake object so if we right click in our hierarchy there's a couple options we can choose create empty which will create a brand new game object with no components on it except for a transform every game object has to have a transform so that will always be there the other option is to right click and we can actually choose 2d object and sprite in this case this is going to create a new game object with also a sprite render which is what we want for our snake i want to reset the position of our snake here to zero so i can actually just click the three dot menu and choose reset it'll set all those back to its defaults i'm going to call this snake let me switch over to my game view here you can see that nothing is showing up yet even though we have a sprite render and that's because we need to actually choose which sprite to render and so i need to first create one in our bottom project panel here i have my assets folder selected i can right click create sprites and i can choose a square for example i'm going to just leave it named square i reselect my object we can drag this into the sprite field there you can also click the little circle it'll bring up a menu where you can select everything or search if you have lots of assets in your project now we can see it's showing up and i want to change the color from white to green that looks good once again feel free to choose whatever color you prefer and we want to add a couple other game objects to this object so one is called a rigid body and then there's rigid body and rigid body 2d the first one is intended for 3d games but since this is a 2d game we will suck rigid body 2d so a rigid body essentially turns this game object into a physics object it tells that it tells this game object that it should be controlled through the physics engine the reason we need this is to handle collisions so when the snake collides into walls when the snake um technically the snake will collide into food which indicates that it's picking up that food and also the snake can glide into itself which would be a game over so we need rigid body to detect collisions but we actually don't want to simulate the motion of our snake through the physics engine you can see there are properties like mass and drag and gravity for this particular game we don't want to do simulated motion so we can actually change the body type from dynamic to kinematic notice how all those properties go away this will still allow us to control the movement of our snake through code manually while detecting collisions which is what we most importantly need the last thing we want is a box collider and in this case the 2d version once again the other one's intended for 3d games box gliders 2d what this does is actually just define the shape of your collision area on this object the rigid body actually will detect collisions but the collider defines the shape of the object um so in this case it's a box just to match the shape and we actually want to adjust one thing on this so if i look at my snake object here let me actually change the color real quick so you can see this notice this green outline on our object here this is represented representing the collider so if i disable this it goes away i re-enable it it appears again we actually want to change the size of our collider just slightly i'm going to reduce this for example to be maybe about to be about half so 0.5 and the reason for this is because if so at one point we're going to have multiple segments in our snake right they're going to be linked up together like this and if all of these had a size of one well then they would technically be colliding with each other they're overlapping and that's considered a collision in the game of snake if you collide with yourself you lose so we don't want these colliders to overlap so i'm just going to slightly decrease the size you know i'll actually set this to 0.75 instead of instead of 0.5 you can see now even though visually they're connected the actual physical area defined by our collider is not and therefore our snake wouldn't be considered colliding with itself [Music] let me delete these other ones let's go back here so 0.75 that looks good oh and we need to set one other property we're going to set this to be a trigger so a non-trigger object if you have two game objects um that weren't triggers when they collide with each other they're going to physically hit and like come to a stop right like if you ran into a wall you're gonna hit that wall and you're gonna come to a stop you may even slightly bounce off of that wall depending on the physics properties in this game so that kind of stuff is really useful for a lot of games but um it also adds a little bit of complexity that we don't need for this game um in this game for example if you run into yourself you're just immediately going to lose and the game game's going to reset it we don't need to simulate the physics of you like hitting yourself and coming to a stop and all of that and so by setting this to a trigger it's just going to simplify some of our work later on once we start scripting everything so everything will be a trigger oh and let me i never set our color back to green let me change my snake back to green that will be it for our snake game object next let's go ahead and create our food game object it's pretty much going to look the same for the most part so once again we can right click on our hierarchy 2d gamma 2d object sprite let's reset the transform to zero i'm gonna make our food red and we're gonna use that same asset as the sprite and now you can see it show up and i can move this around and you can see our snake and our food um all we need here is a box glider we don't need a rigid body only the snake the snake is the only moving object in this game so only the snake really needs the rigid body everything else still needs to collider to define the area the collision area but it doesn't need a rigid body we're going to also set this to be a trigger every box collider we use in this game will just be set to a trigger for simplicity and the size i'll do the same thing for the size on this i'll slightly change the size just to make sure that um oh so actually the reason for it on the food is potentially snake is usually a grid it sort of works in a grid and if let's say you're moving our snake like this and you skim right past the side of our food you're not technically eating it because you're not in the right column of it and so we don't want that to be considered collision when they're side by side like this so same thing i'm going to change our food to be slightly smaller and it's in its collider size so in a situation like this they aren't considered overlapping um let's name this food and that is it so snake food that's that and finally all we the only other objects we need are walls technically this is sort of optional but i think it'll help in this case so we're going to add some boundary walls to make sure our snake can't go beyond um the limits of our sort of our camera here so let's once again 2d object sprite let's call this wall let me just reset the transform we'll use the same sprite as the others i'm going to use a sort of grayish color here we'll just make it um yep gray i don't want the walls necessarily to stand out too much and let's position this let's start on the left side so let's say negative 24. make sure these are whole numbers make sure there's no there's no decimals and that's once again snake usually works in a grid like pattern and if we have um floating point numbers like that it's going to mess up our grid so a whole number 20 negative 24 and let's increase its size here we can change the scale and the y-axis and let's make this about 25 once again whole numbers good that looks good um we need a box glider on this as well um mark it as a trigger and finally we actually don't need to change the size of this we can keep it at one to one it perfectly lines up with our wall there which is good and cool so that's one wall let's just duplicate this so we can right click and select duplicate or you can also press ctrl or command d and let's just flip this from negative to positive now we've got our right wall let's duplicate this again this time we need to be on the top so we need to scale it in the other axis so let's change the y back to one but let's scale the x this time and just until this lines up so 48 looks good let's move it up make sure it lines up whole numbers 12 and duplicate one more time and flip this to negative and there we go now we've got our four walls sort of surrounding our area which will prevent the snake from going beyond our camera um and actually i'm to make these slightly darker just so they don't stand out as much so 20 that looks good okay call this wall all right and that actually completes our scene setup we have all of our objects we need to begin scripting everything all right now we can begin to start scripting our game we're going to focus on making our snake move as our first thing so if we right click on our bottom project panel we can select create c-sharp script and let's call this script snake let's go ahead and select our snake game object and we can drag this script onto our object here just in this empty space you'll see the script show up and this means this script will now run as part of this game object you can click the menu edit script you can also just double click the asset in the project panel and we'll get a class that looks like this by default unity creates us a class that always inherits from mono behavior and they provide a couple functions that are just very commonly used um i actually like to just delete everything to begin with and just start fresh and so in order to make our snake move we first need to declare a variable uh to keep track of our direction let's go ahead and do that let's call this private um it's going to be a vector 2. a vector has two float floating point values in the x and the y and we need this because the state can move both in the x axis and in the y axis so we'll call this direction and that's actually say it has a default of vector2.write so by default the snake is going to move to the right from here we can add a function called update which unity is going to call automatically force every single frame the game is running for every single frame that this script is is active on a game object and this is commonly where you'll handle things such as input and so that's what we need to do we need to assign our direction based on the input the user presses so we can say if input dot get key down i can type get key down and then we can specify the key code so any key you want i'm going to use wasd for my controls i'll start with w we'll say direction equals vector 2 dot up if you press w basically you're going to do the same thing so else if you press s well then we'll move down else if you press a you'll move left and else if you press um oops if you press d you will move right and there we go now we're assigning our direction based on our input we haven't actually made our snake move yet so that's what we need to do next based on our direction we actually need to change the position of our snake now we're actually going to handle that in a different function called fixed update the difference between these two is that update is called every single frame your game is running but your frame rate is variable it just depends on how well the game's running for your computer whereas fixed update is always ran at a fixed time interval and this is important for physics related code because if your physics was simulated with a variable frame rate well then you're going to get some very undesired and un sort of expected inconsistent results so usually all physics is handled in fixed update if you remember when we set up our scene we added a rigid body to our snake to indicate that this is a physics object and so that's where we um that's why we're gonna handle all the movement in fixed update so based on our direction we can actually move our snake so we can say this dot transform which is accessing the transform object here and we can change our position position and we're going to say equals new on vector 3 our position here is always a vector 3 even though this is a 2d game and we can provide our x our y and our z and so we're going to take our current position in the x and add it to our direction in the x and then same thing in the y position not y plus direction y so our current x plus whatever direction we're going in the x plus our current y with the direction and our z can just be set to zero because we don't need that for this game now the reason i set it up this way is because we actually need to do one more thing we need to actually round these numbers here to make sure our snake is sort of aligned to a grid and so i'm going to wrap this statement here in math f dot round [Music] and then same thing with our y math f dot round math f dot round and this will make sure all of our numbers are always whole values which when we did our scene setup i explained how we want our snake to always be aligned to a grid and so we need whole values to do that let's go ahead and test this out now [Music] our snake is on there so we can click our play button and you can see our snake is moving now and i'm using my controls to change the direction now i can go beyond the bounds because we haven't detected the collision yet nothing happens when i eat the food that's all expected now one problem is we're moving way too quickly and that's because our fixed interval here is it's just too is too often so we can actually configure that in our project settings we go to edit project settings we've got a window here i'm going to bring this up here and we go ahead and select time we can change this fixed time step which is that how often that fixed up even says here frame rate independent interval that dictates when physics calculations and fixed update events are performed so let's say let's set that to 0.04 and that's much more appropriate that feels a lot better it's not too fast we can even change this to something else if we want it to be even slower and notice how i'm sort of um i'm kind of snapping to each grid position in a sense i'll never i'll always be able to like perfectly line up with this food object and that's because of that rounding we're doing play around with this fixed time step until you find a setting that works for you it's basically one way you can change the difficulty of the game if you want your game to be really difficult then make it really fast but i think the 0.4 felt good for me so that actually finishes our snake movement next let's go ahead and start scripting our food object so we can randomize the position when the game starts as well as every time the snake eats it so in our project panel on the bottom let's right click create c-sharp script and we'll name this one food and let's add this script to our food game object this time so we'll drag it into the empty space just like we did for the snake let's go ahead and start editing this i'm going to clear everything out just to start fresh so for our food we need to randomize the position but to do that we're going to need to know where the food can can be positioned and we want to make sure it never randomizes outside of our bounds here should always be inside the balance and so one way we can do this is we can actually create another game object create empty we reset its transform back to zero that's actually pretty important for this one let's go ahead and add another box glider 2d mark this as a trigger because we don't want anything to actually collide with this it's going to be sort of an invisible just an invisible bounce now i'm going to name this grid area we switch over our scene view so we can visualize the size here and what i want to do is line up the size of this with our boundary and i'm not going to actually line it up exactly with the walls themselves i'm going to make it always half um half a unit away from the walls and this is because let's say for example our food randomly positioned right here on this point in our grid the very corner if we move our snake let me or move our food down to that corner [Music] so roughly there notice how now our food perfectly lines up with the walls right and that's because all of our game objects the center point is our sort of zero zero for this object it's always it's always based on the center and so if we line up our grid all the way to the edge but then our food could potentially spawn partly in the wall which is not what we want and so we go ahead and we mark everything or mark our grid area half a unit away on all sides okay now that we have our grid area bounds we can create a reference to this in our food script let's go ahead and open that back up we're going to create a public variable here it needs to be public so it show up in the editor and we're going to type it as the same type of our component that we just added which is a box glider 2d and we're going to call this grid area now look at what happens in the editor if we select our food game object and we have our script here notice how this property now shows up and we can actually drag in our reference to a box glider 2d in this field so i can drag in my grid area over here and boom now we've created a reference to that to this box glider in our food script the box collider contains a property called bounds which gives us like the exact size and everything and that's what we'll use to generate random numbers so let's go ahead and create a function called randomize position [Music] and let me get a reference to those bounds i was just referring to so we can say this.grid area.bounds that bounce now we can get a random number within these bounds in both the x and y axis we're going to use unity's class called random which is just a class for generating random numbers and there's a function called the range which allows gener generate a random number between two um two points so range and we can actually say bounds dot min.x and bounds.max.x and same thing in our y-axis random range bounds.min.y bounds.max.y there we go now we've generated a random point within this bounds that we have defined in our editor all we have to do now is assign our foods position to be these coordinates this dot transform that position equals new vector 3 x y and z doesn't matter so we'll set that to zero and one more thing is we need to round these values just like we did in our snake scripts we need to round these to ensure that everything aligns to the grid our range here returns a floating point number and so we need to make sure everything is whole numbers so i'll round these as well round x and round y and there we go let's go ahead oh we actually need to call this function first um and so we're going to use a built-in function that unity calls automatically on any mono behavior which is called start start is going to be called the very first frame this script is enabled on a game object so on start we'll just go ahead and randomize position let's go ahead and test this we'll run our game notice our food is in the bottom left let's run it again top right let's run it a couple more times yup yeah so you can see every time it's in a random position which is perfect and notice how i'm perfectly sort of aligned with this object right it's not i'm either directly adjacent to it or i'm directly overlapping it and that's because of the rounding we're doing um here so that's very important all right the next thing we want to do is actually re-randomize the position every time the snake eats the food so we need to detect when the snake collides with the food we set up our colliders on all of our game objects already and we mark them as triggers and so what this component is going to do is it's going to provide us with a function called on trigger enter 2d it's the 2d version there's one parameter here which is another collider 2d and we'll call that other so essentially this function is going to get called automatically whenever our um whenever our game objects collide with one another or in this case when the trigger is whenever it's triggered and then there's like enter and exit but in this case we just want enter and it gives us a reference to the other object that collided with this one so in here is where we can call randomized position now one thing we should do however is check what other game object actually collided with the food here in this game the only thing that could collide with it is the snake but it's generally a good practice to check that this other game object is what you expect it to be so one way we can do that is using unity's tagging system so we can say if other dot tag equals then let's say player in this case then we will call our randomized position function so let me show you how that works on any game object you can see this tag up here and you can select different tags you can add your own tags there's a few default ones that you need to provide such as player and so we want to go to our snake game object and we want to tag our snake as being the player this means now when our snake collides with our food this function will be called the other collider will be a reference to our snake and we'll verify that that is indeed our snake by checking the tag is the player and if that's the case we'll go ahead and re-randomize our position let's go ahead and test this out here we go boom randomizes every time i collide with that object which is perfect it now it it comes across as if i'm eating the food and then a new one is spawning awesome so that actually completes our food placement and randomization [Music] all right now that we've got our food game object scripted as well as our snake we need to sort of combine some of the functionality to make it so when you eat the food it will grow the snake in size and you'll you'll have more segments being added we don't need to create any new scripts for this we're just going to expand upon our existing sync script go ahead and open that up the first thing we're going to want to do is create a list keep track of all the segments of our snake go ahead and do that actually i need to import um using system collections.generic so i can define a list here this is going to be a list of transforms and i'll just call the segments um in our start function we can go ahead and initialize this list and we can add our very first segment which is just sort of the head of the snake which is um which is the the object that this current script is attached to so this dot transform and then we're going to need to continue to add to this list here now to do that we're going to have to create a brand new game object programmatically that sort of matches our existing snake and so what we can do is use something in unity called prefabs so let me explain how this works here we have our snake and i'm going to just duplicate this i'm going to first call this or i'm going to call this snake segment and all we need on our snake segment is the renderer and our collider we don't actually need the rigid body and we don't need the script itself the script will only exist on our main head object same thing with the rigid body the only the head object sort of controls the movement of our snake so only that object needs the rigid body our other snake segment does not and what we can do is actually drag this object directly into our project panel at the bottom it's going to turn this game object into an asset that we can then reuse over and over again so this is referred to as a prefab you can even see the file name is called snakesegment.prefab um i can actually delete this from our scene we still have it here as an asset and for example if i were to i could just create a bunch of these in our scene and now i just have copies of them right it's just a way of me of sort of cloning a object over and over again and let me actually reset the transform here okay good that all looks good and now we can reference this prefab in our script let's go ahead and create a reference to our um prefab here the type should the type is often just a game object but in this case since our segments list is a list of transforms i'm going to type this as the same as that and we'll call this segment prefab let's take a look at what this does in our editor so creates a new property here and then we can create a reference to this object and so we can take our prefab and drag it in there and now we have a reference to our prefab in our script here let's go ahead and add a function called grow and what this is going to do is it's going to instantiate a copy of this prefab so we can do that by saying instantiate and then passing in the object you want to clone so this dot snake or this dot segment prefab awesome and then let's um keep a reference to this new segment and then we can add it to our list the other thing we need to do though is set the position of the segment to be at the end of our snake object so it should be we're going to add them always to the tail and so what we can do is say segment dot transform or well it already is a transform so i don't need to say that but i can say segment.position equals and then i can grab the very last element in our current um from our current list of segments segments.count minus one will get us the very last one and i can just set the position of this new segment to match um to match our tail object awesome now we need to call our grow function somewhere and this is going to basically be the same thing as our code from our food script so actually go ahead and just copy that and in this case um other.tag is not player but it's going to be food instead and then we'll call our grow function now i haven't established that tag yet so let's go ahead and go to our food game object and we need to mark this as being food now that's a custom tag so i can add a new one i can click the plus button there and we'll call this one food and save that go back and now i can tag this as food which will satisfy this condition here and then we'll call grow awesome now that's actually we'll go ahead and test out this isn't fully working out well let's go ahead and just test out what happens here so notice how i now have more of these segments you can see in the left hierarchy more and more of the segments are being cloned they're not positioned correctly and they're not moving with the rest of the snake and so that's what we will do next but they're at least spawning there so what we need to do is make sure all of these segments follow along with the rest of the snake and so we're going to do that in the same place where we move the rest of our sink which is in fixed update and the important thing here is we need to move everything in reverse order we need to move everything from the very tail to the to the head first and i'll explain why in a minute um but we need to loop through our segments oh and that so i just said we have to um we need to change the position of them in reverse order so i actually need to loop backwards here so this needs to be start at the end and it needs to go until it reaches zero and instead of plus plus it'll be minus minus and we can say segments i position equals segments i minus one dot position so let me show you what this is doing it's it's easier to visualize it in our editor here so we have our snake and let's say there's a couple segments here okay we're changing the position in reverse order so we're gonna go with this tail one first and the tail one's gonna assign its position to be the one in front of it so it's gonna move to here and then we'll go to this one and this one's going to move to here and we'll go to this one and this one will move to here and then finally our head game object will execute this code to move its position there so this makes sure that sort of each segment is following the one in front of it and the only way to do that correctly is if we iterate in reverse order and make sure we update the um head last let's go ahead and retest this out now here we go look at that so you can see the snake is getting bigger everything's following along appropriately and it's working nicely now one thing i might want to do is visually distinguish each of the segments in the snake so we can actually go ahead let's go to our snake object here well actually you know let's go to our snake segment prefab that we created and i can change the scale of this object just slightly so let's say 0.75 and 0.75 and now let's see what happens so notice how there's sort of some extra spacing in between each segment which just maybe helps to visually indicate um the different segments i think it just overall looks a little bit better that way i think i'm going to actually increase this a little bit maybe to 0.9 and i think that might look a little bit better i just want a little bit of gap in between these segments so you can start to distinguish them yeah that feels pretty good all right there we go so that actually completes our snake growth which is sort of the kind of the most important aspect of the game and all we have left to do now is to handle collision on the boundaries as well as when you collide into yourself all right we're nearly complete with our game we just need to do the final collision detection let's go ahead and open up our snake scripts once again we're just going to expand upon this and we already have our function here on trigger enter which we use to detect collisions so if we add another if statement here so instead of detecting when we collide with food let's say that when you collide with maybe an obstacle well then we will reset the state of our game so let's call a function called reset state let me add that here and let's go ahead and tag our game objects with this obstacle with obstacle tag so first i need to add a new tag obstacle and this really just looks the exact same as what we did for our food obstacle i'm gonna go ahead and select all four of my walls so i'm gonna tag those as obstacles and i'm also gonna tag my snake segment prefab as being an obstacle too because that's the whole premise of the snake game where if you run into yourself you lose and so you yourself are the primary obstacle you're trying to avoid so we're mark the snake segment is obstacle but we need to make sure we leave our main snake head object as the player because um on if you remember on our food script we check to see that if the player collides with food well then it will eat it so only the snake head object will will do that all right so back to our code we check if we're colliding with an obstacle if we do we will reset the state of the game so what are all the things we need to do when the game resets well we need to clear out our list of segments and start over again so we can iterate over this and we actually want to start at index one instead of zero and that's because index zero is our main snake head object which we don't want to delete um and in fact that's the object that this script is attached to so we we definitely don't want to delete that one so we'll start at one here we'll say segments.count i plus plus and we can go ahead and call a function called destroy and we can pass in a reference to a game object we want to destroy um it needs a game object reference not like a transform our list here is a list of transforms so we can say transform.gameobject get the appropriate reference there and we can clear our list and we actually need to make sure we add back our main head object we didn't delete this one so we need to add that back but we do need to clear the list because even though we're destroying these objects there's so technically a reference to them um and then finally what we need to do is reset the position of our snake back to the start so we'll just say position equals zero and let's go ahead and test that out play our game oops play eat a piece of food there we go we're growing let's run into a wall there we go all the segments disappear my character resets let's test all four walls yep so on all four walls i was able to um i reset me let me test if i run into myself i need to make our snake a little bit larger first oh i screwed that one i just completely lost on on my own faults alright so let's get a little bit bigger [Music] okay let's get one more we'll do we'll do one more okay that should be big enough there we go so i ran into myself and it reset so everything is working correctly that looks good nice now one thing i don't like is how when you start the game you you are size of just one it doesn't really feel right to me so i think i want to make it so the snake has an initial size we can go ahead and declare a variable for this called initial size maybe it has a default value of four i'm making this public so i can tweak it in the editor i can i will be able to change this value in the editor in case i want to to have a different size and then like when you reset this state of the game we actually just want to add back however many segments until you've hit that initial size so we can say for int i equals zero well actually we'll start at one again because we've already added our head and so i is less than our initial size i plus plus and we'll go ahead and say segments dot add and we'll instantiate um our prefab just like we did up here all right let's see if that works correctly if you look in our script here you can see the initial size is for nope that did not work correctly oh and that's because um so it'll work correctly when you lose so there i lost and then our size gets reset but on the very start of the game this gets called but we aren't executing that code so i'm actually going to change this to just call reset state whenever your game starts now there's this one problem this will cause and that's because in this function we are accessing our list here our list has not yet been instantiated and so it'll actually cause a crashing error and so let's just go ahead and initialize this right away to make sure we don't run into that problem let's try testing this one more time yep so there we go we have an initial size of four i can still continue growing if i lose it resets let's say for example i change this to eight play again and there we go now we have an initial size of eight and so that feels a lot better it feels a little bit more natural awesome that actually completes a sort of core working game of snake this was just a pretty simple implementation of the game snake but i hope you learned a thing or two in the process i would actually challenge you to see how you can continue expanding upon this foundation we've built here what else can you add is there any new features or functionality you can add any new game mechanics one thing we didn't really do at all in this project was any ui stuff we didn't really add like a start menu or or game over menu so maybe that's one way you can continue expanding upon this all of the project files and source code for this game are available to download for free in github there's a link in the description of the video i've gone ahead and cleaned up some of the code and added some additional comments that you can learn from i appreciate you spending the time with me to learn how to make the game snake in unity if you feel like you've learned something then go ahead and give this video a thumbs up if you would like to watch more videos very similar to this one then go ahead and subscribe feel free to leave a suggestion in the comment as to what other games you might want to recreate that we can all learn from thank you you
Info
Channel: Zigurous
Views: 159,765
Rating: undefined out of 5
Keywords: unity tutorial, unity, how to use unity for beginners, how to make a game, unity 2d tutorial, game development, how to make a game in unity, unity 3d, unity 2d, game dev
Id: U8gUnpeaMbQ
Channel Id: undefined
Length: 47min 24sec (2844 seconds)
Published: Wed Feb 17 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.