Unity Basics: A Monetised Android/iOS Game in 4 Hours. | David McDonald | Skillshare

Playback Speed

  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Unity Basics: A Monetised Android/iOS Game in 4 Hours.

teacher avatar David McDonald, Husband, Game Dev, Web Dev, Photos.

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

41 Lessons (3h 56m)
    • 1. Welcome

    • 2. Installing Unity

    • 3. Setup for Mobile

    • 4. Functions And Unity

    • 5. Variables

    • 6. Test

    • 7. Materials

    • 8. Player Movement

    • 9. Player Movement Control

    • 10. Player Mobile Controls

    • 11. Camera

    • 12. Camera Test

    • 13. Clean Level

    • 14. Prefabs

    • 15. 014 Grouping Prefabs

    • 16. Score Logic

    • 17. Display Score

    • 18. Procedural Level Generation Explained

    • 19. Object Spawning

    • 20. Randomizing Object Spawning

    • 21. Adding World Shader

    • 22. Infinite Level Generation

    • 23. Destroyer

    • 24. Audio

    • 25. Menu Layout Setup

    • 26. Audio

    • 27. Menu Layouts

    • 28. Menu Off And On

    • 29. Menu Start Game Button

    • 30. Pause Menu

    • 31. Game Over Menu

    • 32. Saving & Loading

    • 33. Menu Animations

    • 34. Quick Recap

    • 35. Unity Ads Setup Logic

    • 36. Working Unity Ads

    • 37. Ad Button Design

    • 38. Updating Player Model

    • 39. Where To Go From Here

    • 40. Final Project Export Settings

    • 41. Thank You (this is not goodbye)

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.





About This Class

In 2013 Dong Nguyen spent 2-3 days making a simple mobile game called Flappy Bird which went on to earn $50,000 a day in ad-sense revenue. In the last half of 2018, it's not uncommon for a single mobile game to pull in over 1 million dollars a DAY in micro-transactions and ad-sense revenue.
In this course, we will be be making a simple but addictive mobile game, that we will monetise with ads in only 4 hours. No programming experience is required, All you need is a computer with an Internet Connection. We will cover;

  • Installing and Using Unity

  • Mobile Setup

  • Variables & Functions

  • Materials, 3D Models

  • Player Movement

  • Mobile Input

  • Camera Movement

  • Adjusting Player Models

  • Project Management

  • Prefabricated Objects

  • Grouping Prefabs

  • Score System

  • Procedural Level Generation

  • Object Spawning

  • Randomised Game Design

  • Curved World Shader Implementation

  • Object Memory Management

  • Menu Systems, Menu Layouts, Menu Animations

  • Pause Menu

  • Saving & Loading Data

  • Unity Ads

  • Monetisation Design Principles.

Meet Your Teacher

Teacher Profile Image

David McDonald

Husband, Game Dev, Web Dev, Photos.


My name is David, I am a passionate game designer living on the Sunshine Coast, Australia. Founder of WHAAT GAMES, creator of Galaxy Cube. My main skill set is Unity and C# programming, although I am skilled in many other areas, including making inappropriate jokes at bad times and winking at strangers. I have been making commercial video games for roughly 5 years, I have been making non commercial hobby games for much longer and I have been teaching game development for 3 years on my YouTube channel Lets Make A Game Together

See full profile

Class Ratings

Expectations Met?
  • Exceeded!
  • Yes
  • Somewhat
  • Not really
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.


1. Welcome: In 2013 Deng Wen spent 2 to 3 days making a simple mobile game he called Flappy Bird. Flappy Bird went on to make $50,000 a day in AdSense revenue. Sounds crazy. By the end of 2018 the top tier growth grossing games on the APP store and the Androids told We're pulling in over a $1,000,000 a day in marker transactions and AdSense revenue. The medal game market is booming, and it's getting easier and easier to create a game with every coming month or year because of new technology. However, if you've never made every digging before, it can still be a very overwhelming task. Hi, I'm Dave. I've been creating commercial video games for almost five years now. I've been creating video games for much longer and just not commercial ones, and I've also been teaching video game development and video game design on my YouTube channel. Let's make a game together. In his course, we're making a simple yet addictive monetize without support Mobile game in under four hours. I'll be teaching those courses if you've never done any program before in your entire life or game development in your entire life. However, this course will also be suitable for people who just want to get a game on the market. You just wanna finish something and just have their product, their creation on the market. I found that when I started out understanding the entire process off studying game from start to finish really help me understand some of the core ideas behind game development. This course will cover everything from installing. Unity will be sitting up from mobile will be talking about functions and variables with animations. It will help you understand what these things actually do. We're talking about object materials were getting out playing to move around without finger mobile control. So we talked about Mobile important doing a score system saving and loading were doing some basic basic procedural level generation and created getting a level that continues on forever infinite level generation. Talking about shader is keeping a code neat and tidy as well as implementing menu animations. So also be installing unity ads which will help your game earn money while you're not developing games, which is always a bonus, and talking about some very general game design principles at the end of this course who have a good understanding that what goes into making a video game and more importantly, you'll have a finished product that it got to show your family and friends and get on the APP store. I'm confident than you'll gain the skills and knowledge required to build a simple May ballgame. We've had support, so we'll have said Let's get started. 2. Installing Unity: So if you are absolutely brand new two game development, a lot of what we talk about and do will be a little bit confusing to you. And that's totally okay. When I first started out, I did not understand anything. I was so confused of the most simple concepts like I didn't understand what variables were . I could understand what functions did. I didn't understand how it was put into a game. How do you put a game on the APP store? These were all very, very confusing for May. So if you don't understand everything perfectly, that's totally fun. Just follow along with the tutorial, and I guarantee, by the end you'll have a working game. When you understand the whole concept from a game from start to finish, you better be out. Understand the concepts that we still we talked about at the beginning of the session without being overwhelmed. So the first thing going to do is go to unity three d dot com and click Get Unity. You know he's a free game engine that basically nine off 60 or 70% of all games are made on . You can make mobile games. You can make three D games. You can make amazing games. It's pretty. It's pretty, pretty awesome and free. Um, game engine. So we're going click Try. Personal. Personal is the same as Pro or plus, with just a few little features removed. Like so, for example, we can't have our own splash screen on on personal. You have to have the created by unity, which is totally fine. My games have got that quick. I can confirm down early in store for Windows or for Mackel. Whichever operating system that you're on, it will download. You'll see some free assets here to help you get started from free tutorials. You can open up the installer and just run through that to install the latest version of unity. Don't worry. If you don't have the exact same version of unity than anything over this will work, farm, everything that we're doing in this tutorial. So don't stress about that because I've already installed unity. I'm just going to open it here. But before we do that, I'm gonna download the project files. So what are the project files, the project files or things like audio? It was like a theme song or it's things like that. Sound effects, things like out sprints for the game and just things like that little assets that you can't create inside of unity. But we will be used in this project. If you want to use your own assets, that's totally fine. You can use your own sounds, union visuals. If you want to use ALS visuals that are in this project for your own game and release it on the Android store or the IOS store, any type of game, that's totally fine as well. Do what you do. You okay, So let's start a new unity project. So it startup Euna Lee were gonna click new. Make sure you sign in with your account, which I'm sure that you do gonna choose three D template. We're going to name it Balloon Beach. I always spoke balloon wrong movements playing among now, but I'm not gonna check and we're gonna check the location. I'm gonna choose location off where to save a game chooses anywhere that you feel comfortable saving it on your hard drive. You know you can leave, you know, the analytics owner offer doesn't really matter, and we're gonna create Crate Project you know, we're now creating a new project and set everything up for us. Okay, So when you know he starts up, this is what you'll see. If you've never opened unity before, once again, you'll be overwhelmed. But don't worry. We'll get through it. Okay? The first thing we're going to do is we're gonna do a little bit of tidy up, so I don't You need starts off by creating photo called scenes. I don't really think we need that. So what is going to delete that, then we're going to drag in at project files, so you just click them and drag them into the assets window here. Okay, Fantastic. So now we have a new unity project with a, um that is overly to rock and roll. We can press play and see what I game does right now. It does nothing. Just a camera in an empty space. We can see if he we have our services. So we have, like, you know, the ads turned off in the analytics. Turned on which was that that question with start collab bills and bunch of other stuff that we don't really need toe worry about. We can click over to the inspector. The inspector is something that will be using for most of the game. So if I click on something like the camera, you can see all the information that we have for the camera that's in the game or the directional light. Over here, we have out scene. We have all the all the items that are now seen Over here we have our seen view. So we can if you right click, you can, like, kind of move around the scene If we wanted to, like, you know, at a ah, at a cube, we could add a cube and we could, like, move around and you can see over here in the game game view, you can kind of see Cube. If you wanted to make the Q bigger, you could come over to queue of here and drag the axle. You could drag the the why and the scale make it bigger or smaller. He could do whatever you like, or you could click these buttons up here so you could get a hand tool. Move around. You got the, um, don't actually what is called the move tool? We can move it like along different accesses. Or you can just, you know, grabbed by that move around. You got the, um, rotation tool, which obviously you can rotate and all of these. Ah, all these work with, um, messing around with the transform information appears soldiers based on numbers. So, for example, if, um, I'll show you an example in the SEC, But say if we also wanted to, like, grab, you want to grab the scale tool, you get scale things like this pretty simply and so on. You just play around these tools if you like, but say if we wanted to, this is to leave this Q because we don't need it. Say, if we wanted to grab a new cube and let's just say Cube and we wanted to make sure the Cube was right in the center, we could change his exposition to zero its Y position to zero and a Z position to zero. And now this is exactly in the center, and we know that the cube is 11 has a width of X value of one ah y value of one in his e value of one. So if we want to create another cube copy paste. Now the queue. The other Cubans are the that cube and say, if we just wanted to be right next to other, Cuba could just change the X scale to so not the scale. Sorry. The position to to not one. Sorry. So one. Then we know that these two right next to each other, which is pretty cool. Do you need something that we need to worry about? Let's just delete them. Don't need them is down here we have our assets. These the the items, I suppose you could say, like out scripts, out audio, things like that, things that are actually going to be in our game and included in the build. So if you like making your song and want to drag it in, you can just drag it in. We got a console down here which is used for debugging code will be using this a fair bit and we have our animations which is used for creating like animations like whatever we want to do, like going to a ball bounce or something, we can create that in the animation section 3. Setup for Mobile: Okay, So the last apartment to do before we get stuck into game development is money to set up our project to work with the top of game that we want to make. So we want to make a mobile game. So it's pretty easy to do sophisticated. Who is going to file safe? Seen as I was going to save this seen as the main cool. So now we can see the scene has popped down here in the assets menu, every click on out. I mean, we'll open the scene. Happy days. Everything is going well that we want to go to file click build settings and it should or should or automatically be on the PC Mac in Lenox Standard Line. What we want to do is we want to click on the IOS, or we gonna call on Android, depending on what you want to develop for personally, they're both pretty much exactly the same in regards to what we will be doing inside of unity. So choose which one and you want to click to you wanna click switch platforms so mine's already on our way. IOS. But quick switch platforms and what that will do is it will move the unity product over toe work with IOS. It should take, you know, a couple minutes to do the next thing we want to do after that, that's kind of worked. Grow back into build settings and we want to click add open scene. So you can see here we have that deleted scene that we deleted the start. We can just leave that and we added our open scene, which is that main seen. So if we wanted to say build our game right now, we could actually build the game, and then we could actually move it over the X Code or we could move it over to Android Studio and we could pull on the phone and we would actually say he this game, that's totally it. Like you've already created a game. I mean, the game doesn't do anything. It just a camera and empty space. That's all you to do to basically set up the project to work with Mobile. And I'm sure you felt found it interesting that you can also do Xbox one pierce for Facebook. I mean, unity is a really, really dynamic Um ah, game engine and after you create the project obviously have to do a little bit more tweaking in there, Um, and for example, X code or endurance studio to get it to get it to work. But basically, that the majority of the work could be done in unity and exported to all these different platforms is really cool. So the next thing we want to do is we want to change your game aspect ratios. So this is like the camera, like what the game will actually look like. And we could sell it to, like, the iPhone tall. Or, you know, if you're on Android will have some different options. IPhone iPad, wide iPhone, four tall. And you know, it has a different resolutions, but for ease of sake, I'm just going to create, um, a new, um resolution, which is exact resolution of my phone. I currently have the iPhone seven plus, which has a resolution off 10. 80 by 1920 so far. Going on here in press the plus button, I can create a new, um, uh, resolution. We're gonna call this my phone or Andrew or whatever you wanna call it, and I'm going to make the width 10 80 and the Hunt, 1920 and press OK, fulsome. So now this is what our game look lack when we press play. That's what the camera looks like. And we're all a sudden. We've got the correct aspect ratio for air games working on a mobile platform. It's totally awesome. In the next episode, we'll do a bit of a scripting primer for people who have never done cutting before, just need a refresher and also explain how unity uses scripts and how unity works to create an actual game inside of the game. So see you there. 4. Functions And Unity: so games runoff code off programming programming is just instructions that we give the computer to do certain things. So, for example, if I wanted a gem to rotate, I could just tell the computer Hey, make this gem rotate and that's it. So what I'm gonna do is I'm gonna create a script just to explain some of the core concepts of programming and what unit he does but those lines of code, But with those instructions you don't need to follow along with this section because I'm just gonna delay the script afterwards. Rumors going to use it to illustrate a point. So if we rock clicking, that's just what if I right click and just go creating you see shop script. We're gonna call it test. Open that up. It will open up. It will open up in visual studio or another code editing software once is open, you'll see a bunch of different lines that are already in there. Don't worry. You don't need to worry about any of these too much, but I'll just quickly go over them thes e you name spaces. These are basically telling what what packages? They're going to be included in inside of Ah, the script here. So add more to this so we could add less. But in general, we actually don't touch this. Then we have our cloths at classes, basically the scripted itself. It's basically the big um can you say the big the big Ah, think of it like, um, all the instructions will go within this class here, and the class is called test and it derives from monitor behavior. So just quickly another side note, your code might look a little bit different to mine here. If we click here and I press space and access expects Perspex backspace, your code may look like this. This may be how unity has or visual studio has formatted your code. You can change these settings so it looks like mine in debug options. I didn't go through and you get the code before. Might have. However, you like. This just happens to be the way that I like to format my code. It's for the open color brace to be on the same line as the method, and the clothes could go. Brace is on the end of the method. However, this doesn't actually affect the code of law. So you just This just makes it look a certain way, but it doesn't actually affect have a code runs. So if you want you code to look like mine, you go to debug and options. But if you just want to leave it as is, that's totally fine as well. It won't affect our anything runs. Just make sure you understand that your code well look like this on my code. Look like this. Awesome. Then we have two functions we have avoid start and void update. And on top of those we have comments. These comments could be anything. If you just put two slashes, you can write anything, and it won't be affected by the code. So, for example, I could drive this method go function, function and method of basically the same thing you might hear me say. Say either one. This function or method, a method or functions are, um, happens once at the start of the game, and this this method or function happen happens every frame of the the the game. So if we wanted to write something out, if you wanted to write some code, that would actually do something. Say, if we wanted Teoh create something that happens once at the start of the game, we could put it in here so we could press enter to do in need line and we could write debug , log every bracket open. Ah, um speech marks. And we could say this is the start function working. And in the long we want it, I'm closed off by using a semicolon. Cool. So then, if we go back into unity and we just drag this script onto the main camera, it could be but literally in any object in the game. But we're gonna grab just dragged him to the main camera and we get him go over to our console. What we actually asked to do is we've asked to at winning the game stance we want to run. This line occurred debug dot log. It's going to log some information to the console and the information that we're going to log is this statement here. So if we go over to the console press play, we should see that's unmask semis on play press play again. This is the start function working cool. So we've written our first line of code. Now, what if we want to write something in here? Well, this is copy and paste this debug log, and we have a script here. The this is the start function working. Well, this is the update function, which is to say, this is the update function, working every single frame. Save this press play. And you see, we have started being called once, and we have down here. This is the update function working every single frame. And it's happening every single frame. Cool. So they're the basics of how start in update work. But if we want to create our own method, that's totally easy as well. We could say something like void. Yeah, own method. It's gonna make sure it has these and the two curly braces and the took to color braces. Anything we put in between this will be our method, our own function. So we could put whatever we want in here. So we could copy a debug dot log in. We could chuck it in there and we could write. This is our own method. Save that. Go back over to unity, press play and bam, nothing happens. We have to start function working, and we have the update function working. But for some reason or other function isn't working. I wonder what it is. Let's get back over to the script and find out. So we have voiced our void update and void our own method. Now, I could've name this whatever I wanted. Blood just chose to call Aaron Method. But the problem is this isn't being called at any time. Update automatically calls. Every frame start automatically calls with Stan. And there are other things like awake that gets called before start. But we need to actually call this so if we want to call this once we could caught, we could put it in start. Or if we want to call every frame, we could call it in update. Let's just call it in stop for now. So we're going to say now I mean method done so then we just cold this method from start. So when the game starts, it will call this line of code. It will move down here and do this instruction to press play. This is a stop function working. This is their own method. This is the update function working every single frame. So that's a quick primer on basically how code works inside of unity. Now, obviously, in the real world will be doing doing our own doing some different in the real world, we won't be just doing debug dot logs will be doing things like moving objects or rotating things or making collisions work. And all those things are pretty simple to do inside of unity. They just list of instructions that we need to do, and it will be overwhelming if you've never done cutting before. But just trust me, follow along. By the end of the entire project, I guarantee you'll be much more confident training next video for an explanation on variables and how they work in the game. 5. Variables: So we're just going to delete this script that we just right. We're going to go up to Main camera, will notice that the script now has is saying it's missing. And so if we just highlight over that and click remove component and we're just going Teoh , explain exactly how I'm variables work inside of unity. So let me create an example. So I'm gonna create a new scripts New Say Shop Script Nicholas Variables. Let's open that one up. Okay, so Well, it started with the same template. But this time a class is called variables. I'm going to show you a few different types of variables. So two todo star very well we say public, we can also say private, but just for just for simplicity sake, we're just gonna need more public for this at this stage public int hole number. Actually, let's call it something different. Let's call it car speed equals 45 45. Cool. So an integer is a hole number number. Sorry, my this key boys really had to type on and then we got a different variable. A public string. I'm gonna call this player name equals Dave and be good Another variable called Public Bull and we're gonna call this is is player in spends band Dory in Boundary, and we're going to equal that too true. Okay, fantastic. So, um, this so a string is basically just like let's just call it text for now, But it's probably best way that you understand. It's just text. It's just in from It's just a packet. It's just a container that holds the information. Dave, this is just a container that holds the information 45 whole numbers and this is the information that holds a true true or false statement. Okay, so this is probably very confusing, and I totally understand why, but if you've never done program before But if you have then a liberal programming, it should make a little bit of sense. But variables of what we use to store information and manipulate the game world. So, for example, if we had a car that was going at 45 then the car crashed into a wall, will then we could say, you know, um, this this isn't actually towed, but let's just say it was code. We could say if, um ah car crashed um, into wall. Then we could say, Um costs paid equals equals zero because the car would then be going at zero speed that is backed. Plan to go won't work. Don't use that. That's just that's actually garbage. That doesn't work, but it is implementing a point. So what we do is we just we ask questions to the computer. Well, how fast is the car going? Well, if the car is going at 45 then we want to move that car object at the speed of 45 is the car in the boundaries is a player in the boundaries? Well, if it is, then, um, if it is or God is true. But if it's not, then we need to do something. So a real world example is say, we have a car traveling down a track and the car drives out of bounds, and what we want to do when a car drives out of bounds is just like it happens in Mario Kart, the video game where when you drop out of bounds, the card gets picked up and put back onto the track. Well, if we want to do something like that, that's pretty easy. We could say if we could say inside of update, we could say if this is what if statement is so what's asking the computer if is playing in bands equals two equals? Signs asks. The question of people's If car is inbounds equals both. Open up, curly braces, close curly braces. Then we want to say them We can say something like, you know, move, play. Ah, back to track And that's it. So So that would mean that as soon as this is ticked to false, the player will get moved from wherever they are out of bounds, back to somewhere that we put on track. So if you look at these variables here we have a float, a string and a bull off. Floaters liken inter job, but they're like decimal place numbers, so an interdict can't do decimal places, but afloat can, so you can have, like 4.2 45.6. So there are a lot better for doing things like car speed. A string is a car is the car name is this red boy, which will be the title of the car and a ball. It's like the bull that we were talking about in our script is car inbounds is car inbounds . The sequel to True. This car name is equal to read Boy, and the car speed is equal to 45. Let's see what happens. Okay says So you could see here in this example, we have a car troubling up the highway. The car is going at the speed of 45. Its name is Red Boy, and it's inside the bounds, so everything is working fun. So in that situation we have used 45 the variable car speed to determine how fast the car can actually travel. Was saying, Hey, the car speed is 45. Therefore, make the car truck travel at the speed of 45. Pretty simple Run, but have a variables actually worked to affect the gameplay? Well, look at this next example. In his next example, we have the exact same situation. The cars traveling at 45 his name's Red Boy and is kind. Bounds equals true, but let's see what happens when the car drives onto the dirt. What's the float? Car Speed variable. It's 45. Car speed goes down to 20. So as the cars driving along, still driving at the earning, the speed of 20. He's going to drive out of bounds. Look, what happens to the bull is car inbounds turns folks, and also the car speed turns to zero. So what happens then is the game goes OK. The car is out of bounds, so let's move the car from where it is. Now back onto the track and put the cast you back up to 45 the car can burn around that corner and speed off into the horizon. Everyone is happy, Happy days. So that is just a quick example of how variables used in a game engine determine how things work to determine the logic of how the game works. 6. Test: Okay, so it's time to throw you guys into the deep end. A little bit of a little The variable script and project is back to where you guys should have it. And I want you guys to create a new script, create see shop, script, you guys unquote whatever you want, because we're also going to delete this. Okay, so I'm gonna show you guys how to do something pretty interesting. I'm going to create a variable, cold public bull. Is Dave a good look? That's gonna evil. The false sad. Then we're going to go down to the void star, and I'm going to say debug thought log. I'm gonna open and close some speech marks and say, Is Dave a good look? Question? Mark Put a space in there, and then after the speech marks, I'm gonna say, Plus, I'm gonna add the variable is David Good bloke. So what's going to do is it's going to say it's got a bit variable. That says is that was a good bloke. Is David good bloke articles false. And then it's going to log out. Is they have a good bloke and it's going to tell us the answer. So if you go back to unity and drag out script onto the main camera and press play and we move over to our console is a day of a good bloke False. Ah, it's sad. So what we're going to do is we're going to, right? We're going to change that variable. So after we've logged it is David. Good bloke. I'm going to write his David. Good bloke equals true cool. And then I want to copy this and I'm gonna pace underneath. I'm gonna say, Is Dave now a good book? Give a gravity unity and press play is they have good book. False. Is Dave now? Good, Blake. True. So what's happened? There is our variable. Is David Good bloke started is false. Go printed out His false got changed to true and then got printed out. It's true. So for the test, I want you to know I want to see if you guys can do the same thing to see if you guys can create a variable. Get tau, log out into the inspector, change that variable and then leg it out again. You can use any variable you lock. You can call it whatever you like. And you can change the value to whatever you like. Give yourself 10 minutes to complete this task if you get it done in 10 minutes. Hey, happy days. You're pretty good. If you're still struggling externally fund as well, you eventually pick it up. In the next episode, we will start coding the actual game. This is where the project will pick up at a faster and faster pace. Since soon we'll have a working prototype that we had a show your friends and family see there. 7. Materials: Okay, so let's start actually working on the game. This is where it gets exciting. So it's the later script. Whatever. We don't need that. That was just for the test. On day we're going to create a couple of the photos were going to create a new photo, Cold Materials. This is just for organization. We're incredibly photo cold scripts. You have to create these folders, but I just like to keep things organized. So inside of the materials folder, um, we want to create some materials, so I'm going to create a new, um, material. Nicole is grass. And when he created a new material by right clicking and she's incredibly material in calling it water. So with the grass, I'm going to come over Teoh. Click on the, um either one Click on grass, Come over to your BDO Here, click on this little color wheel and I'm going just trees like a nice in durable green color. And for the water. You guessed it. I'm gonna choose a nice, simple blue color cool. So it created after materials and now we're going to create just a plane for to do some testing for our bold to roll on, like to get the ball going. So we're going to go over the game object and we're going to Could a new three D object? We're going to create a new cube and we're going to course. Cube actually recall his grand For now, we're going to change its position, 2000 and we're going to change its scale to just something that we can work with. 100 on the X access and 100 on the Z exodus, and you can see it's incredibly bright. It's something that it's yet it must have brought. It's completely what so in now seen. So if we seem out here, you can see we have, um just a big flat want. Yeah, you basically, um And we get a direction a lot here that we can you know, um, change the colors, change the direction, things like that. And we got a main camera. So with the ground, we just want to click on the ground, and over here we'll see the components that are on the actual ground object. So we have a cube mesh filter. We have a mesh renderers, and we have a box Kalata. So the Kalata is what we use Teoh to detect, whether up with objects to have collided with the object or whether or not they inside. The object, if you click in, is trigger and the mess surrender is just rendering the actual mesh of what the actual object is. So if you see under the measure, render a section and we have a section called Materials. If you open up that material, you'll see that it has an element, and the element is just the default material. That's what painting into the all those white. If we click and drag our grass material over you, notice that it turns green and it looks much better, in my opinion. So that is just a quick and dirty way of getting a material to look a little bit better in unity. Just click. Just creating a new material changes colleges dragging along to the Cube, and now we have a an environment that looks a little bit better. Toe work in in the next episode will start our first script and we'll get the ball rolling . Pun intended 8. Player Movement: in this episode, we're gonna get some movement happening. So the first thing you want to do is create a new game object, and we're going to create a three D objects. And we're going to create a, um, sphere call this V for you and will send to the player. So we double click. You'll see that the player is right inside the ground, and that's because our ground is actually at the same location. And he's actually the same hot. So if we actually grabbed the ground, drop down the wine position, stand to negative one, because that'll make everything perfect. Cool. So we have a player at 000 and player has a mesh render, which makes it look like that it has a V Kalata. And just to make things pretty, let's create a new material, um, material in close player to him. I just cannot stand that that white color and let's go over to the sphere and go to material and drag the play. A temp color was changed it to call your lack. Let's just say that's pretty grace and say Yeah, red red works you can see pretty clearly and then we're going to grab a player. You see, it has a mesh. Render has a speak a lotta, and if we press play the game does nothing. We haven't told them to do anything, so that's what we would expect. So if that's what's happening for you. Hey, everything is working well for Goto our console. We should have nothing here or we actually have two errors. The reference script unknown is, is on. The behavior is missing and a reference script on behavior game object. Okay, let's go over to a main camera assist. Oh, that's the script that we deleted, and it's still trying to access that. So we just need to remove that coop. It's good to see the debugging process. Sometimes we press play again on get back to Sorry, get out of play mode and remove component and then press play. Now console should be absolutely free and clear, so we have ah, player and there players just sits there. Nothing happens. And, um, that's because we haven't told the character do anything if we dragged the character up, would say a little bit. Press play. Nothing happens either because we haven't actually told you need that. We want gravity to effect this game object, and it's really easy to do that. Inside of unity with you just add something called a rigid body. So if we click on add component and click rigid body, no. But your body to day make sure it's rigid body and would click use gravity and mass and just just all the exact same settings. That comes as default and we press play bam! It falls down until it hits this clot of its on the ground and doesn't move any further. Awesome. Now we have physics working in the game now, given they're not amazing physics but the still physics nonetheless. So now we want to go over to our scripts photo we want right click on Create a new C Shop script. I'm gonna call this player with a capital P. Best Best practice Teoh. Name your scripts with a capital because that's the class name and classes usually start as a capital. This is just good scripting practices, And so once we create a script called Player, we want to double click to open it in visual studio and we can get to programming. Okay, So the first thing we want to do is just get the players move so it is seeming a little bit and we probably don't need the star. This will just leave. The start will go into the update and what we want to do is we want to actually access this player. We want to access the component rigid body on the player and we want to tell the rigid body to move it in a certain direction we want Toe adds a certain force in a certain direction. So if we go back over here, we can actually say get component inside these two little triangles if ago, with a cold Richard body, I'm prints thes close parentheses dot velocity So we were just choose with the velocity is and we just want equal that to vector three dot Ford And we want to times that by, let's say, 1000 and we wanted times that by the time the adult time So what's happening here is where getting a component that this script is attached to well where accessing the rigid body were accessing accessing the velocity on on the rigid body and we're equaling that to a new vector three go forward, so that just means this is a direction. So we're saying the velocity eagles, this direction and with times in a direction by 1000 and there were times in that by time to Delta Time. Tom do adult time is the time Parsons the last frame If you want something to move it a concert velocity speed, for instance, multiple that by time to a double time. So you get consistent results if we then save the script. When we get back over the unity we press play, nothing will happen. Well, how play will fall to the ground. But if we actually and the reason nothing happens, because the script isn't actually attached to the game object. So what we can do is we can actually click on the player script and just drag it over. Or we could add a component and we could type in player and you'll see our script pop up there. Either one works just fine and let's get out. Player was dragged them back down to Earth at zero, and let's press play and it should move forward. Awesome. That means full, quite fast, and we can't control it yet. But in this episode we have looked at how to get a script attached to a game object, and we've worked and we've got that game object to move forward in at a constant rate, and we've added some physics to that. That game of export falls down from the sky, so everything is going going well in the next episode will touch on how to control the ball and its direction. 9. Player Movement Control: Okay, So to get some movement happening, let's double click on our player script, and we're going to create a couple of variables of at the top here going to create a public float. I'm going to call this via speed if you start with a small, um, P will small letter and then you whenever you write a, um, a uppercase letter, it will actually split That, and the reason we say public is so that we can access that in the inspector's. So if we go over to the inspector and go over to the player, you'll see that we have now a player speed variable here and you'll see that it's been a player speed and it looks Nazi formula. So these are just coating best practices and we want to create a We don't need to access this in. Yeah, actually, create a public withdrew the access. It makes it public public floats. Directional speed. Okay, so now we have two variables. Play a speed and direction speed. So place people deal with, like how fast the actual ball is. The player is moving forward on directional speed will be half arson moves left and right So we actually a already using that were already using this number somewhere, right? So we're actually using it down. Here were times in Victor three dot forward by 1000. We can change this 1000 to play a speed, and if we press save and we go back over to our, um, game, you'll see that we'll have to variables here pop up. And if we press play, you know something very interesting. First of all, nothing happens. Why is that? Nothing's happening is because the public float players speed. We're now times ing Vector three to afford by player speed and play a speed currently equals zero. So what happens in Mass when we talked something about zero and equals zero? So if we actually we can actually changes in here so we can actually drag this forward and Ford, Ford, Ford, Ford and you'll notice that at 184 that's how fast out player is moving. We could make this 1000 and that's how fast it was moving before, or we could actually make it negative. 500 and, yeah, they're old numbers. They will do stuff, and negative 500 means is actually moving backwards. But you can see now it's under the floor. You got some wacky results. We can actually create the default in here. So let's say, because we're using 1000 before that was a little bit fast, let's say 500 so we can say equals 500. So now it should. Default is 500. If we want to go back over to the play a script, we can click reset, and it'll compass 500. Now, whatever adjustments we make here will then override whatever number is in here. So just make sure sometimes it's a bit of a gotcha. And you'd be wondering, Why is my script working? Just make sure that this number here a well, this number here, Maury, is the number that you actually wanted to bay cool. So the next thing we want to do is we want to actually create a float. Now this flight will only be used inside of updates, so we don't need to actually declare it up here because it's not a A class variable. It's not variable that's going to used to it the whole class. We're just going to be using it once and then basically throwing it out. So good crepe float. We're gonna call it move or is zone two? Well, that run. And we're gonna equal that to input. Don't get access open parentheses, and then we're going to open speech, quotes amergen and topped with a capital horizontal. And once again, close every line with come with, um, something home. And we just going to debug that out. Debug thought, log, move horizontal So we can see what's going on. So if we, um, press play, ignore the, um the game object for a moment and we're gonna go over to our console will see that we have zero if you press right on your on your keyboard. So I click on the plate game Impressive Rodney keyboard. You'll see that it goes upto one and negative one, and you know it changes when you press left and right on the keyboard. This is because we're accessing the unity inbuilt function called input and getting information from the keyboard. And we're assigning it to a variable cold float. Ah, foot variable, cold, moving horizontal. So we get rid of this debug dot log, and then the next part might be a little bit confusing. We're gonna write, transform, stop position. So what is the transform opposition? So if we go back over to a player will get a bunch of errors pop up. If you've done what I've just done there, don't you to fall along, But just watch. If we go over to a player, will see, we got our transform up here. So once again, we're accessing something on the game object. We're accessing the transform, and we're accessing the position. So we got an X value. We got a Y value, which is up and down. And I got a Z value, which zero allies out and we go back over the script and was saying transformed opposition . So we're saying what we want access this thing and we're going to equal that to something And what are we gonna equal it too? Well, we're gonna equal to We could equal it to back to three or four or something we could equal . It's ah, bunch different things. But what we want to do is we want equal it to a new position. So what we're going to say is vector three dot lup. So love is linear interpolation. So it basically is a smooth movement between two different spots. And right now you can see it's asking for a Vector three, a position of Vector three B position and a time it's going to take to get there. So this is confusing you. I don't blame you. This is the kind of stuff that you learn while you you learn more, Maura's. You get better programming. This is just the syntax that unity uses to control certain things. And if you're brand new to programming, all of this will go right over your head. But just follow along. Do exactly as I do, and we'll get there in the end. So the first position we want to learn from well is just the position that were out So we can say game object dot transform, stop position. And then where do we want to go, where we want to go to a new vector? Three. So this is where it gets even extra tricky. So, for example, we want our player to be able to If you watch this this game view here, we want a player to be able to move forward. So what we can actually play because we're getting some errors. We want to say the player to move in this direction here, right? Well, this is actually backwards, so we wanted to move forward and we wanted to be able to move left and right with the controls. But we don't want to be able to move away off the screen like a way off here, because that would not be fun. So we want to actually claim for the position of where it can actually move to, like, say, maybe here and maybe here, so I can only move to the different sides of, um, the screen. But we wanted to be able to move as fires. It is at once in this direction. So this one Monaco will duel that for us. So it's a pretty sweet line of code. Soon we wanted to access the transfer position equals Vector three. Don't look game object or transformed opposition, which is opposition. Now we want to change that. We want to move from our current position for me again would transform good position to a new vector free. We want to clamp down effectively with meth f don't clamp, and it's asking. Well, what do we want to clamp? We want to clamp the game. Object transform Dark position. Don't X so it accessing the X valuable variable plus move horizontal. So we're now accessing the variable that we declared up here, which is out horizontal access. Put a camera in and I'm gonna Dumanis 2.5 def. So that's minus 2.5. And because we using afloat, you put the f afterward Comma 2.5. Awesome. So that then clamps opposition. And then we want to go past the parentheses and put a common and we want to ride game objects. Don't transform dark position. Why? Remember where it's asking us for a new vector 30 And we forgot the f here. And then we want to say game objects transform the opposition. I thought that that the close come parentheses, comma, directional speed, which is the variable we declared at the top times time that delta time, and we want to close those princes. So I'm going to zoom out a little bit just so we can see the whole line of code. And it's quite a long line of code. So we're accessing the transformed what position were creating and were saying, Hey, that transform position off off play a game object equals a new war equals vector $3 up were loping, which is moving smoothly from one position to another. The first position we're moving from is the current position or play a game object. We're moving to a new um position, which is a new Vector three. That was that The X value on that vector three is clamp between negative 2.5 and 2.5. Why position is just whatever the Y position is. The Z positions is whatever the position is. And we're times in that bi directional speed times time that built the time. So the only other thing we need to do is a sign out directional speed so we can go up here and right equals, say 20 and get back over the unity. Make sure updates recent. And if we press play, we should be able to move left and rights. And I'm just going to right click on the same view and whip around just so I can see in the direction see the bull in the direction that we're actually moving and let's is dragged right back and let's just get the play on the camera and drag it right back. We can actually bring up a little bit and could actually pointed down a little bit cool. And if we press play, move left and right and enter in, it stops at a certain position. So if this episode went way of your head, I don't blame you. This is one long line of code, but it's just a really quick and neat line of code. If your project isn't working properly, make sure you copy everything exactly the same. The capital's maybe the same points would be the same unities comments of the right positions, and you need to be using everything here. Top exactly the same. And it definitely will work if you've got everything topped exactly how it is here in this script. So that's it for getting the plate player to move left and right and forward in the next episode will handle mobile controls 10. Player Mobile Controls: Okay, so to get mobile controls are working. It's actually pretty easy. So we're gonna talk about play a script once again, And what we're gonna do is we're going to create an if statement, um, just in the update here. So the reason we're doing this is because when we're playing the game on that mobile, we don't actually need, um, these two lines of code here. So we're just going to write if, uh, sorry, hash. If unity in big capital underscored Ella or and so the way you do always to these vertical lines or unity stand the line or Unity Web player, and then we're just going through under this, we're just going to write hash end. If so, this is not common code. This is not something that you would see all the time. So if it looks a bit strange to you Hey, it's This is it is what it is. So if we go back over to unity and we go to the console press play, just check that everything is working. Fine. Yep. Everything is working fine. Still that codes been saved. Everything's good. So this just means that these two lines of code won't. Actually, nothing will happen when we're playing on a mobile device. These will only happen in the, you know, the Ebola. You only stand alone or Web player. Stand alone is like windows or back linens. Cool. We still wanted to move forward. In any case, underneath that, we can actually run a note of ourselves and just right to two comes and writing mobile controls. And then we want to create a new um, we want to create an if statement. So this statement is obviously like you're asking a question, and if that statement is true, then continue on with that. The code within that, if statement. So we just want to check if input using the input class again like we used for up here. If input don't touch, can't he's great other. Then zero. Then close parentheses and open curly brackets. Press enter. So then what that will mean is whenever there's any more than zero fingers touching the screen, do whatever's in this code, so we don't want we wanted to run only if something is touching right and the screen. And so it's saying if touch can is greater than zero do the stuff that's in this code. I'm gonna need in this up here by closing. That just looks a little bit needle Kuba, before we actually do the code that happens inside this. If statement, we need to actually create a variable. Another variable that's just a throwaway variable. The variable that's on the use within the update method will within you in this method, which is the update method, and that's going to be a vector to So what is the vector to a Vector? Two is an X and A Y position, so we're gonna call this vector to touch. Touch is going to be equal to camera. Don't main. So the main camera don't screen two World point and we're going to say input don't mass position, which is a bit deceptive because it also works on my ball. Plus new Vector three 00 10 comma their Commons area Come on 10 if awesome, so creating a new vector called Touch. You don't need to understand everything that's going on here, except for this is basically getting the location off where we're touching on the screen, and it's storing it in a variable called touch and then within Um, this. Ah, if statement here we need to say, Well, if you got more than one finger on the screen, we're going Just simply say transform. Don't position equals new victor three and the first position of the new Vector three will be touch dialects. So that's part of this touch variable. So touch the exposition of this touch variable, which is their finger position, and transform the positions. That Why? Because we don't need we don't need the, um, UAE position off our finger. We're just moving it left and right, and then transform the position z. And this is saying just basically, you just stick with the day for day, folks because we're creating a new vector three cool and that is it. So now we can actually test this out. So let's go over to you. Only make sure we got no errors. You press play, and obviously we can't test it out yet. We got another reference air. I case. Let's go over to the SEC. It highlighted playoff click on plan double click. Okay, so it's saying that our camera don't may not screened. Scramble to point. I'm guessing that it's actually going well, I don't know what which, which is the main camera. So to fix that, let's go check out our main camera click at Main Camera and we can see that it's known, actually tags main camera. So we want to change it. Let's see if this let's see if this fixes this govt attack main camera, click tag and change a sonnet two main camera. So now you know he knows that when we say camera dot main. We're talking about this camera because we've tagged with the tag main camera, which is a default tag annually. Let's see if it works now. Press play. Awesome. Now we have no errors, but how do we test it? Well, we need to actually test it on a mobile device. So, you know, he actually has a an app for this on both Android and IOS that you can download. It's called Unity Remote five. And then all you need to do is plug in your device to the computer, and it should, um, show, screen like this, and then you press the play button and then it will play the game on the screen and you'll be able to test out if if your touch inputs are actually working. If that doesn't work, go to edit Project Settings editor, and you should be able to choose your device from this section here. Give it to plug in your computer. It should appear here, and you should be able to select your device. And then you be able to test out that the controls work perfectly. If for whatever reason, you're having trouble connecting your device to the computer and for some reason can't get it to to connect. And it's not working. Don't worry, because this is the only line of code that will be using to actually test for the mobile controls. Basically. So as long as you've got this written here, it means that we can can continue on. And when we get to the stage where we actually export our game and put it on, the mobile devices used to be how to continue on with the course without any troubles. As long as you've written exactly what's here. Awesome. So everything should be working fantastic, okay, And the last thing we need to do to get our movement basic movement working correctly is to make the camera for the player, and we'll do that in the next episode. 11. Camera: Okay, so you get the camera movement happening. It's actually quite simple. So where we left off is when we play the game, Al ball moves forward. We could move left to right with the controls, the keyboard, and we can also get were on em. May bomb. And but the camera doesn't actually follow the player. Now, this is obviously a problem. So there are a few ways we can handle this. We could actually just drag the player. Um, we could just drag the camera and nested within the player press play, and it does something similar to that. And of course, we could combat that with code or just, you know, make it. You know, you could do some other stuff that we're not going to to do that. So I was gonna Anesta. We could, um Goto window. We've got a package manager, and we could actually click on all we could download a package that that might even be included in your version of, you know, leave he if you're watching this. And future called Cinema Machine in a machine used to be a paid asset on the asset store, but now it is free for all unity developers because Unity has bought out the program because it was such a good plug in it is the bee's knees. If you want to make a camera for a three D game like God of War Cinema Machine, if you want to make you get a game like Mario and you need a camera, um, for for just a simple truth again like that cinema machine. If you want a camera for a game like Gears of War, where it shakes and or looks really awesome or has from the calls cut scenes Sina machine, it is extremely impressive and also extremely free, which is sweet. We could install that and if we wanted to. But for what we're doing, I don't actually think we need this much like grunt. This is like putting a V eight engine on a SE tricycle. You don't really need it because all we're doing is moving the camera in one direction. It's not going to be doing anything else, and it's actually really simple to do that. So we're gonna do things the old fashioned way because I think it will also show some really cool. Some of the really basic coding techniques that may help you understand things a little bit better. So we're gonna go over to US scripts, photo gonna right click. We're gonna create a new C shop script and we're going to call this camera following. Gonna open up this. So there's a few things we need. The first thing we need is we need to tell the script what we're trying to Fuller. So we're actually trying to follow the player. And how do we know where the player is? What We know where the player is from. The players transform position. So right now it's at 00 negative. 41 45.1. So we need to get that information. So we need a variable that can help us find information so we can just write public game object. So we're creating a game object variable, and we're gonna call its playoff. We don't need to start method so we can just get rid of this. I don't even need this Lana card here. Sister comment. Make a code extra lean, and we're going to change update to late update, which I find works a little bit better for things like cameras. It's basically happens after update is cold. Late update gets cold, so we just going to run another big line, big, long line of code. But hopefully this one isn't as confusing. It sounds very similar to the other line of code we wrote in the play off script here, but it's just a little bit different because we're not actually clamping anything. So all we're doing is we're saying, Hey, this game object. Sorry just yet. Well, this camera just needs to move in a certain direction. And so we want to smoothly move from its position is now to the players position, minus a certain amount of like the distance between the camera and the player so we could rhyme game objects dot transform don't position. So this is talking about the main cameras transformed a position which right now is this. This is the vector three and we're saying game transformed a position. Remove that. The common that was a mistake equals the victor three dot look. Okay, once again, looping is just smooth motion from one position or another. So we need a vector three a vector three b end. How long it's gonna get there. So our first, um, Vector three position is just where we are now. Game object transformed opposition, and the next place we want to be is we could just write player position. But the problem with that is, we'll show you. Actually, that's front playoff. Don't transform dot position time, adult time, times 100 just to get the ball rolling. Cool. So if we press play and we go to our main camera and we drag a camera for a script over to the camera, it's going to actually ask us. Well, what the hell's the player? I don't know what this is. So then we need to actually dragged the player into that section. Camera four. So now the script knows where the what the player game object is. And it's saying, Hey, make my position, Lope it so smoothly. Move from my position to the players position and do it at time. But don't time Um, Times 10. How times 100. Sorry. So let's see what happens. Press play. Oh, that's interesting. What's going on here? Okay, if we pause it and we zoom in, you'll see that a player is here or fun and our camera is actually right in the middle off the, um, player because we've just looked to the exact middle off the sphere. So things aren't working out exactly how we wanted to them. So when we actually need to do is we need to create a bit of a buffer zone between the player and the camera. So how do we do that? Let's get back over to our script and we're going to delete. Um, all this up to the vector three outlook open parentheses and we gonna say game object, Don't transform the position. This is where we wanna live from and we want to look to a new Vector three and the new Vector three will equal zero on the X axis. The wax will be game of it transformed opposition dot Why so Basically, don't worry about changing anything for our height, for the camera height. Don't worry about changing the camera hard. Just keep it what it is. And the last one is player. I thought game object. Don't transform dark position dot z and he is that he's a tricky bit monness 10. That's a pretty good distance run. Well, I think So, um, so basically what that means is, let's and sorry, we'll just finish this on a cut, actually, and then put a comma there and right time that adults time, times 100. It just seemed like a good number before Just just just is there So it speeds it up. End with end with Prince Sees close with semi Kahlan One line of code. Let's see how it goes. So if we press play cool. So our cameras and you might not even look Yeah, there we go. You can see our camera is actually moving. Then we can move left or right, and it is gonna fall off the edge. But if we press play again, you'll see that the we could move left and right on the screen. And things seem to work in that pretty well. So right now, if we get the player and we put the playback at zero and we put the camera back at, um well, I can state that heart and we put that back at zero. They're both on top of each other. But if I was to drag this back to negative 10 that would That would mean that That's exactly we've oppressed playing and should just start rolling on from exactly where we are , because in our script, that's actually what we've said. We've said, Make that gave birth to make her position sorry lip from our position. No, just zoom out a little bit. Make opposition look to a new vector. Three. The exposition. Don't worry about it. Just leave it. Zero The white position. Don't worry about it. Leave it at the default of whatever the camera's position is and as a position. Leave it at the players position but minus 10. So if I made this 15 it obviously go back further if I made it five. Get back further and do that at a rate of time that the time Times 100. Awesome. So now we have a working game, Um, in the fact that are working movement system in that in that outplay can move left and right and continue on and you won't go off. The screen obviously has fallen down now, and the camera will follow him or her. So in the next video, we'll do a little bit of a test 12. Camera Test: so I hope everyone's following along with at least 10% of what we're talking about. So for this test, I'm going to challenge you guys. There's some stuff of learned in previous episodes. I want you to open the camera follows script back up, and I want you to get the distance between the player end the camera, and I want you to store that in a variable here, obviously a public variable, so that you can change it at runtime on the script here. So for that, you'll need to create your own variable. Um, assigned the variable in this line of code here and then be able to adjust it within the inspector. Spend no more than 10 minutes trying to complete this task. If you struggled to implement your own code, that's totally fine. Just take the extra code that you did right and delete it so you could looks exactly like this again. And then we can continue on with our lesson. Otherwise, congratulations on learning to be a master programmer 13. Clean Level: okay, Before we start talking about pre fabs, I want to just adjust the level a little bit and make it look a little bit more like the finish park that we're going to be dealing with because dealing with pre fabs is Ali, as I will explain later. It works a lot better when you've actually got a good scale of have a level is meant to look. So right now we have a ground and we have the directional lot main camera in a player. But this ground isn't actually how Why would we want things to be So, um, first thing I'm gonna do actually is I'm going to open up the project files here, and I'm going to copy all of these. Just don't shouldn't drag them into the assets. And I'm gonna click on the assets photo. I'm going to delete the projects photo and then you'll see that we have all of our folders just all neatly stacked here. That I'm gonna want to do is I want to get the ground and I actually want to make the ground about seven wide and about, say, 1000 long, because that's about how big we want the actual level. That's about how big we want it to be just for testing purposes. Um, and the other thing that we want to do is we're gonna create the water. So click, copy, paste, copy the ground, whom to call it water. And the only difference is I'm going to make this 1000 wide, and I'm going to choose a new material which will be water. And you see, we have some weed overlapping he And if we press play, you'll see some like some flickering and start that. The reason that is because both of these in the exact same position. So we just want to get the water and we just want to drop it down by 0.1. Awesome. So now we're like, scooting along, and we could have left and right, and we fit pretty well on the green area because of that clamp code that we wrote in a few episodes back and say, If we were to drag like, say, let's get a cube on and just bring that opulent and white so low. Keegan's bring there and we press maximums in place so we get the full impact you can see that. In fact, although it is a bit slow, maybe we do need to bring it back up to 1000. We can go up to the quote there, the, ah, Cuba and run into it. So there is a little bit of movements that's good. So now that we have a product looking like this, it's time to jump into pre fabs and I'll explain exactly what they do and how they work. And then we can get to creating our first enemies or say obstacles, see that? 14. Prefabs: so back in unity, we can see that we can like in Stan. She ate things like weaken, create things like cubes or spheres or things like that. But what if we want to create, like, say, a enemy that just pops into existence or something like that? Well, we actually need, you know, an enemy's got in animations and scripts attached to it and all these different things, and we can actually combine all those things together into what we call a prefab s o. What a prefab is basically a combination of all the elements that you know an object needs , and then you can. Instead she ate or create or spawn that thing into the world. So to give an example, let's just let this Q because we don't need it. Let's create a new photo Cold Free Febreze on. This is just for organizations say once again, open up the pre Febreze folder. Actually, no, let's let's go back. And it's not the models photo, and we have this model Hickel triangle. So if we just drag this triangle into the hierarchy over here, it will pop up ran dislocation. So what we can do is we can just drag it forward a little bit. We can change its Y position to zero. We can change this to negative 90 cause that's what I think it's trying to do. Um, and in fact, let's removed. Let's get the triangle. It's spring it back to him to the play level. That's about the size we want. And let's press two. Awesome. So I think that's actually good. Good size and location for the prefab. Um, so right now the prefab has on it a mash renderers, Um, and it's got a certain material. Um, and what we want to do is we want to go over to materials and we want to create a new material full. The and we're creating new material for the triangle, so create material for angle, and we can change the color. I am just going to use like, a dark grey because I think that looks because I think that looks I'm going to use a dark grey cause I think that looks best. And then if we go over to triangle, weaken, then obviously drag the material so it looks like that I think it looks pretty good. So what we want to do is we want Teoh. Just turn off the player for a second and we want to get the triangle. And we want to put the triangle zero 00 Rotation should be negative. 90. So it rotates like that. Otherwise, in that we could have it like this is something. But we're not gonna do that. Keep it in igniting. I'm scaling 100. Elise. Things look good. Diesel. The defaults. Um And then what gonna do is we're going to go over to the pre fabs fora and we're gonna just drag in triangle. Cool. So this is a prefab of our triangle. Now, what we can do, you can see has turned blue here, which means that anything that we do to this, you can click, apply, and a little plot this prefab or anything you do. This prefab will affect this. So, for example, if we decide to, um, change the texture to the water texture, it actually is going to change each eye instance off the prefab. So that's like, let's try a few more in here. Hamlets. Cool. So we got a bunch of different triangles. Now we go, we can go to the pre for the triangle prefab instead of instead of changing the texture, the color on all these different triangles, we can actually just change it on the prefab. We can change it to whatever color we lack. So that is what a prefab does. And that is what a prefab is. In the next episode will look at how to use pre fabs to create randomness. 15. 014 Grouping Prefabs: I guess I've deleted all the triangles out of the scene, and I'm just going to drag the triangle back into the scene so you'll see here that the triangles at 0.27 and zero so you can see um, I think it was before it was a little bit low, so I just bring up to 0.27 Might be different for your, um, your project. But just make sure it's like sitting flush with the ground just so it looks nice. And so we have the triangle right here and let's just bring it forward a little bit. And let's turn your playback on and let's see what happens when the player runs into it. Okay, the play goes straight through, has no good. So what we want to do is we need. So let's look a triangle and see what's on our trial. So we got al mesh filter. We got a mesh render on which renders it to the screen, and we've basically that's basically it. We don't have anything else. So what we want to do is we want to add a mesh Collado sequence typing mesh Kalata. You could use. Say, for example, a square Klawitter if you want things to be a little bit simpler, but this should be pretty good. Um, certainly a triangle. So then, if we press play now, you'll see what will happen. Cool. Our player goes over the top. That's really awesome. So because our world is always flat, we never, ever want our player to be on a move up or down. So I could actually go over to our player, go down too rigid body. We can open up constraints and we can actually freeze, um, position on the Y access. Suppose play again and you'll see it's just rotating in spot there because it can't move up and over. And that's exactly what we want. Fantastic. So then we have a triangle. How do we use them to create randomness? How do we use them to create the game that you guys sort of the beginning The game that finished the finished project? Well, we need to actually create a few different pre fabs a few different instances, so we have our generic triangle here that just ysl great, but we need to actually create like sets of triangles like a grouping of triangles and then use them as pre fabs. So how we gonna do that is let's turn off our player again and let's turn our triangle with Bring a triangle back to zero in the Z axis, so it's right in the middle. Let's just bring it here. Just like to position the camera a bit better so we can see what was going on and let's get out triangle and let's copy it and paste it. And we're going to put this one at position two. I'm gonna put this one at position. Negative, too. So then we got a gap through the middle. Awesome. So then we also want to create an empty and we want to make make sure you zero this empty and 000 and we can call this triangles under school A. And we can grab these two triangles which, if they're at the perfect position, um, drivers to triangles into triangles, a triangle day should be it 000 for everything, and then we should have I'm negative, too, in two, and then we'll be able to actually drag this. You know, we can drag us forward and back and can do Think whatever you want with it. You can move off the side, announced group together. Well, that's awesome. But we also. But what else do we need? So we need Okay, so we got the two colliders here, so that's all great. And we want to actually tagged these triangles with a special tax. So when we run into them, we can actually, you know, create a game over screen. So if we click on one of the triangles and we go up human, click on the tag and we click open tag that would click the tag button here and click ad tag. We can have a list of tags here we can click the add button and we can call it triangle with a lower case T triangle, and then we can go over to our two triangles and weaken, set their tag to triangle. We could go to a prefab weaken, sit that's that tag to triangle. And so now, whenever we run into it, we can actually access this through code, and we can ask the question. Hey, have you run into something with the tag triangle and then we can use that to from former game logic. So the only other thing we need to do is we need to create a center section. So the center section will be where we get the score and we just want to make sure so whenever the player passes through the center section, he gets one or she or he gets one point. So what we do is we can create a new three D object can new? Um, uh, we're actually listen to creating you empty. Let's grab this empty 000 Make shorts absolute center. We can call this gap. We can drag this gap onto triangles a once again, triangles, SUVs 00 and all these negative two on the X two on the X and 000 So it's right in the middle. Then I'm going to do is at a box Kalata and you can see here. I'm not sure if you can see because it's also green, but you can see here we've got a we have a box Kalata. Now all we need to do is click Is is trigger, and then let's see what happens. So if the player runs into the section that's fine, that it still can go through the center. The reason it could go through the center is because we've turned is trigger on. If we didn't turn his trigger on, the Collado would act like a Kalata bam. We ran into the closet, but because we've turned history grown, we can pass right through it. So would use another separate line of card to say, Are we in the trigger zone gap? And if we are, give it a point. And so that's how well before my game logic and the only other thing we want to do is you want to add a tag to this gap section so we can go over to the tag section ad tag and out of the tag and weaken Cole Cole it school ump Cool. And then make sure you a sonnet to score up. And then all we need to do is we need to make sure this is that. Zero is we can just drag this whole parent object here into the prefab section, and then we have our own. We can get rid of it now and then. Whenever we drag him in, we have our own prefab. So the area that will give us a score and we can run into these two enemies. We don't have any of the logic coded in yet. But this is how how will be going forward with the pre fabs. So we've created one prefab, but we actually to create two more pre fabs, and I'm pretty sure you guys will guess how we're going to do it. Let's just do it really quickly. Copy Paste and we can paste it again. Let's open up. I'm triangle. So we got one of negative two. Let's add this. Make make this 10 Let's turn off this one. Sorry, and turn off this one just so it looks so you can see what's going on and we need to make a gap at to So then let's turn. If I player as well, so then we have the situation where we have the 22 triangles on the left hand side and we have the Cube. Um, here. So that's fantastic. Being call this triangles be drag this in done. Now we can get rid of this and get rid of this, and we can do the same thing here turn it back on. We can go triangles at to triangle at zero, and we can make the gap naked, too. And then we can call it triangles. See? Awesome. So then, if we delete this, you'll be able to see if we drag this in and then we drag this in enemy drag this in, make sure these ah, turn the playback on. We impressed play and the player can move through these sections. We need to make sure that all of the gaps I was just give gap. His trigger gap is trigger and camp. It is trigger press play, man. We can pass through and everything works fun. Cool. So we got a basic scenario here, so let's just, um, just drag this opposite. We go a, um BC Let's put this one at, say, was a 20 on the Z. Let's put be at 40 and let's put C at 60. It's a free press play. Let's see what looks like cool. So we should get a score there. We get a score there and we get a school there unless we bump into them. So in the next episode will be coding the functionality of these gaps in these triangles. What happens when you run into a gap? What? We want the score to go up. So in the next episode will be coating the logical the functionality behind the the pre fabs that we just created. See that? 16. Score Logic: to create a score or we're going to do is go over to the assets, go over to his scripts, right click, create a new script, cold score, and we can drag this straight on to out player. So now we see the Scriptures attached the player, weaken DoubleClick toe open, and we can create a new public int school. Remember, images are whole numbers, and because as score is going to be in whole numbers, we'll just use an interview. We don't need a start, and we go instead of update and just write debug dot log. The score is space. Make sure go outside speech quotes plus and they're just passing at school. Happy days. So all we need to do now is call the on trigger enter method, which is an inbuilt unity method that just calls when we went when we run into a trigger zone so we can run a void on trigger, enter possibly eight colada when coolies of the Kalata Aava and an open, um, curly brackets closely brackets press space. And then we've got a Kalata working, so we can actually just write a debug dot log here. Colada is working and Let's just see how that works. Let's go over to you, Nelly, and let's press play awesome. So if we go over to a console, we see the score is zero, which got called 270 times because we have the update method calling at every single frame and our scores at zero and Kalata is working. So what happened there is when we went through the gap of this first object here, it triggered the on collision Enter. So Ikle entered the Kalata of a gap and because it's trigger So it's OK entre granted, we entered the Kalata. Okay, let's call Let's call this function. But we want to actually know if it's the correct Kalata because we just don't want it to be calling all the time so we can actually check for attacks so we can say if of ah, I thought game of objects the tag equals. So when you put two equal signs, you're asking the question doesn't equal on one equal sign of your assigning something. It equals this, for example. So we're saying if other Takemoto tad equals school, um, then we want to do something. So if you remember, we have a now triangle out gaps. A tagged with the tag score up. Make sure you spell it exactly the same with the Capitals. Exactly the same, like he was up against locates. That's why I said to make it lower case. And then we can say something as simple as, um, school plus plus, which means the school will go up awesome. So let's check this out. There's press plane. Let's look at the console. Score zero scores. One scores, two scores three. Awesome. So now we have the logic behind our school system. Whenever our player bumps into a gap, it will added one to the score and score just keeps adding up fantastic. 17. Display Score: Okay, So the next step is to get out of school, to actually display on the screen so we can go over to window and we can go to package manager and your your version of unity should have text mesh pro already installed. Ah, text must probe was another asset that was purchased by Unilever just because of how awesome it was but should already be in store. But if it's not, click under all scroll down fund text message pro and install in deal project. Cool. So what we want to do is we want to right click. We want to create in the hierarchy will create you. Why text brush pro text. It's going to ask us to import him. Peep essentials Just click. Yes, it's going to import and we don't need the extras. Quit out of that And so we have our text. Most pro text, which is just up here. So nurses also created a canvas and an event system. The we won't be talking, there's too much, but we're going to go straight to the text must pro text and we want to change the text to say thirty's five, and we can change its position up to here and we can change the font size is too, just to adjust a little bit more. If you look here, we can actually drag these out. So everything fits. Well, awesome. And just feel around the settings until you get something that you like. Okay, so that's all good and fine. But if we want to use the fund that we've actually create, we actually imported That's part of the assets. Or if you want to use your own fun, um, what we need to do is we need to actually create. They flaunt assets so text mesh pro doesn't actually use like text as we would imagine it. And actually creating this super high res version of the text. And does this like this tricky course off? So basically, our text looks perfectly crisp and smooth. So what we need to do is we need to get a window, and we want to go text mass pro, um font asset creator. We want to select a fund blocks which should be there. Water sizing, patting everything is fine. Generate front at less. So it's going to generate the phone at less cool and then we can click save savers and we can put this in their phone. And just as that save now we can quit out of this. Go back to a text mesh pro and we can now select that from up here, which I think looks a little bit better most suited to our game. So you can mess around with a few of the settings here. We can obviously change the color weaken. Do you know some cool stuff you can mess around to see, um, to make it look how you like to look and ah, and then just some things and certain stylings to make it look how you want it to look. And so then when we press play, obviously nothing's happened because we haven't actually connected our script to the school here. So we'll do that right now really quickly. So if you go over to our player, we open up our school script going to do is at a new name space. So this will tell you early that we're using text much pro. So we say using T I m pro just like that. And then we can create a new public text pro u G u I I'm gonna call this school. You are awesome. And then in sort of update, we can actually get rid of the debug dot log now and weaken Just right. School you want dot text equals score. So we're actually saying the score you are texts of the score of this object equals this score. But we can actually pass a number because a number isn't like text. It isn't a string. So we need to use a function called thought to strength done. And that should work absolutely fine. So if we go back over to you, Nelly, we go to a player will notice that on the score script a new score, you element appears we can drag in our text mesh pro text. We could also rename this to make it easier. Just call it score And a player has now the school and now women press play. It should update 20 and then we go through one to three. Awesome. So it's just a simple is that so? We haven't actually talked about what happens when we bump into one of the triangles and we're gonna leave that for a later episode because it'll work a lot easier if we do it when we're dealing with things like menus and the game over method so we can do it all in one place. But right now we have a working score, and that's all that matters, see in the next episode. 18. Procedural Level Generation Explained: So this is where the fun stuff really starts to begin. We're gonna start talking about procedural level generation. What is procedure level generation? Procedural level generation is basically random ization, but within certain rule sets so we can create a level. And we want that level to be created, but not a complete randomness. We want to set the certain rules that that level is created in. So, for example, no man's sky builds planets under certain rule sets or Minecraft builds world's under certain rule sets or games like Splunk e build that builds their two D levels under certain rule sets. But how do they actually accomplish this? Well, to understand procedure level generation, let's look at a very, very simple example. Tetris in Tetris. Everyone understands how to play Tetris. Our hope are you gonna line up of the lines horizontally, and then you get a point of whatever the thing goes down. But basically, the way the procedural level generation works in Tetris is your given random shapes, and you've got to get them to fit together. It isn't programmed what shapes will come out at what times is actually chosen at random, but the shapes aren't random. The shapes are actually selected from a group of different shapes that the Creator is decided. Okay, we're going to have this pointy shape. We're gonna have this t t shape. We're gonna have this straight full line shape. And we didn't have a bunch different shapes. And we're going to choose out of these different shapes and just going procedure. We generate them at random as the game is actually playing. So what this means is that Created can play his own game and be surprised with the results . So this is actually really fun way to make games and can also be very frustrating because you can't predict what is going to happen. Not perfectly anyway. But how does this relate to our game? Well, again has a level that goes on forever and ever and ever will deal with this in a later episode. But we also have triangles that need to spawn not at random, but kind of a random that it spawned at preset locations based on certain rules that we give the program. But they need to feel random. Ben. It would feel like they're chosen at random that the computer is making the choice in which it actually is making that choice. So when outplayed goes along, he may rat running into a prefab with two triangles on the left, and then he may run toe a prefect with a gap in the middle. And then you might run into a prefab with another gap in the middle, and this is totally random, but it's within certain rule sets. The reason why procedural level generation could be so fun to play with is because you can adjust the smallest variables or the smallest things. Why the smallest component? And it can totally give you totally crazy, different results and different game feel, and your game will feel different. And if you're confident, often programming, you could take this in the next episode and add to it, and your game will feel completely different to everybody else's. That's what's awesome about procedure level generation. So now that you understand a little bit about what procedurally level generation is, let's implement that into our game 19. Object Spawning: So let's start a new script. Right click. Create new Say Shop script. I'm going to call this object Spooner, open up in visual studio Cool and we want to create a couple of variables straight off the bat. First of all, we need to access out playoff. Sir, we can create a public game object player. We've done this before. We also need to create a public game objects and he's re gets crazy. We're going to build a array off game objects. So not just one game object. We want to create basically an array or you can imagine, like a list or a grouping. But the court a raise. And to do that you just add it open and close square brackets after the game objects. And we want to call this triangle pre fab with s we do s of the end so that we know that it's an array. This is full. Our own sake. Cool. So the only other variable we need is that the location that the objects will be spawned out. We install this in effect three on because we don't need to access this Vector three inside the Inspector, we can just leave. It is private, so we can say private victor three spoon or obstacle position. Cool. I don't think we need start so we can get rid of Start. Get out of that first thing we want to do. We want to create a throwaway float called Float Distance to Risin. We're gonna call it and the horizon. It's just gonna be an arbitrary amount of space between our player and how far we want the objects to spawn. So we're just imagining and arising at this stage. And when our game is actually curved, it actually will be over the horizon. And that's going to eagle a vector three don't distance and the distance we want to get is between the player. I thought Game object, transform dot position end this born object position. Awesome. So now we have a variable. That is that that is just a float between a player end this sport location. So what was the purpose of this variable? Well, we want to create a fixed distance between where the object spawn. We don't want them to spawn with gaps that are too big between the triangles and we don't want to between the triangle prefects. And we don't want to spoil them too close together either. We want to be pretty consistent. So what this could do is because we know this value. We know the value between the player between the player and the sport of your position is we can say, Well, if it gets to a certain length or gets under a certain length, then weaken spawn a new triangle. So then we need to do is run a if statement. If distance to horizon is less than, say, 1 20 well, then what do we want to do? We want to spawn triangle. Now this is going to and we're going to do with capital. This is going to throw an era because we don't really have this were trying to call this method, but we actually haven't created this method yet, So let's just create the method down here. So we go avoid spoon triangle, and you see now that it's fixed the error, But I suppose we won't actually say spawn trying golds. Just so we understand that we're actually install were actually spawning be triangles prefer This is just for our sake. So we understand that code a little bit better. And then all we want to do is we want to change the sport Obstacle position on equal to a new vector. Three. Do we want to change on the X axis? Know So leave that zero. We don't change on the y axis, so leave that at zero as well. And then we want to change it on the easy access by a spawn object position so that the Z value of sports one orbital position dot C plus a distance of same 30. So this will be the amount the distance between the different triangles. So you can adjust this number 20 or 50 or whatever you you find fits best. Awesome. So that's literally it. We've created the locations of where our triangles going to spawn, but now we just need to spawn them. So the next line of code is where the magic happens. It's where we actually spawn the triangles. It's called in Stan. She ate inside of unity and you don't have an inbuilt method. Helps us do. This is really, really simple. Going to do is write in stand she ate. Then we need to open parentheses we need to tell it what we want to. Actually. Instead, she ate. We want to substantiate one of the objects off the triangle prefab. So right now, why don't we just choose the very first triangle prefab? So it's a triangle triangle pre fabs open square bracket, open parentheses and would strike zero. So the object of sub zero index off the array. And where do we want to instance yet what we wanna unstained unit at Spawn Obstacle position. And how do we want this object to be rotated women's place in this in the scene? Well, if we wanted to be exactly like we have settled in the pre fabs, we just need to riot quantonium, which is very hard word to spell clintonian dot identity, close parentheses in with the semi colon and save that quantonium door identity is whatever the game or default rotation is. So we choose what a game object we want to spawn Orenstein. She ate. We set the location, which we set up here, let me say, just born at the default rotation. Awesome. Let's go back over the union set everything up. Let's create a new the empty game object we're gonna call this scene manager and I like to put a little underscored the stop there, and I like to drag it to the top. And I also like to zero everything out just to keep things neat. And we want to end the script of Exporter Awesome. It's asking for our playoff so we can just drag out player in. It's asking for our triangle. So if we open up this tag it saying, Well, we actually have zero objects so far, so we can just change up to three and then we can go over to our pre fabs weaken draggin triangle's a dragon. Triangles be and we could drag in triangles. See? Then we can take these three triangles and we can turn them off. You impress play. Today we have procedural level generation that will just keep on going forever. But there's a problem as you can see game objects, a sporting the very first game of bricked over and over and over again. We'll deal with this problem in the next episode 20. Randomizing Object Spawning: Okay, so this is a pretty easy problem to solve. So we want to open up our seen manager scripts, Sorry, objects, born a script and you notice he that were in Stan Shih ating a triangle prefab at the index off zero. So if we just change this to one, let's save that. Let's go back to unity press play. All of a sudden, it's morning element Be well. We needed an element of randomness in that game. A game for a little bit boring. If. Is this this the whole time and you can see that there instead, initiating 120 clicks away from the, uh, player. So what we want to do is we need to actually create. We need to actually randomize this number so we could create a very will expose. Appear to say, like you create a random number that's the length of a throwaway variable like, you know, here. Or we could create a you know, random random number up here and create random function. It's actually pretty easy. Just write random credit random range inside off the actual. Instead, she ate method here, so it's actually asking for what location the index we need. And instead of writing one or zero or three or let's say let's actually let's see what happens, we could do five. We'll go over to get unnameable press play and it will just not do anything the games actually playing. I'm not sure if you can see game playing. You see every console array index is out of range, so it's basically saying like, Hey, we don't have five game objects here. We only have three. So we could actually do is we can go instead of writing 012 or three or five or whatever, we can actually create a the random method or function inside of here. So how do we do that? It's pretty easy. So instead of writing 01 or two or three or whatever, we can actually just write random don't range and then we can open another set of parentheses honorably. From zero to now. We could write three up here cause we know there's only three pre fabs. But we might. What happens if we, like, lose one of the pre fabs or if we had more in the future, a better way to do it and better better coding practices. It's just right triangles, pre fabs dot length. So whatever the length is, that's what it will be said to and then close parentheses again. So if you look at this shit one open parentheses, one of propensities, close parentheses, close parentheses and then obviously close parentheses here and you can see the highlights . Cool. So if your car looks like this, everything should be fine. So now it's choosing a random number between zero and length, the length of ham Ernie triangles. We have awesome happy days. So let's see what that looks like in the rial game. Press play. Awesome. So now we have procedure. Actual procedural generation. A game is a bit slow and boring. It may be simple, but it is procedural level generation. So every time we play the game, it will be different to press play. You know, it's got to in the middle there, press play again. Awesome breath play again. Awesome. So you could create mawr pre fabs if you wanted and had more to this at more variety. But for the sake of the tutorial, I'm just gonna leave that three, but feel free that had your own pre fabs and add more of them and do everything that we've done already. And your game will be different and feel different. And also you can adjust the numbers inside. Here, you adjust this number or if you wanted to the Harazin re further way you can adjust this number. But yeah, awesome. So right now if we press play, we've actually got a working game. A game is pretty boring and the game is pretty basic. But this is at product table, prototype level of gameplay. We can play the game. It's we already know it's too slow, but we can see that the game is actually working in. We can get a feel for what the game is actually like. So we've actually finished the game portion off Editorial. Siri's and that's really awesome. So the next portion off of this Siri's is the Polish. This is where we turn this game from looking like this into the finished and final product . We iron out some code, we add some saving. We added the world curvature Shader script and we do some really awesome things to take our game to the next level. We polish it up ready for release. So join us in the next section while we take this game to the very next level. 21. Adding World Shader: Okay, so let's stop publishing this game. So right now when we press play, you'll notice that the game is really, really, really fast. That was a joke. It's really slow and boring. So first thing we want to do probably is speed up a player. I think it's that 500. Let's try 1500 press play. Oh yeah, that fears a little bit more, a little bit better. I'm actually feeling it is some sort of, ah challenge, cool. And because we like that, let's open up the script and change the default to 1500 just so it doesn't stop up in us that Iran, if we just something cool. So the next we want to do is right now, we've got a pretty boring plain ah, ground and we want to kind of change that. So to do that, let's turn off the ground and let's turn off her water just for the time being. And let's drag in. Al, Um, it's gotta models and was dragging out ground. Awesome. Okay, so right now it's Ah, it's his looper highs. Let's just for juice that by negative 0.5 well, that looks perfect. And let's call this just grand cool. And let's just see what that looks like. We'll press play. Ah, Yep. Things are looking tasty so you can see the little edges. He make it look a little bit like you can tell your players moving a little bit better. And now we want to implement our shader. So as Shader is, what's going to make the world look walk. So what are shaded does it doesn't actually affect anything in the like doesn't affect real world coordinates per se it mawr It more tells the compiler how things are going to appear on the screen. We aren't going to go into how shade is a coded in this tutorial because they're a lot more complex and not really a thing that beginners can really touch on. Um, but it is something that you really kicks up the look of your game to a whole new level. So luckily, we've got a shade A script already here called Curved World. Eso if we just, um, first of all, go over to our model, click on our ground. Open that up. You'll see we have three different textures that are already imported here. So let's click on that ground first, and we're going to say extract materials. That's gonna ask us where to extract these materials. We want to choose the material photo. It's like that photo Awesome. So it's extracted those materials discovered to our materials and we'll see We've got grass , mat, sand Matt and water Matt. So we probably don't need these other ones grassed grass in water. I don't delete them there. The Opens. So we got water Mount Sandbank in grass, man. And right now, they using this shade of standard. If we change this, we could change it to like that, which looks horrible. We're gonna leave it a standard. Ah, and we're going Teoh, Um, what we're gonna do is gonna go out the water. We're gonna grow the grass material, are going up the same material. I'm gonna change them all. Two curved shadow. Awesome. So if we press play now, nothing happens. And the reason nothing happens because we need to actually, um, pass in some variables to the shader and say, Well, how how much we want this shaded to curb the actual world. So to do that, let's go over to our scripts. Photo we're gonna cut a new script. Cold AMP Inish Feel Lies. The service trip will handle things like, um, like frame rates and just like the little settings that we may have on. And so it's just common practice to call the app initialize. And let's just drag that straight away on to the scene. Manager seen Manager has that script, and let's open up that script. So normally inside scripts Void Start is the 1st 1st method that is called straight away when the script loads but is actually a method that is called right before start. So if you want something done before start, you can use avoid awake, so we'll be using that to avoid awake. So if you want something to happen before start, this is where you'd put it. Make sure it's capitalizing. Everything looks exactly like that, and then we just need to write, shada Dot said. Global Float Open parentheses, open speech marks underscored curvature comma and we considered it too. Point zero f awesome. And the next Lonmin right is Shada. Don't that set global float under sort shrinking 0.1 F. So these air settings that I've tested out that work the best, but feel free to adjust these numbers to adjust the look and the curvature of your game. You can also create a variables up here that you could that and, you know, like you could have curvature and trimming. You create these variables here and make them public. And then you could change that. The variables for these numbers here and then, as with them before you can then adjust them inside of the editor and you'd see things adjust in real time when you're playing the game, if you want to test out things. But I found these two numbers to work pretty good. So if we press play now and you'll notice straight away, we'll get some crazy looking graphics ready. Press play. Okay, so first of all the world curves, which is what we want. Ah, and these don't curve. Thank a so first things first. Let's grab that camera and let's just drop the rotation down to about there. Don't worry. We'll fix up this ugliness up here in a second, so this is drop it to say, 24 whatever looks good on your game. And right now, if I press play I want to show you something. That's pretty cool. So this is the edge off the material. Okay? And now want to point out something? Hang on a sec. This doesn't look right. The further we go back, the further this rolls off. And these the edge here is actually at the level zero while players at zero. And this is on the grounds that zero. So what's actually going on here? Well, what's going on is this is not actually moving the verses, not actually moving the model and changing the models direction. It's just appearing that way where the Shader is basically tricking the graphics to render it a certain way. If that makes sense, if that's an easy ways to understand, it's it's adjusting how it appears on screen, even know it's not. Actually, we're not actually going over a hump that makes us much going around the world. So what we can do. But so what's happening here is there's a little bit of a problem, though, because right now, these hovering up in the air and that doesn't really make sense. Well, actually, no, it does actually make sense, and the reason it makes sense is if we go into our materials, will notice how triangle has the standard shader and the standard shared isn't being affected by anything else. So if we just change this shader to curve world, all of a sudden they plop right where they need to bay. So if we un could play and you'll see that things just the way they're supposed to be now our player is still at zero, and all these items are still at the height of zero. But it appears as if they're not. That's the awesome power of shade er's. So the last thing we want to do to make a game, um, look a little bit better is we want to fix this ugly background. So what we can do in your materials is we can create a new material here, creating you material. And when you call this two de scribed box and we're going to set this the, um, skybox to a skybox to a mobile. Sorry, my bowel Scott Books and we're gonna set out Z texture to Al Texas Sky Box. We're going to go to a main camera and we're going to add a skybox and then we're going to just drag in our customs skybox and you'll see our background is fixed up. Well, it looks better anyway, but it's still not perfect. We need to adjust the office it a little bit, So if we just drag this up and down, you can just get something that you think looks good. Four, maybe 56 Eggs fought that. That looks good to me. 0.5 So then, if we play the game, we have a curved world and things look pretty cool. Mont need to adjust the camera a little bit. Just give it a little bit more room. So maybe 23 Press play cool so you can address things to your liking and you can muck around with some of the settings. Um, you can even dragged the camera up and I'll see you in the next episode, where we will focus on when I believe that it's five C in the next episode where we will focus on making the world go, Ah, go forward infinitely so I'll see there 22. Infinite Level Generation: Okay, So you may be thinking the next party is actually pretty hard, but actually, it's really, really easy because of the way of with set up a game, remember, Everything is on a flat plane. Everything is that the, um, coordinate off 10 in the UAE access. And a player is actually, um is freezing his position in the white position cause it never needs to move up or down, although it appears is moving around and unearth around a planet. So what we need to do? Ah, we have our ground here, which has our ground in that water. We actually create a new object called I'm gonna call this planet. Let's set its coordinates to 000 and then listens. Great. Grab the ground. Ah, model here and put it under the planet. And then all we need to do is we need to find the end off the planet. So right down here and we need to create a highlight here, and we want to create a new three, the new empty. And when you call this trigger zone and we're going to add a box Kalata to this and we're gonna make it is trigger and we're going to. So right now our planet's accordance to be at 000 r ground should be observed. Negative 0.5 and zero and triggers own needs to be basically at the end of this planet area here. So if we just drag this forward, we can see that it's at about 100. So if we just spin this round, we'll see that yet it's pretty much 100. So if we just make this 100 should be perfectly on the edge there. And then we can make this scale. Um, se, you know, five. Um, let's make sure it's wide enough. Actually, make that 10 and let's make it five on their waxes as well. Cool. So that definitely covers us. So when our player goes through this trigger, ah, we need to do something. And what we need to do is we need to, um, create a script added to this method, and then we need to add some instructions in that method. So let's just do that. So let's go over to a script photo. It's right click create, say shop script, and we'll call this level. Gen. Was dragged this onto the trigger zone so at triggers and should have the level generator script the is triggered box Claddagh. And let's open up level, Jen. Okay, so inside about level generator script, we can actually just delete the void. Start and avoid update We don't actually need them. Okay, so the first thing we need is a on trigger in tow. Ah, method. So we actually go over to our score script and just copy this one here because we've already written it out. Dump it in him. Avoid on trigger Renta. Awesome Collider. Abbott. Cool. We don't need this. And we don't need a the if statement in here either because we only have one thing that's going to be clotting, and then we're going to need to call a method. But the top of method that we're going to be calling is not actually a method button I a numerator. So it's the same as the method, but what it lets lets us do It's a core routine. And what that means is, what it lets us do is it lets us wait for a certain amount of time before we perform a certain action. Um don't get too caught up in the terminology here because we don't. We won't use them these too much. But just know that we need to first create a I in your brain, which is like a void, but it's not avoid. So we did it by creating I I numerological that transfer and inside an iron unity, it needs to return something. And so what we need to do is because we could write return now. Ah, you'll return now. But we're not going to do that. We want actually to wait for one second. So we're gonna say yields, return new, wait for seconds and then it's gonna ask us how many seconds? Let me just say one cool. So now it's going to, um, wait one second before performs the next line of code and all we need to do to call this transfer courage seen oi in America is to start a curtains. It start her routine. My spelling is atrocious, and then we can just open parentheses, open speech marks and right Trent transfer. So that's a little bit overwhelming. I understand that it's because it's different terminology and different ways of calling things. How we normally would, but this will work just fine. And so now we're gonna ride debug dot log, hit the trigger zone after one second, and let's close that out with Sammy Cahn. Copy this. Let's dump it in here just to make sure everything's working. Delete that and we could go back to unity and press play press play If we go over to a console hit the trigger zone, hit the trigger zone after one second. Awesome. So we know that this is working perfectly well so we can delete these to debug dot logs and the only other thing we need to do to get the to get the level moving forward, um continuously is we just need to wait for one second. And the reason we need to do that is just so we have enough time for the player to move through the trigger and for this part of the level to be behind the camera. So that's why we wait one second and then all we need to do is move the level forward by that certain amount. So it's actually quite easy. So we need to do is write game object, don't transform dot parent dot position equals new Victor three and a new vector Freedy. It just needs to be zero not changing the X access zero not changing the Y access and then game objects don't transform dot position the Z Plus we need to have a certain amount aiming to work out what that is. Um, let's just say 100 Fernando, but we need to actually work that at at a semicolon it in there. So the reason we use game object that transformed our parent dot position is because we actually need to get the position off the parent game object. So if we remember, our trigger zone is here, but we don't need to get We don't need to move just the trigger zone, for we need to move the parent. So we need to actually get the parent object, Which is this planet? A. So that's the reason we use transform. Don't parent dot position. Cool. So now we've got a planet here. Let's just copy this and paste it unless his drag this one forward right until we hit the right spot. So you can see here. We got 200 so we know the value that this needs to move forward because this planet is that zero. We know the value that this needs to move forward is by 200. So let's go back into a script and let's changes to 200. And let's name this planet under school be and let's name this planet under school A And let's just press play and see what happens. Okay, so we're going forward, and it appears that the level just continues forever. So what's actually happening here? So let's just have a quick look. We go to a scene manager, um, script, and we turn off object spawning. So we got nothing in our way and we press play. We can actually go to the player and you'll see that what's actually happening is as the player passes certain spots, it's deleting the world behind the player and sending it 200 clicks forward. That makes sense, but from the player's perspective, the play that's actually playing the game see how Shader is stuffing up, Have you there a little bit? That's okay. It just looks like the world is going on and on and on and on forever because it's it's It's lining up seamlessly. We know exactly where things lining up, and the world will just continue doing this forever or until the phone breaks or something like that to go back to the same managing. We turned back on objects, Porter. So, yeah, this is basically simple procedural level generation. But the only problem we have now is is now, if we pulls it, we have a bunch of different triangles here, and eventually that will add up in our memory. And things will get really messy and really slow and use a lot of data. So what we want to do in the next episode is work out how we're going to clean up this stuff that's behind the player, so see there. 23. Destroyer: Okay, So to clean up the triangles after they've been spawned or going to do is we can go to a scripts photo, create a new script. Let's call this script. Destroy? Yeah, cool. So what we would normally do is we would normally find the position we would normally create a public, very public variable for the game object position of that player on. Then we would just drag it in. But because our, um, autumns are being in Stan shaded from pre fabs these different pre fabs here, we can actually do that because would have to drag them in. And so we're actually going to approach this in a different way. We're going to say, Private game, object player and then inside of us. Stop method. We just wanna assign the player there, and we can do that easily by saying player equals game object. Don't find game object with tag. Make sure it's not game objects, but game object. Oh, parentheses, open speech, quotes and Capital P player. Awesome said that will find our player and let's go back over the unity. Let's go to our player and let's make sure the player is tagged with the tag player. That's definitely important. So now we play it. They know the game knows that the player is out playoff. If that makes sense, because we've tagged it and back over to the script and then all we need to do is we need to say, Well, hey, when the when something is behind the player by a certain amount, we just need to delete that thing so we can just run an if statement inside of update if came. Object dot transform The opposition dot z is less than player doctrines. Trance transform dot position z monness 15. So that gives us a little bit of room open. Ah, close Parentheses Open, um, killer braces and then all we want to do is say, destroy, destroyed, not destroyer. Destroy game object. Cool. So that will just destroy this game. Object. Whatever script this is attached to it. Where was one of a game reject this script is attached to? It will destroy that game. Object when the, um, this game object gets below 15 in the easy access of behind the players at 15 space is behind the player in the Z axis. I hope that makes sense. So all we need to do now is weaken. Grab our three pre fabs here and we can add to the script destroyer and we can press play and hopefully everything works out. Let's just have a look. So he looked. He ah left and things should be being bleated. And they are. Things are working great. So it's restricted out in the scene view unless is good a player. Things look a little bit wacky because of the further we move away. Obviously, the ah, a shadow works differently. But if we press play, what's this one adds delayed it. Cool. Awesome. So that seems to be working fun. So with a simple um script, we have just asked the question, Hey, are you 15 spaces behind the player? And if so, just destroy that game object and that's it. You just for any object that will be behind on the player. And because our objects are pretty simple and because we're not deleting them like not destroying them massively like a huge amounts were not destroying mass amounts of objects. This is actually a really fine called to work perfectly on my boat of ass is it's not going to be too much of a drama, and it's a really simple solution. Go 24. Audio: cool. So it's time to add some simple sound effects to a game. This is also very easy. So let's actually get rid of our ground because we don't need that anymore. And our water. The two things that we took off not these guys, but the two two objects. We turned off another earlier episode, and we can save. And then all we need to do is go to a player and we need to add a component to a player called audio source and then go inside of our audio and we can actually go back quick back , not player. And we can actually drag our theme song to our audio clip, Um, section and we compress play cool, so that's working just fine. Then we can open up our player script and we can create two new variables. Public order your clip and we're going to call this score up and another one public audio clip damage course, the minute another on trigger inter function. So if we go over to score, we can actually highlight this again and then get back to playoff and we can go underneath the update, dump it in there. We don't need this. And if other gamer tag equals score up, that's actually exactly what we need. So we can just write our audio code in there so we can say, Get a component. So once again, this is getting the audio, um source component What your source. Just like we did in earlier episodes. And we can say what you saw. Stop play one shot and we can say what quickly were in play. We want to play score up and just at 1.0 f volume. Cool. And let's just copy this copy and we want to change this from if other going to tear equals triangle. We want to play the damage sound effect. Let's go back over the unity. First of all, let's make sure our prefab let's make sure our triangles actually are tagged with triangle . Yep, they attacked with triangle and the gaps attack with score up. Okay, everything is go on flying so far, and then we can go over to a player and we can assign our score up and our damage variables and they'll just being SFX. So get back to player and good n so score up school plus one and damage as damage. Cool. Now this won't work how we think it's going to work just yet, because on our pre fabs how pre fabs have a mesh Kalata. And this is actually a mistake, because our gap will work fine and we can actually test. That causes the trigger. But these are not triggers, and in fact, they're probably. We probably don't need a measure Kaleida, because there's such simple shapes anyway, So to fix that problem, we just need to click on these. Click on all the triangles within these pre fabs. We can remove the mesh Kaleida, remove and add a box collider. Because it's such a simple shape, they should fit perfectly. And we can just test it by dragging it in. And you'll see here that the box collider is pretty much perfectly around both objects. That is exactly what we want and do that for the other two. Let's change the pre fabs removed the mesh Kalata at books Kalata. I make sure we click is trigger. That's the other thing that we need to do. And 3rd 1 Now remove mesh Kaleida. Add books. Kaleida Tick is trigger. First of all, let's Ah, remove the triangles. Cool. And just for the sake of our own ascent early, let's go and mute the audio source. Just we know it's working now. We don't need to hear it. Everything kissing when we play the game, Let's just meet that cool. So things seem to working absolutely perfectly. We have our theme song. We have a noise every time we the school goes up, and when we run into something, we get the big thud as well. Off course, we just passed through the game objects now, and that is fine, because what we're going to do is we're going to actually write some code for a game, for when for what will happen when we actually bump into one of these triangles. So don't worry. We'll fix this in a later episode, and we'll see there 25. Menu Layout Setup: So how are we going to approach? This is in this lesson. We're going to set up the basic menus system, and the next lesson we're going to start, um, coding in the actual functionality of it. So this lesson will beam or just dragging and dropping sitting things up, how you like them and all our explains in core concepts. So let's first office. But let's first start off by Dragon Canvas right up to the top, just so it's easier. And we're going to create three menu items to create empty, create, empty and creates empty. The first empty will be in game, so this will be the many that will be displayed in game. The 2nd 1 will be in menu, so this will be inside the menu and this one will be game. Ah, menu you. Why? And it's good to put you at the end of it, just so we understand it's you are cool. So our score is actually part off the in game us. Let's just first check these role at 00 with with or good or good, so we can just drag outscore into in game you wire. So, for example, if we wanted to turn off the score, we could just press this and turn it off. And we can do that through code, which is what we'll be doing in the next episode. So if we just got to a score and we can actually put on to day to make things easier, So let's turn off all these other menus for now. And let's just focus on the in game you are so the in game you and the only other things will need when we're playing the game is a pause button so we can right click on here and click. Create new U Y um, button and then we see the button pop in here. We can call this polls Paul's bottom, and then we need to go down to our, um, sprites photo. We didn't click everything besides the skybox. Highlight that, and we want to change it to a to a sprite. To do you are all This should be fun press supply coop. And then when we go back to our polls button, we can change this front to wear pause button. We can click preserve aspect, and then we can change the width 2 150 the heart to 150. And then we have a pretty cool looking play button there. We can actually pull button and we can actually get out of the text has been made that and click this and then we can just change its position. So change that to a spot that you would like And then I'm just going to drop the capacity a little bit cool so it blends in nicely with the screen. Awesome. So right now doesn't do anything. That's fine, because we're just sitting up the menu at this stage. Cool. So in the next part, we're going to deal with setting up these two menu items, and then after that, we will hopefully be a jump in decoding some functionality. See, there 26. Audio: cool. So it's time to add some simple sound effects to a game. This is also very easy. So let's actually get rid of our ground because we don't need that anymore. And our water. The two things that we took off not these guys, but the two two objects. We turned off another earlier episode, and we can save. And then all we need to do is go to a player and we need to add a component to a player called audio source and then go inside of our audio and we can actually go back quick back , not player. And we can actually drag our theme song to our audio clip, Um, section and we compress play cool, so that's working just fine. Then we can open up our player script and we can create two new variables. Public order your clip and we're going to call this score up and another one public audio clip damage course, the minute another on trigger inter function. So if we go over to score, we can actually highlight this again and then get back to playoff and we can go underneath the update, dump it in there. We don't need this. And if other gamer tag equals score up, that's actually exactly what we need. So we can just write our audio code in there so we can say, Get a component. So once again, this is getting the audio, um source component What your source. Just like we did in earlier episodes. And we can say what you saw. Stop play one shot and we can say what quickly were in play. We want to play score up and just at 1.0 f volume. Cool. And let's just copy this copy and we want to change this from if other going to tear equals triangle. We want to play the damage sound effect. Let's go back over the unity. First of all, let's make sure our prefab let's make sure our triangles actually are tagged with triangle . Yep, they attacked with triangle and the gaps attack with score up. Okay, everything is go on flying so far, and then we can go over to a player and we can assign our score up and our damage variables and they'll just being SFX. So get back to player and good n so score up school plus one and damage as damage. Cool. Now this won't work how we think it's going to work just yet, because on our pre fabs how pre fabs have a mesh Kalata. And this is actually a mistake, because our gap will work fine and we can actually test. That causes the trigger. But these are not triggers, and in fact, they're probably. We probably don't need a measure Kaleida, because there's such simple shapes anyway, So to fix that problem, we just need to click on these. Click on all the triangles within these pre fabs. We can remove the mesh Kaleida, remove and add a box collider. Because it's such a simple shape, they should fit perfectly. And we can just test it by dragging it in. And you'll see here that the box collider is pretty much perfectly around both objects. That is exactly what we want and do that for the other two. Let's change the pre fabs removed the mesh Kalata at books Kalata. I make sure we click is trigger. That's the other thing that we need to do. And 3rd 1 Now remove mesh Kaleida. Add books. Kaleida Tick is trigger. First of all, let's Ah, remove the triangles. Cool. And just for the sake of our own ascent early, let's go and mute the audio source. Just we know it's working now. We don't need to hear it. Everything kissing when we play the game, Let's just meet that cool. So things seem to working absolutely perfectly. We have our theme song. We have a noise every time we the school goes up, and when we run into something, we get the big thud as well. Off course, we just passed through the game objects now, and that is fine, because what we're going to do is we're going to actually write some code for a game, for when for what will happen when we actually bump into one of these triangles. So don't worry. We'll fix this in a later episode, and we'll see there 27. Menu Layouts: cool. So now we're going to be dealing with the in menu you instead of the in game us. This will be like our main menu, but will also be a pause menu that we both be the same thing. So first thing to do is turn off out in game you want, because we won't be seeing that. And then under in many a year, we want to turn it on and then we want to right click, and we want to create a new U Y. Um, penalty. And we can just drag this right up. Awesome. So that covers out main area. We can change the color if we want a little bit, so we can have, like, a bluey color or something just to saying that you enjoy someone, want to create and play buttons. We can just right click, create new you Why button? Same deal. We don't need the text. Call this play button and change the sprite to a play button preserve aspect. And then we can change the hot and the width to 300 by 300 or whatever you think suits. I'm going to bring it down a little bit just to cover up outplay. Next thing we want to do is create a new empty. I'm gonna call this Loga and then underneath longer. We're going to create another you I you are image. And that image is going to be our balloon beach title hit once again trusting that suits you. Drag this hump, call this title. I want to create a new image. I'm going to choose the games Toddle, Loga bowl change about 2 50 to 50. And also bring this to the right location When I call this left boom and gonna copy and paste right bowl. Cool. And I'm just gonna drag the title underneath so kind of there in the background and then just fiddle around till you get something that off something that you think looks good. Cool. So that's the in menu. You I obviously nothing is working just yet, but let's just turn off the menu. You I and let's go to go to a game over menu. You are So first thing we want to do is we can actually copy this panel. Well, some straggle into that, you know, obviously changes. Just biggest something else. If you want something else to look a different car. Lucky we could make it like a red color or something. But I'm just going to leave it as is. Next thing you want to add is a button, and this would be to restart our game. So obviously, because it was gonna be called a restart button. Get rid of the text because obviously we don't need that. It's changed the sprint to the restart button. Let's change the preserve aspect. Changes to 300 300 just like our, um, play button. And then I'm going to drag it down just a little bit just to cover up our, um, character as well. Once again, this is all personal preference. Do whatever you think looks good. Next thing is our hot rock click you. Why button? So when a call his heart and the new brackets ad show I had, I suppose it's a good way of saying it. We don't need the text. He can obviously change the sprint to the hunt. We can preserve aspect ratio and change the with 2150 by 50. Choose the position that you would like to be. Coop, your thing we need is our crown to show our high school. We certainly decode the functionally for that. But that is fine. So the first thing you do is at another image. This image will be the creme. So I find it 4 38 by two. 90. Looks pretty good and change the position. Call his crown image. Next thing want to do is add some text. So where has some text mesh Pro text. I'm gonna call this high school. You know the drill. By now it's put in a number 458 or whatever you wanna name it. It's a lot by the center. Let's change the font, but change the size. Bring his position up. Okay, so now we have the basic menus set up. Now that doesn't look crash heart. But all the items that we will need are there and laid in later episodes will be cutting the functionality and editing the ah animations. So now I'm gonna make some final adjustments to really make this menu system look better. This is all personal preference. So just choose whatever you think looks good and run with that. Cool. So I'm pretty happy with the in game you are. I'm pretty happy with the in menu you are now. I think that looks much better and I'm pretty happy with the game over. Many you are could have a red tinge there, and I think everything is a bit more proportional. Looks a little bit better. Cool. In the next episode, let's start cutting the functionality. 28. Menu Off And On: Okay, let's talk. Cutting the functionality. Let's open about scripts, photo and open up app initialized. Okay, so it's kind eaten a few things up here. We'll be doing a lot of work in this script in the next few episodes, so I just want to make sure that everything is set up pretty nicely. First thing we can do is you can actually write in awake application dot target frame right , and we just equal up to 60. That would mean that it will target 60 France for second so again will look smooth on all devices. Then we can set a few variables, so these will be our menu, Our menus. I suppose you could say so. Public game object in menu. You are public game object in game you are and public game object game over. You are so another variable made is a reference to a playoff so we can run public game object play out. So now we can access out playoff and we want to. Actually, the first thing we want to do is we want we start again. We don't want to start and just immediately start playing again. We want to start in the menus. The first we want to do is actually stop the player from moving. So we do that by just saying Player don't get component. Rigid body don't constraints equals rigid body constraints dot phrase position Then all we want to do is tell the game which items on which menus we have want to have on and which many is. We wanna have off and the first thing you want to do is we want to turn out. We want to turn out in menu You. Why on so we did that by saying in menu, you are dot game object, don't set active and then we can just put inside parentheses. True. So what that's doing is that is making sure that that in menu you are is ticked on like that. That's what that said active represents and the only other thing we want to do and this is just for for having clean code is we want to turn the other to make sure the other two were turned off so we can say in game you are dot game object dot said active false closes semi colon. Obviously we can copy this dumping underneath and we can say Game over you I to give objective, active equals false. Soon as we get back to a game and we go to our seen manager, you see that we can fill in these three spots so we can fill in the player we can fill in. Game over your eye in menu you I and in game you are Coast's press play and see what happens. Awesome. So now what happens is all the other menus turn off on this menu turns on fantastic. That's exactly what we want. But now when we press play well, a game doesn't do anything. We can suppose we move left and right if we use the control sticks well, the keyboard, But again doesn't actually do anything. And we pressed the play button. Nothing actually happens, so we'll tackle this problem in the next episode. 29. Menu Start Game Button: Okay, So to get that game playable again so that when we press this play button ah, the game actually starts. Let's go back into our app initialized, stripped. And we need to create a new method. And this will is gonna be encouraging, actually, but this method will curtained is going to, um, do everything that needs had to happen when I gained means to stop. So we don't actually need updates so we can get rid of update, and we can run on the numerator start game. Cool. So this one, actually, you see what wouldn't air already? Because our in your marriages need to return something. Um, and what we could normally do is we could, like, get it to wait for a few seconds and stuff, But we don't want to wait every single time we play the game. We want only when we press play after we've died, we want to maybe wait for a second. But when we press play, when we first started playing the game, we don't want to actually, like, wait for a second. We just want to stop playing the game, if that makes sense. So what? We need to do is we need to have a We have a local variable. Now, we haven't done this yet inside off this project, so if you're a little bit confused by it, that's fine. I think this is the only instance that that will actually use this. But I want to do is inside here. We can pass some arguments that need to be called when start game is called. And the argument is to be that we're just going to make the variable that we that you're going to need to put in for the argument which is gonna make it afloat. And we're just gonna call this wait time. No, I'm calling that. And then we could just say yield return. No, uh, new Wait for seconds. Look. And normally we would just put a number in here, but instead of putting a number and we can just actually put in wait time, which is this float here. Now, why is this important? Why we don't like this. Well, it means that when we actually call this co retain, we can call it in such a way where we can actually designate how long it needs to wait for whether that zero seconds or whether that's one second or 10 seconds or whatever and we'll be using this method for two different purposes for purposes will meet end on the game over screen. And we want to start again or for purposes when we just start the game. So the other thing that we want do inside off start game Ah, change all of these. So we'll copy all these paced him in there. And we only want the in game. You are to be, um, on So the other two will be false, obviously. So maybe it's false and make this true Cool. We probably want this yield statement underneath all of these. I'm instructions here and then underneath weight anethe this yield we just want to set the players motion back to whatever it originally waas. So we can just grab this copy of this line of code, dump it in here, and we can say Richard body no constraints don't none. Sedans turned off all the constraints and the only constraint we do actually want on is that why? So we can go back, dump it in there again and say freeze position, Why cool? So there's a tenable off and then turn the wire freezing back on. Fantastic. So you may be thinking great. We got this long will not really long, but we got this big method here that kind of explain that it does everything that you know you expect it to do. But how do we actually call this method from inside the game when we actually press the play button? So if we press play now, you'll see that nothing happens. Well, we actually created method that the play button can use. So how we do that u Conn. A new method cold public, and it's important to say public, so we can access it with inside the inspector void. Play button. Cool. So later on, we'll add some more functional at some if statements inside the play button to do the wait time functionality. But for now, we need to do is write, start parroting over parentheses. Start game, which is the name of the current ing over princes again, and now it's asking. You can see here is asking for our white time, and we're just going to say 0.0 F, which is 0.0 seconds and then we're just going to close it off with a semi column. Awesome. Let's test this out. So if we go over to our game weaken, go inside of the in menu you why we can turn it on just because we're working on it and we can go to a play button and you'll see here has a method called on click What? We can actually press the analyst. We can choose the scene Manager Dragon into that selection there, and then we can actually access functions that are on that script. So if we go click on this no functions, we could go down to APP Initialize, which is one of the scripts that's on the scene. Manager object and we could go to play button So the ball domain is when we press the when we click this button, whether it's a touch screen over clicking with a mouse, it'll run the play button method on the APP initialize script. And when we go over to our app initialize script and we see that play button that play button it calls the start game current teen and the start game Claritin changes ally menus , waits for however long it needs to wait, which at the moment is note Norman a time and then puts the rigid body constraints back to in game functionality. So that should be pretty easy to understand. I hope everyone's following along, but if we press play now and see what happens, press play awesome. So the game starts and that works great started again. Press play. Once again, I compressed play button. The game sounds playing, and everyone is happy. Awesome. So in the next episode will start dealing with Paul's menus and things like that and continue on with this menu functionality. 30. Pause Menu: Okay, so let's add some polls functionality. This is actually pretty easy. So if we turn off out in menu you want and let's turn on our in game you are, you'll see we have a button up here, play button and we just need to have a known click method that we can call that will obviously freeze the position and things like that. So if we get back over to our script and we've got our public void play button underneath that we can say public void pause game they're in just made this set of bad boys, and then we just copy this line of code dumped in there as well. And then all we need to do is go over to our pause button at a new on click event. Dragon Asi manager. Done this in the last episode, Go to APP. Initialize pulls game cults for press play. Game starts when we compose it. Awesome to say that we're playing the game. He and we pressed Pause right here. Well, when we actually press play, we're going to run straight into this, um, this triangle and we don't want that to happen. We want to give out our player like, you know, maybe a second to to, you know, reposition themselves before they get slammed into this triangle. Safe. Reverse play. Now there's nothing we could do virtually straight into that, um, triangle. So we want to give people a little bit of a warning after they've actually start of the game and the pause. The game. So how do we do that? Well, let's go back over to our app. Initial a script. Let's create another variable called public, and this one will be a bull. And, well, it's just It's just going to cold. Has game started and it's going to equal fourth. It's gonna just default to false Great. In fact, we could make this private doesn't need to be public just so we keep the inspector neat, and then this is where we do that Tricky if statement stuff that I was talking about before so inside about play button. We just wanna have an if statement run and we want to say if has game started equals true, remember, two equals? Asked the question. Then we want to start courage ing, but we want to actually wait for maybe one second, But then we want. But if the game hasn't started, what we want to say stuck, we want to say else. So if the game hasn't started, if the bull hasn't suddenly eagles false, then we want to just start with zero seconds. DeLay doesn't make sense, so if the game has started, it was true. Then we wait one second. But if the game hasn't started, we equals zero. Well, we haven't actually set this to true. So where do we set this to true? Well, it would make sense to put it inside the pause game method. So when we pause the game, that's when we say, OK, the game has started now, So first thing we want to do well, probably the second thing we want to do is say, has game started equals for cool? So let's test it out and see how it works. We press play and we press play. Everything is going well. It started instantly. Cool and then let's press the pause button and then we'll press the play button Awesome. So it gives us a one little second, um, amount of time to understand where we've got to go and what we're gonna do. Press play weights one second. Bam! Back into it. But if we start from the start, it just stopped. Awesome. So that is working exactly how we want to work. And now we have a functioning, um, play button and a functioning pause button. And the next thing we need to do is work on what happens when you run into a triangle. Well, we know what needs to happen. We need to turn on this in game over menu you are. So let's work on that in the next episode. 31. Game Over Menu: Okay, so let's start working on the game over menu popping up. So it's also pretty simple. Open up the happiness live script, emigrate and create a new public avoid game over, and we can basically copy everything from the Pause menu. But obviously, this will be false because we don't want the in many year I am to be on. We want the game over. You are to be on. So the other thing that we want to do is if we look at our game, we have inside the in game the game over many you why we have a heart, which is a show add button. So we need to create a method for when someone clicks on this button, his own clicks on this. We want to show an ad and then give them an extra life. So we need to create that method first and then in a later episode, will actually deal with the functionality. Oh, creating the ad system. But for now, let's just create a new public public void show ad, and it's sort of show ad. We just wrote a comment fix later because this is something that we will need to fix later , but just so we can understand Ah, have things going. We can just copy this, start courage in here. Awesome. So if we go back over to you, Nelly and we go to the heart show add weekend on at an on click functionality weaken, drag over the scene. Manager, we can add a app initialized show. Add. So when we actually fix this game later on, when we actually implement the show ad code, we will actually have a another bowling here that will basically say, Well, have we seen the ad before? And it's like, Well, no, if we haven't seen there before, then were allowed to press the button otherwise would know letter press the button. But right now, just for testing purposes, we're just going to put this in here. Fantastic. So we got a game overworking and we got a show at working. But how does void game over get cold? The player needs to run into something, and then it needs to. Then that's when we need to call the methods of how do we do that? Because thea up initialized script isn't connected to the player. It'll okay, so this is where we do some magic. We're gonna go over 12 player script and you'll see we've got this audio source. That's some. If we run into a triangle, this happens here. Well, we can actually call a method on a map initialize script. And we could actually cole the game of the method because it's public. But how do we do that? Well, first, we need to create a reference inside the player class to our script. Such the top here, we can say public game object, seen manager and then underneath this play one short audio source Inside Triangle. We can just call the game over method from this so we can actually say Seen manager don't get component. Have initialized from princes. Close parentheses dot game over. However, princes close parentheses done. So now when we run into a triangle, it's going to call the game over method. It's gonna move over to the APP initial a script. It's going to call this method here and that method. First of all, it makes the player stop its position. Great. It says Game has style because true, great, and it pops up the game over you. I, um Ah, it says that that Active said, that menu pops up awesome. So then we have the option to restart the game and we have the option to show ad. So we've done the show and functionality, but we also have the option to restart the game. So to do that, we just need to create a number, public void, restart game. And this one's going to be a little bit trickier because basically, we need to create. And we need to start with a new name space because we're dealing with scenes. Now we just need to write using unity Engine thought Seen management cool. So then what this does is it gives us more functionality inside of our code here and in underneath restart game, we can just load the same scene that were actually in. So right now, if we go to file build settings, we'll see that we already have a scene in the build. If you don't just click, add opened scene and you'll see that it's index's zero. So that's the index for our scene. So we just remember that it zero if we go after the code, weaken just foot when we press the restart button weaken. Just simply type scene manager. The load scene zero Done and just not here. Loads. Whatever scene is at Index zero in build sittings. So let's go back over the unity and let's let's get this functionality working. So let's go to our heart First. We've got happen. Initialized. Show add. Yep, that's all good. Let's go to a restart button. Let's Haddon on click event That's dragging are seen. Manager. Go to APP initialize, and we want to restart the game. Cool. Let's press play Correct menu pops up Iran. Okay, and we've got an ERA. The era. Let's look so if you go over the console will see unassigned reference Exception The variable See manager of players not assigned the case. Let's go over to our player. We haven't assigned a C manager. It says none down here. So let's make sure remember to drag that over. Let's try again. Press play. The correct menu pops up. Press play bam! Okay, now we can press this button and waits for a second. Awesome in press the button again because obviously got unlimited lives at this stage and it works. Just how were expected to work. And if we die and we compress the restart button, it reloads the game. Awesome. So that is working. Just how would expect it to work? Fantastic. See you in the next episode. 32. Saving & Loading: Alrighty. So what we want to do now is we want to a just our high score, which is well, will appear the when we die or when we have the chance to use unity ads. So the way we want to do that, though, is we need to actually be able to save and load dollars. So this is actually pretty exciting episode. So right now and when we press play, um, and we press the play button and we die the score is 47 500 or 458. This is not ideal for obvious reasons. So if we open up our score script, the first thing you'll notice and you may not notice that it's the same one yours. But it's definitely like this on mine is we have to squiggly lines under tm pro and text. Much pro you are you? Do you? Why, Um I don't know why this is This isn't affecting your game. It'll but my inkling is I think what's happening is there's an error inside of visual studio messing messing with this because this this this is a new feature to unity, to be native unity and assistant error inside of visual studio and nothing to worry about. Ah, it's not actually affecting games. If you see this in your project, don't worry about it. But if you don't see it, also don't worry about it. But it's all good. First thing we want to do is create a public and we wouldn't make public audience high score, no high school. And we want to create a reference to the high school you are so we can just copy this line of code and at high Score Awesome. And then it's pretty simple. All we want to do is say in update. Weaken say, if school is greater than high school, then we could just save hosko Datta. So how do we actually save Donna? Well, it's really simple. Inside of unity Weaken Just use Player Pref Some play preface really powerful and really simple and gets the job done exactly for what we need. So we're going to be using play preps, so to do, to use play prep. So we need to do is write, play, press don't set into, so we're setting an interview variable. I prevent open parentheses, open speech courts. We're gonna call it a variable high school. So it's either accessing a variable called high school and, if there is not, is going to create a variable called High School after the print. After speech, quotes be press made comma, and we want to just make it equal to score while we make unequal to score well whenever score is higher than high school, and that is a new high score. So instead of been changing the variable of high score to score, we can just cut out the middle man and seven integer high score equal to score. Because what if it is? If score is higher than high score on my gosh letter scores in this sentence. If score is greater than high score, then Weaken said in an interview to whatever score is and that will work perfectly fine. But what about actually getting the high score? Well, how does that actually work? Well, let's create a stop method void. It starts, and then we can write something as simple as high school vehicles. Player preps don't get int, and then it's just asking what interview we want to get, what play perhaps you want to get and we just want right high school. And as long as these export exactly the same with same capitalization, everything, it will work just fine. Then I wanted to do is write high score. You. I don't text equals high school dot to string, but I've just realized we have a problem here. It may not be obvious at first, but let's go back over to you, Nelly, and we'll see if we can discover the problem. So if we go over to our player, if we open up our canvas and open up a game over menu you are and go over to play out, we can actually scroll down and we can see that we have an empty spot for high school. You are what? Weaken Dragon out high school, So pressing play and pressing the play button scores 123 and die. Okay, escort zero. But we just got the high score of three. Let's restart the game. Press play again, Di Oh, now it's displaying a high scores. Three. What's going on? So it's actually saving the daughter, but it's not displaying it correctly if we get the high score on that round, if that makes sense, So, for example, let's Ah, let's be their high score again. Press play. 123 four Bam! It shows three. It's saved four, but we're actually still displaying three. Well, why is that? Let's go over to a code and have a look. Okay? When are we adjusting the hospital? Very variable. Okay, we're adjusting. And here, here and here. The only ones actually setting the high score integer variable here. The only time high score is actually being changed is in start. Which only happens once at the start when this script is called. So we need to actually change some of their code here. So right down here where it says play press set into high school. Equal score. We could do that, but to fix the problem that we're having now a better thing to do would be to change the high school. So we say high school equals school cool. So if score is greater than high school will now high score equals school. Fantastic. And then we want to set out in future. And we could just leave it score. But let's use high school just for consistency sake And let's go inside of here and say player proofs don't delete all you can press play quickly Bam less save daughter should be later. Now we can delete this line of code Go back press play when we rollin Bam should be zero. That's exactly what we expected. Press play and bam! It should equal three that is working perfectly. So if we restarted now and we press play and we die here bam at high scores three. Awesome. So I hope that makes sense when we women need to save data. We're just setting in Georgia called high school and were equally into the high school variable. And when we want to load the data where getting a high school variable and well with accessing player preps and we're getting an integer and we're getting the insurgent off high school and was sitting that interview, I was sitting this injured your high school to the player preps integer off high school. How many times I say scoring this episode? Okay, awesome. So now we have a working, saving and loading system, and our high school menu is working perfectly in the next episode will work on adjusting the menu to have a little bit of Zach's, and that is animations 33. Menu Animations: Okay, so let's jump straight into some animations, right? Click and create a new photo calls animations. And then we're gonna work on the in menu you y animations first, so we probably want how play button to pulse in an hour. So we go over Teoh in many U Y and go to play button, and we can just click over to animations and then click create. It's going to ask us where to put the animation, and we can just call this play button and saved inside of animations and animations of Pretty simple to do. We just need to We can actually just press the record button, and we can go to say 30. Change the width to 400 and the heart to 500. You see almost a bit too big, but you'll see that they will turn red, and it will fill in the data here, the size doctor, the size Delta Donna. And we can copy these key frames from the start so you can see it goes up. Couple these key frames from this stunt and drop them in of end here. And if we press play awesome, that's our sweet animation I think it's a little bit to violence. Let's go over to the middle key frames again and let's say for 50 let's see how that looks . Jesus still won't be a little bit too No, I think that looks everything looks fine for our purposes. Awesome. The other thing would be one to adjust is if we select our logo. We want to create an animation and we're gonna say logo, save up. And once again, we want to press the record button so we can start it. Probably, you know, like so let's say 700 and then at 30 or whatever you think looks good, we can drop it down a little bit. And then up here, we can say 700 let's see what looks Looks like that's a little bit crazy. So we can just use this, that I'm scroll pad to just scroll down a little bit and weaken drag these right, And that's these key frames. So I'm gonna drag it out to say 1 50 drag this to about there, and I'm going to actually just this up a little bit cool surfer press play that looks a lot better to May. Okay, so if we press play now, we'll see the play button moves and we see the longer move. We want the balls to rotate as well. So if we un click that and we click on our left bowl, we can add a tomato. Now. This happened or medically before because we were. We weren't using a child object that already had an animator, so we need to do this ourselves. So if we just had an animated clip and weeks click on our left ball will see down here in the animation window, it now opens up a new, um to begin animation Left Ball Creek Click New animation clip creating. You were gonna call this left full cool, and we just want to do some rotation. So if we press the record button, let's zoom. Yeah, probably wanted it about 200. So if we got to the rotation here, we can just go to the Z 3 60 That's a full circle. And then, at about safe, the two. Yeah, I would say zero. We press play awesome, so it looks good, but there's a little bit of dampening their Well, what do we need to do. Let's to fix that. Let's go into her curves. And if we just scroll up, you'll see that I curves like this. We grab this section down here, we can drag it up. And if we drag God this section, he weaken. Drag that Dan. So it's a bit more of a straight line. And now if we press play, you'll see it's just rolling along. As if flack, it's got no dampening or anything. Just look rolling along the wind, which is the effect that we want. Awesome. So we want to do the same thing for the right play button. Click on right click on right bowl. Add animator. We can click back over to it dub shape. It's asking us for a rightful animation clip. Yep, create new one yet, right? Well, sweet. Press the record button. Leavitt ad. Pull it. 3 60 We can got it to Which is what? We had a lot and zero go to a curve Sheets. Awesome. Let's press play and see how that looks. Okay, so now you understand the basics. Adjust things to your liking, and I'll do the same. Okay, That looks pretty good too. may. I'm happy with that at this stage, and this actually concludes the Polish ing section of our game. Everything is working pretty well except for ads, but we'll cover that in the next section. But that game is working pretty good. All the buttons work fine. We can play weaken pulls, we can play again. We can control everything we got. Animation's working, and everything is looking pretty swell in the conclusion will talk about what we've learned over this Siri's and just read a reading a few off the design and coding decisions that we've made and will also implement our unity ads Look forward to seeing you there. 34. Quick Recap: welcome to the conclusion off this Siri's. Before we get on to making putting an ad support and doing the final few touches. I want to just go over things that we've already learned. We've actually done a lot of stuff in this game, and it may not feel like it, but I don't want to recap what we've done. If you have made it this far. Congratulations. You're really awesome and you're on your way to becoming a sweet game developer. We learned about installing Euna Lee, setting up for mobile functions. We learned that variables then went on to learn about materials play of movement, how we can get the player Teoh move with mobile, important controls. We got camera camera system working. We got a score system working. We got saving and loading working. We got random. We gotta get the levels of randomly generate objects in random places, and we got the level to continue on forever within. Start talking about shade er's cleaning up our code audio and then adjusting our menu and adding some animations. We have covered a lot in this course, and I hope it's being quite enjoyable for you. You've got to take these core principles and expand them into other areas and other games that you want to make in the future. All the code were written in this game. We're work in pretty much every game, and I look forward to seeing some of the awesome projects you guys work on in the future. So in the conclusion section off this Siri's, I want to touch on two things. I want to add unity, add support, which is pretty important for monetizing your game. And I also want to touch on where we go from here. What features could you add? What features could you remove and what features could be cool and how you could approach them in our current game, So without further ado, let's get into it. 35. Unity Ads Setup Logic: Okay, so let's just jump straight into making some ads work inside of unity. So what we want to do is if we press, play and press play again when we die, we run into these spikes. We wanna have the option to press this little button here and for us, a show on ad, and then it gives us an extra life on. But we only want this to happen once, and there's a little bit of logic that we have to code in there. But to first get started, we just need to move over to our services tab over here. And we just need to go to the ad section here and turn it on, monetized me that your game sweet. We can click on Go to Dashboard and I will bring us to the website where we can look at the information about how many people have clicked on the ad and things like that, and it will be linked to your unity account if you have logged in and so far everything is looking good. We can enable test mode for development, and we can click back over to our inspector. Okay, so how do we actually get, Ah, unity adds to work inside of our game. Well, first, let's open up our app. Initial a script. We could have our own script that deals with all of this stuff for just the ants. But I think because we're doing so, it's such simple add functionality. It'll be fine to be in app initialized. So, luckily, if we go over to, um, if we go over to you only three to calm such services that as such quick start guide or if you top in the quick start guide for Unity adds, you'll see that we have some example code here and you'll see it even shows us where we want to put our code, your code to reward the gamer in here. So this cut this code Here is the simplest way to get unity, adds working, and you'll see that we need unity. Adds dot advertisements, name space and you'll see a few things in here. I encourage you to read this God to give you a more in depth understanding of what we're doing. But right now we're just going to jump straight in and get the ads working as quickly as possible. So back over to visual studio, there are a few few things that we want to set up. First. We want to add to name spaces using Unity Engine dot out of a ta Zeman's using unity engine , don't you? I cool. And now we want to code in some functionality to just get the button toe work at this stage . So to do that will probably need to create a new to new things. First, let's create the reference to the button. So let's just put that up here. Just a little. The menu. Adam, you are items air up here. It's a public game. Objects add Boston Coop, and we need to create a bullion private just cause we don't need to see it in the Inspector Cool has seen rewarded God and what, like what's falls? Fantastic. So then, if we scroll down to a game to our show, add button here, you see that right announces fixed later, and then it just starts. That's the current team, which is start game. Well, we could get rid of the fixed later for now, and we can just write something as simple as has sane rewarded ad equals true cool. And we're just gonna add a note that this is just temporary because of this, just for testing purposes, even though it was protesting purposes before. But bear with me and then inside of game over, we want to create an if statement. It says, Well, hey, if we have seen the ad, we don't want that button to look or like it's gonna work and we don't want to actually work either. So we can just say if has seemed awarded ad equals true. Then we can reference a few things and just turn them on or off on site on the add button. So the first thing we're gonna do is say, add button dot get component image, and we can access image because we're using. We're using the you know, the engine that you are names best. So add bundle get computer image dot color equals new color. And then we just want to set readily to one green, um, green toe one, um, Fluto hon and Alfa Channel 20.5 F. So if you're not familiar with color, basically was setting everything to be exactly the same cold that it already is. So we're setting all the values red, green and blue to 100% and was setting the transparency to half the transparency. So I hope that makes sense. Do anything to say Add button, I thought, Get components button. And what are we gonna do if we've seen the ad we want to? So it enables Eagles false because we don't want them to be able to press the button. All right, let's go over to you, Nelly and see how that goes. So just so we understand when we when we hit something, we press the show at Button, it's going to what would happen here's would normally show on ad, and then it would turn this to true. But what you're going to have to true now because we're gonna show that just yet, and then it's going to start the current scene. But when this is true, when we bring up the game over menu, next time it's going to turn the color to 0.5 and make it so we can't actually access the button. So back over the unity. Let's open up, out, game over menu. You are heart show. Add fantastic when was dragged The ad heart show out into the add button section on the Scene Manager script. The APP initially script on the scene. Manager of Object. So let's press play and let's test this out play bam! It was pressed, his button cool and bam! And they are. The button is no longer working, but we can still restart the game. Chris play Bam heads back again. Awesome! So that works. So the functionality works absolutely perfectly now, and now we need to do is get the actual ad to show, and that's actually a lot simpler than you think. So we'll talk about in the next episode. 36. Working Unity Ads: So if we open up our app initialize script and we go down to our show, add on button here, what we need to do is we need to we can get rid of this. We talked a unique at anymore because we know it works. And let's go over to a unique quick start. God. Okay, What we need to grab from here. Cool. So we'll see here. They have the public void showed rewarded ad, and they just have one. If statement in here, you can see they use a different style off coding than I currently do where the they put these down here than up there. That's just personal preference. It doesn't actually affect the code. If we press ah copy and go over to code, we could just dump that in there. I think it could actually get rid of, um this is well, so now instead are throwing an area here. But let's go back over to our script here, and we'll see. We got a private avoid handle show results, which is the same thing that was being underlined. So this is copy all of this. Leave it. The last one. The last Ah, Kelly brace because it'll be the class Kobe then and let's throw that under here. Now. I'm just going to fix this up to be how I like it cool. So that looks pretty good to may. I think that is good press save. Let's go over to you nearly because we've just copied Sim card from somewhere else. We just want to press play and just make sure we get no errors. Awesome. We get no arrows in. We see we get this unity adds Initial. Isaac was true here, so that's good. And that's just showing that things are working well. If it says True says that things are working and here we want to say your code reward Gamma goes. He give coins etcetera cool. So I don't need that. And then we can just say has seen reward Lad equals true. So just so. Everyone knows a switch statement is very much like an if statement, but it's just switches through the results, and when it lands on a result, it doesn't continue and ask the next set of questions. So it's a little little bit Mawr. Ah, it's a little bit more friendly for like my balls. And it's a little bit less work for the computer because it the quicker than if statements a Zafar a CPU is concerned, but they're very much the same. But all you need to worry about is putting your code in between this section here. So we've got a few cases we got case show results equals finished. So if we've finished the ad the little day bug got logo that has been shown, we turned the rebels the true, and then it breaks out. So it goes, Alright, we break out of this and we just exit this method here. Cool. If you've skipped the ad, well, nothing happens. But you could put some courage. And underneath this, um but nothing happens. It just says, Yeah, biscuit before the end, okay? And then it breaks out of that. Or if it's failed to show that could save had an incident problem with something. Nothing happens Theaters and D bugs and logs and air and says the ad has been felt the show and then it breaks out of that. So the one that's going to happen the most is at the top here, and we want then. So it'll hopefully come to this. The ad will be shown successfully all the way through, and then we'll break out of the the switch statement. So if that's a little bit over what my home and you don't understand, that's fine. Going to remember is stuff that goes in between, um, this break and this cased dot finished is the code that will be run. So what's the next thing that we want to do? What we need to do is he keeps trying to form into like that. So let's just leave it start Curtin stunt game and we want to pass, Um, the the time as, let's say, 1.5 seconds. So 1.5 s cool, and I'm just going uneaten this up a little bit. Well, I hate copying. Other peoples could Yeah, I think that's had a specially formatted, but who knows? Doesn't matter. It doesn't affect the game that looks fun to me. So now if we go over to our game and we press play can see over here and it out enable test motors on, we impress play bam Press that the hump this green would be your Adena awesome. So it's working perfectly. Fine. Press the close button. It's 1.5 seconds and then continue zone and we compress it. Fantastic. So that is now a functioning unity ads system, and the last little thing we need to do is set some cool animations and make it more enticing for the player to press the hot button. See you in the next episode. 37. Ad Button Design: old Roddy. So when we pressed the play button now and we get smacked by the big triangle we want when this button eyes available repressed, we want to entice people to be able to press this button. This is a good way to get people to want to keep clicking, you know, keep clicking on ads, and we want to decrease the value of this button. So what we can do is when this button is available, repressed, we can make it pulse, and we can make this button look exactly how it is now and then. When this button isn't available to be pressed, it doesn't pulse like animate, and this one does animate I have. That makes sense. So to do that, let's go over to our in menu you I Let's turn that off. Let's turn game over the menu, you on. Let's select our hot click of it animation crude in your animation in animations, and we're gonna call this hot and button. Remember to do a press the record button, and we can change its with two SE 200. Move it to higher. Maybe 1 75 We could probably dragged that to 30 Um and then say 1 50 1 50 and then copy days and throw them up here. This should be pretty familiar to you and press play. Let's say that looks like that looks pretty good to me. So we got that animation. Fantastic. Now we can click on our restart button. Same thing. Let's add an animation re stunt button press record. And we could do a cool rotation thing so we could do negative 3 60 and then scroll out to say, three calm. 00 is your Let's see that looks like cool is going to the curves. And let's just make sure those curves Ah, pretty straight. You can adjust things you're locking or you can add a bit of a pulse to it if you like, But we're going. I'm just gonna leave it like that for now because I think that looks pretty good and let's go back over a project. Let's go to a script and let's open up the APP. Finish last groups already. So let's go down to the game over, um, script here, and we just want to add a couple of other lines of code to adjust our at button. So, um, some stuff in here so we can say add button. Start get component. And the mater don't enabled giggles. False. Cool. And then we need access to our restart button, so can't get up here. Public game object. Greece, Greece. Top on scroll back down here. And we want to set out a restart button. Don't get component. Ana Mato, I thought enabled equals for So what this will mean is when we have seen the reward, it turns off our at button from being, um, animated. And it turns on our restart button with that. But what that actually means is this one needs to be on by default, and this one needs to be off by default. So then we go back over to you, Nelly, and we go to a movie menu. You Why? And we go to a restart button and we turn the animator off. So if we press play now, press play. Bam! Cool. So right now, it's tempting us to press this button here with me. Of course, it makes sense. Press this button, right? It's not really tempting. It's a press. This button, you press it. We see an ad close the add weights 1.5 seconds. Bam! And it's not working was not working. I hope everyone knows by now we forgot to assign it. So lets his Dragao reset button in. Test that again. Press play. Bam president. Add close ad, awesome cinema conferences And it's tempting us to press the reset button. Well, it's saying, Hey, this we're gonna do so We're teaching the player what to do. Subconsciously, the average person doesn't think about these things, and we can easily just press this button now. And the game feels a lot better. So now we have a working game over system with ads implemented. Everything is working just fine, and all we need to do now to make this production ready is when we are making it production ready. All we need to do is unable test mode, and then we're ready to rock and roll. We can export this and pull onto both IOS and Android, and the unity ads will work just fine. It really is just as simple as that. See you in the next video 38. Updating Player Model: Okay, so in this episode, we want to finish off our player. A player right now is just a generic sphere. But we actually want to change that because we've got a model of that player so we can use truly from materials. So if we go to our player and we can see all things that player has on it, if we just turn this off and we can rename this temp and then we can go to our models and weaken drag al Player and you see that a player is probably too big. So let's make the scale, um, 50 by 50 by 50 rotations. Zero cool. Now you'll see that if we click on a model, we have, um, two materials here. We can extract these materials and we can put these materials inside off and materials photo Cool. If we go over to materials now, you'll see that they're here. And if we change them to curve world Shaler, everything will fit nice and snug. Beautiful. Now, if we press play now, nothing will happen. But basically a player is moving forward like this and not actually rotating. We need to actually code in some functionality for the rotation. But for us to actually test this out in tow work, we need to put overall, um, all the components on here to get to work correctly. So we need a speak louder. A rigid body player, um, script, a score script and in audio source. So let's do that. We can actually copy the components by moving over and just copping Opponent Pace component as new copy component person panel is new Trump component Peskin panel is new copy component pairs components new. So the reason is good to copy. Instead of just creating all new components because that feels in all this information, the only other thing that will need to do is go over to a camera and we can actually drag out player into this section. Seen messenger. We can actually drag out player into this, um, object. Spawn a script here, and we can also drag out player into this up. Initial outstripped here and we could make sure player is tagged as player. And then you'll see when we play the game and breastplate. Oh, we don straightaway. Why's that? Let's have a look. So how player has ah so what the problem. The problem is. So we have a Sphere collider here, and that's fear. Clatter has come over from our other game object. But you'll see that. I bet you yet as clatters actually huge. And the reason it's so big is because we copied it over from, um, our last has removed them a couple of from my last game object, but this one is 50 times larger in scale. So we're just going to add Ace nervous V Claddagh cool, and that looks good. Listens. Press play awesome. So scoring works. Getting hit works fulsome. Everything looks fun. Except our player doesn't actually, um, rotate, which was happening before. It's just that our material didn't show that that that was actually happening. So to fix this, let's go into our play a script and add some code. So scripts player, So underneath our lot of could he that actually moves the play forward. We want to say transform dot rotate vector three dot right. I think right will work, and we want to times that by get component rigid body dot velocity Thought Z. So that is the speed that we're moving in the four direction that's how fast we wanted to make it. But maybe divide that by four. So it's just not so fast because that would be a pretty fast number. So if we go back over to unity and we press play, so everything's that services is easier on a new player. Object. Awesome. Cool. If you wanted our slept works as we expected. If you want things to move faster, um, weaken, get rid of this or change the number there. Go back to unity and press play and you can see it's quite fast and you'll see that when we stop. If we go over room, we go to player, you'll see it's actually stopped as well, which is what we want. And but let's I'm gonna leave that at divided by maybe three, but faster. So that looks like, Ooh, that looks pretty good to me. Now we could, actually, if we wanted to rotate this, say, we wanted to rotate it, um, 90 degrees. What we could do is we could go into he incident, saving three rocks, a victory forward because remove, announce rotated and we could press play as a little bit tricky. But you get the idea. Awesome. I'm going to revert there back to what we had allows before. Cool. I'm pretty happy with that. So now we have a new model in the game. I just want to get the player and just make this zero gangs. I like to face this way, and we don't actually need outplay a temp anymore. So get rid of that. And this is play test. Make sure everything is working. Okay. And everything looks to be working fine. If we crash, press and add Awesome. Cool. Everything seems to working fun. So there you go. So we have a new model in the game which has different materials. Ah, the the If you actually go into the materials, you can change Obviously the color of these, if you wanted to a different color. Um, but I'm just gonna leave the color. That was because I like that and Yeah, there we go. So I'll see you in the next episode. 39. Where To Go From Here: Okay, So before we tie a bow in this project, I want to go over a few core things that are vital to this course. And that is that everything that I've taught you to do so far has been made, just shown you instructions on and then you topping its instructions. But where I want to really encourage you and where game development goes from game developer goes from basically a novice to someone who can make their own game is by experimenting and adjusting things and trying out new things. So what I want to do is explain to you a few things that I think that could be done in this project to make it way better and then But I'm not actually going to show you the explicit way on how to do that. But I'm going to point out a few design decisions that we could make. So, for example, if we play the game now and we press play again, the game very quickly gets boring. And why is that? Well, it looks impressive. I mean, well, it's not It's not, um, you know, God of war, anything but it. You know, it looks Okay, um but there are a few little things that just don't sit right. So right now the ball kind of rotates only in one direction, but it because if it wrote, held with the horizontal axis, um, it also right now, nothing else happens in the game. So this game gets boring very quickly because we're dealing with the same objects over and over and over again. So basically, the player has one choice. The player has the choice to move around the objects, and that's it. There's a lot of middle sections here, so the player has the choice to just move away from objects. And that's all the play has to do. But where game design gets where game design comes in and where and how we could make this game a lot funner is if we had more conflicts for the player to resolve and what I mean quite conflicts. So, for example, if we were coming along, I'm just press playing an important again. So if you're coming along and we had the option between these two toe also pick up a coin or to pick up a power up. But let's say the parables here. Ah, player might risk running into that, Um, these just to get the power. Or let's say we wanted to make it. So there was some coins that sprinkled down or let's make it. So we we wanted to make it that, um, that, um certain power ups make coins come towards you and then gave you a point. Well, this would give the player options. The play isn't just going through different. Oh, yes. Got through that one. Yes. Got through that one? Yes. Got through that one. They have to make the decision. And in the split second of time, do I want to go? Go for the coin that's here. That might put me at risk. What? I want to play it safe and go through here. Or what? If it's a special quint? It gives you five points, etcetera, etcetera, etcetera. We want to give the player options on how to be the best of the game. If that makes sense, we want to give them ways to be better. And right now our game only has one way and that is to repetitive. Lee Play the game now. I could be wrong. This could be good game design games like Flappy Bird was so simple. But they played on the idea that you died so quickly that you could restart and was easy to restart. And that was actually really good game design. But something like this you'll need to. I think it's better to actually put another conflict in. So another thing that you could do is you could make it so the speed of the player actually ramped up over time, and these are actually really easy things to do. So let's jump over to our place script, for example, and we got our place speed at 1500. But what if, um, every every single frame we just said Flair? Speed equals play a speed plus zero point one f. Let's just see, Go over to you, Nelly and press play. So right now our player is going along, but it'll gradually gets Foster and Foster and foster. The problem with this, though, is eventually it'll get so fast that, um, it will be unplayable, like, literally unplayable. But I'm not sure if you can tell. But things are actually getting faster and faster as we go on good way to tell is if you just look at the numbers at the top there. So even there, with that little bit of a speed improvement, I actually noticed a little bit of a difference in how the game felt again. Actually felt like all it's ramping up to something something's happening. But this actually won't work in the long run because obviously you'll get to us. But where players can't, um, get any better. So what you could do is you could wrap this an if statement. Just say, Well, if you play, speed is less than and you just pick it the Fossas amount. And then you increased the value only in that case, So that's just something somebody you can do. Another thing you could easily do is you could make it so, um, you could create an object, create three D sphere. Let's just go to the sphere forward. Give it a random and too, because we know it's curved. Let's just change the scale to be that of coin and obviously could get it to road rotate with some code. We've done this before because we could just sit this trigger here, and then we could have a tag and we could call it coin or something. They would come over to a school script. And we can say if other Garrett tag equals coin, then score plus plus or school plus five. Whatever you want to do. So things are really simple to actually in which going to delete that. But things are really simple. Um, to just adjust this game and make it a little bit better, Make a little bit fun. The other thing you could do is you could make a character select system. We just like different players with different colors. Um or, you know, completely different objects altogether. You could make it so you could collect invincibility, power ups and these impair apps. All that all they would do is, you'd say, um, you know, once you've got the invincibility power pair up than you can say, get components vehicle, Ida, um dot enabled equals true. And then it just stops you from being a big club with anything but that will mess with your score systems. So you come to the play a script and you could say something like here in here and go, you can say and so too ends Macon like it's a condition where both these things have to be true at the same time and is invincible equals false and you create a variable. A bullying cold is invincible, and that turns on when you're, you know when you've got the power up and then turns off when the power runs out. So these are just a little ways that will probably be overwhelming to deal with at the start. But once you start trying to implement them yourself, I know that you've got this base plain and you're not going to screw up anything. Maybe copy this project and dump it into another, um, area on your computer and then just play around things mess around. What happens if you had some coins? What if you want to do to spawn at random locations once again, if you feel like OK, I want I want to actually spawn Cem Random coins. We got objects born a script and you could create some more pre fabs and you could just see what what we've done here in the parts. Okay, so that spawned a triangle and it just well was sporting the triangles, um, at at our sport obstacle position does E plus 30 what we could do the same thing, but plus 15. And you could have it, you know, Exporter at random location. My point is that game development is tricky when you first start out, but the best way to get better is to try new things and see if you get them to work. And the best part about working inside of unity is you can go to Google, and you can just type in something as simple as how to make a coin magnet unity and you'll get a you know, yet 50. We get hundreds and hundreds of results where people have had this exact same discussion, trying to come up with a coin magnet, trying to come up with the invincibility, trying to come up with a colored characters select system, and you be able to find other people's scripts that they have. Let people just use or the discussed together and you be able to look through the code, and hopefully you'll have the skills to be able to take some of that code out and try it out on your game, and it may not work and it may work. But the grind is how you get better. If any of you guys are new programmers and you've gotten this fire in the course and you actually end up implementing new functionality, please, by all means somehow get in touch with me and show it to me. Send me a message over Twitter. You know, contact me however you want, and just show me what you've done. I really love to see the results besides that, join the conversation and let's discuss some cool features that we could add to this game in the next episode will touch on the final project Toddy up and the release settings See there. 40. Final Project Export Settings: Okay, so our game is pretty much complete, but we want to check the settings and just make sure everything is all good. So the first thing we want to do is we didn't just play a game and see if it works. Fine. Inside the inspector. It's plate for a little bit. Awesome. Never one to go over the console. We'll see our logs here. Okay, Claudia is working already. It was double click on that. I mean, it would not be appropriate script, and you will see a little debug. But look here, We don't need that anymore, so we can just delete it. It's just unnecessary overhead at this stage. If we're about to release press play again Awesome. So everything is working good. Fantastic. Then we want to actually go to our player and make sure we unm ute the theme song here. The audio source. Okay, so now we press play, we have out lovely music back. Awesome. So that works fun. Then we want to get a file build settings and we want to run in X Curtis release. Ah, in android. These settings will do just fine and we're gonna heat and go down to play a settings, we can set a company name, product name. We can build our default icon and default cursor if we want to, which I don't know will be necessary for mobile. We can set up our icons in here, I'll tell you that we wanted to explore one of the pixels of 1 20 piece, about 1 20 pixels, etcetera. You can go through these settings, deacons say. Well, I only wanted to be landscape. Our only wanted to work in portrait. We don't need to do work in port upside down or landscape writer landscaped left. And these will be a little bit different, depending on what, um, depending on if you're building for Android or for IOS, but basically they're all set up pretty well how you want them, font. I encourage you to go through these and check them out. Anyway, however, I sail this bunt when we export out of unity. So if I file build settings and I click build, it's got I'm just going to dump it onto the desktop in a photo called Build. It will take its time to actually build the project, but what's actually happening is there's not actually building the game that will work just perfectly inside of IOS or Android is actually building the IOS X Code project or the Android studio project. So what does that mean? Well, there's an old saying in game development that I think I invented. But basically, when I first started when I first created by a first game Galaxy Cube in 2014 I thought that once I explored out of unity, I could just easily upload it to the ah IOS app store, and everything would work just absolutely, perfectly and how wrong I waas There were tax form to need to fill out for Japan. There were certain certificates on it'll download. I needed to prove that my computer was a worthy computer and it on a little these specific things for Apple to get my app onto the APP store under the pay a fee of $150 Android, it was much easier. I just downloaded Andrew a studio open the Project Andrew, a studio. I followed the steps to complete things and, um then I just uploaded it, and within 24 hours it was there. So even if you don't get all the project settings perfect in this build. It's important that when you put your game over two x code or to Android Studio that you can adjust them there. Now that my project has built, I can open up and I can see that this is the actual project that I would open up inside of X Code now because I'm on a Windows computer, I'll need to actually open this inside of a Mac computer. And I'm not on my Mac at the moment. But if you haven't enjoyed, if you build an android, app would be every similar and you be able to just open up inside of Android Studio. So if you're on Android, I suggest typing in developer developer Android Studio inside of Google. It'll come toe page like this, and you'll just be able to download Android Studio and open up your project and full of the steps to get it on to the android store. There is an entire manual here that you can read that will help you go through this step by step process, and the same goes with X code here so you can download that if you're on a Mac and install your game on to your phone and start testing out to make sure everything works perfectly before uploading it to Apple or to Android. Now, why aren't I going through all these steps inside of this course? Well, because these steps change all the time. If I I've released two games on the IOS and have released two games on Android if I was to and I've got a lot of experience might make it messing around with these two companies. If I was to make create a new game and upload to these stalls right now, the first thing I would do is come here and start reading this. This, Ah, this manual here because they're always changing the standards and you can't really keep up . So the best thing I can suggest that you do is you come here and you read exactly what um, it's needs to be done. It's the admin part of game development. It's the boring part of game development. It's the frustrating part of game development. But once you get through this last little bit of fire, your game will be on the APP store or on the android store and you have a game that you've got to show your family and friends and say, Hey, I made that. How awesome is that? So all that's left down to do is the download X code download Android studio. Get your app working on a phone, tested out, make sure everything works and then follow the prompts sort of X code or Android studio and get your game on the store. Congratulations. Making it this far means you are now technically in any game developer because you have developed in indie game. I know it may not feel like it's your game because you followed two tutorial, but like I said, you can add your own a little bit of flavor and you're a little bit of things. But you now been able to see a project from start to finish and know exactly what goes into making a game. You gotta take these skills and the things that you've learned and the code that you have learned end the techniques that you've learned and put them into your own projects. Produce that you think up by yourself are looking forward to seeing what you guys do with this project and until next time 41. Thank You (this is not goodbye): congratulations for getting to the end of the course. You don't super well to get this fire, and I'm so glad you made it this far. If you end up making this game into something more amazing and just just crazy, then please send me a link of love. The check it out. And if you decide to take some of this code and you go on and you make something with some of the code that we've let, Mr Taurel also said to me, I love check that out as well. But until next time, check out youtube dot com slash Let's make a game together. Let's keep making some games together and, yeah, I'll see that. Thanks, guys bite.