무료 쉬운 게임 개발 강의 - 3시간만에 개발, 출시, 수익화까지 완성

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Anyone can easily learn how to create their own game, publish it on the Play Store, and monetize it with ads in just 3 hours. Hello. This is JoCoding. This video is about how to make a profitable Flappy Bird clone game that anyone can make. Let's begin the year 2022 version of the lecture First, a brief introduction to Flappy Bird. It's a very simple game made by a single developer, in which a bird attempts to fly between columns without hitting them. As this game gained popularity, it became famous for earning 50 million won a day and 1.6 billion won a month from advertising revenue alone. While learning to make this Flappy Bird clone game, you will also be learning the basics of game development. Some of you may have seen my lecture last year, but by adding some new updates and putting to consideration the parts that you found difficult according to your feedback, I have edited and re-shot a 2022 version of the lecture video. This lecture does not stop at teaching you to make Flappy Bird clone game. It teaches you the basics of game development, so you will be able to apply it on making a huge variety of games yourself just like these games submitted by my subscribers. Here is the table of contents for this lecture. You will be introduced to the game engine used for game development and learn how to install and set up the game engine, Unity. You will also learn how to develop a Flappy Bird clone game, launch it on the Google Play Store, and monetize it with Admob ads. In addition, in other lecture that follows, you will learn about marketing. After watching that lecture, you will learn how to develop, release, monetize, and market games, all the way to commercialization of games. First, please subscribe and like, and follow along to the end of the lecture to be able to create your very own game. Okay. Let's begin. First, I'll briefly introduce what a game engine is. To put it simply, a game engine is software designed to make game development easier. In the case of game development, it is usually necessary to apply gravity or make objects collide, such laws of physics are needed. But if you were to develop this one by one through coding, it would take a huge amount of time and effort. Right? However, these game engines provide something like a physics engine that enables you to command "Apply this law of physics" for immediate application of gravity and automatic calculation of collision, etc. It provides a variety of tools that make implementing the laws of physics extremely easy. You see a lot of moving animations like this in games, right? A game engine provides an easy way to create animations like this, and also provides a very easy way to add sound effects. In other words, it is a software that provides easy-to-use various tools needed to create games. In addition, the advantage of using a game engine is that it can be used not only for games for smartphones like we are planning to do today, but also for PC games running on Windows or Mac, games running on TV, games running on console devices such as PS or XBOX, VR games, and even games running on cars. Game engines make it easy to create games that can be used on multiple platforms. There are many different type of game engines. The two most commonly used game engines are Unity and UNREAL ENGINE. Unity can write code based on the C# language, and UNREAL can write code based on the C++ language. If we were to list the pros and cons of both game engines, the video will become too long. So let's skip that part. For a very simple 2D casual game like Flappy Bird that we're trying to develop, it's easier to use Unity, which is said to be lighter. Therefore, in this lecture, we will develop a game using the Unity game engine. Then let's install and configure the Unity engine together. Please watch the screen. Let's try installing Unity. Open your internet browser and type unity.com/kr/download in the address bar to open the website where you can download Unity. You can get started with Unity in three steps. First, download a program called Unity Hub. Second, select the Unity version from the Unity Hub. Third, install a specific version of Unity. Then we can begin our project. Let's download Unity Hub first. You can get the Unity Hub beta version here and the previous version here. It's still a beta version, but it looks like it will be an official version soon, so let's install what's here. Windows, Mac, or Linux. Download according to your operating system. I'm going to download Unity Hub for Windows. Open the downloaded Unity Hub installation file. Let's install. Agree, install. Installation is complete. Check "Run Unity Hub" and click "Finish". Unity Hub is now installed and running. We can now install a specific version of the Unity data. You can begin installing now, but let's click "Skip installation" for now so that I can explain to you about its configuration. First of all, you can install various versions of the Unity Editor in the Install tab of the Unity Hub. Before that, you must first activate your license. What license am I talking about? If a certain company uses Unity, they need to pay a certain fee via this subscription plan. However, for personal use, students and individuals can use it for free. So if you are using it for personal use, you need to activate your personal license. Let's go to license management first. If you do not have license activation, go to 'Settings' on the left and click on 'License'. Now, we need to log in. Let's try logging in to Unity. At this time, login is required to activate the license, but if you don't have an account, you can create a new ID. After logging in, this screen will appear again. Click add license. If it's for personal use, receive a free personal license from here and use it. Click here. In the case of an individual, the total annual sales must not exceed USD 100,000 or KRW 100 million. You can only use the personal plan if you haven't received more than $100,000 in investment. Let's agree and receive the license. After waiting a while in license management, I can see that a license has been added. License configuration is complete. Next, we need to install the editor. Before installing the editor, click 'Settings' to change the project path first. Your project path should be C:\Users in your current computer username. If this is in Korean, you will get a lot of errors. If there's Korean in your username, click this to create an English folder like this right under the C drive. Now everything is in English. See? You need to make an English folder like this in order to avoid errors. So, if you select this folder and the project is created in this location, there will be no error. After making this specification, close 'Settings'. Now we can install the editor. Click Install Editor. There are several versions of the Unity editor. We will try the long-term support LTS version. The LTS version means a stable and long-term support version. If you use a higher version or a pre-release version, you can use the latest features of Unity. However, it can be changed or omitted in the future, so if you want to release it stably, you should use the LTS version You can download the recommended version Or you can go to Archive and go to Archive Download to download various versions of Unity. Additionally, you can view only the long-term support LTS version by clicking here. In our video, the lecture was conducted using the 2020.3.18f1 version on the download page. Let's install this. But, you don't have to get the exact same version. The game we're trying to make is not a complicated game. In fact, no matter which version you use, the basic functions are the same. So you don't have to install the exact same version. You can just download and install any version of the 2020 official release. However, if you want to use the exact same version as the lecture, go to this address for the long-term support archive to download the specific version used in this lecture. To download this version, open it and click on Unity Hub. Then click on Open Unity Hub and a window will open where you can download the selected version. Let's try installing a specific version of Unity from here. At this time, we can additionally install various modules together with Unity. We can use the Visual Studio Code as the code editor. However, since there were many people who had difficulties using Visual Studio Code, I will also teach you how to develop using Visual Studio Community version which is heavier but also stable. So those of you who want something that's more stable should check this box. Go to Platform, and since we'll be developing an app for Android, click Android Build Support. Check Android SDK & NDK Tools and check OpenJDK. After all these are checked, click Continue. Agree to the terms and conditions and continue to agree to the terms and conditions. And click Install. If you close the window, you can see that the version we selected is being installed. Installation is complete. It says an error has occurred, but when I checked, it was installed just fine. Now that the installation is complete, go to the Project tab on the left and click New Project. You will then be able to select the editor version and template here. Since we are here to make a 2D game, let's select 2D Core and use this to create our project. If you scroll down, you can select the project name and location. Make sure to create the project name in English as well. Also, it should not start with a number like this. Names that start with English are required to avoid errors when building the app later. I'm going to name this project FlappyClone. Click Create Project. Now you can see that the project is being created like this. Once the creation is complete, the Unity project will begin to run. A message appears stating that a version update has occurred. If you want to use this version as is, just click Skip New Version and proceed. When the creation is complete, you can see that the new Unity project has been executed like this. Next, we will download the images that will be used to create the game. Open your browser and type animalface.site/flappy in the address bar. I have uploaded the images to be used in this lecture for you to download. I will leave the address on the main text and the comment. You will be able to see all the images in this page. Right-click on it and click Save Image As to save the images to the path of your choice By default, Unity projects can be found by entering the username and project name in Users in C drive. Here, we will save the image file inside Assets. Saving complete. And when you return to the Unity project, you will see that the image we downloaded is placed inside the Assets folder. If you double-click the image, you can see that several game elements are included in one image. Since there are usually so many game elements, there are many cases where several game elements are contained in one image like this. So we have to separate them one by one. To do that, click on the image in Unity. In the inspector window on the right you will see that the current sprite mode is in single. Click it to change it to multiple. Then click the sprite editor below and click Apply. Then click on the Slice menu at the top and press the Slice button. You will be able to see the game elements being separated one by one by a white line. If there is an error in the separation process, just click the image and adjust the blue line like this to edit the area where the image is divided. After checking that the game elements have been sliced properly press Apply at the top. When you close the window and click the arrow on Assets, you will be able to see that each game element has been separated properly one by one. If you get an error when you click the sprite editor, you need to go to the Windows package manager and install a package called 2D sprite If it's not installed, click the Install button here to install it. Now if you try clicking this again, it will work fine. And if the image comes out too blurry after slicing, apply the filter mode of the image as point (no filter) and change the Compression, from normal quality to none. Since the image is no longer compressed, it will become less blurry. Now click Apply. The image size will be slightly larger, but the image will not be broken. Now that the image we need is ready, let's begin making the game in earnest. Before that, let me explain the overall screen configuration of Unity. There's a tab below called Project. Like when we checked for the added images earlier, This provides you with a search engine that allows you to click on the folders to check the files inside. Just like Windows Explorer. Above that, you will see something called 'Scene'. You know scene? As in movie scenes? That scene. Like in movies, such images in games are also called scenes. You can see that a camera is installed here, right? If the image is outside the camera, it won't show on the game. If it is inside the camera, you will be able to see that scene in the game. And see this 'Hierarchy' on the left? Things that are included in the scene are called Objects. All images, game characters, and everything that appears on the screen are called Objects. Let me add an Object to show it to you. Let's add these game images and background images to the scene. When I drag this image and drop it into the scene, it comes out like this. Now look at 'Hierarchy' again. Originally, there was only a camera in the sample scene. but now a new object called img_0 has been added. This is what you call an Object. You will be able to see that a new Object has been added. If this was a movie, and this is a scene of a movie, all the characters and things appearing in the scene are called Objects. And you can move these objects around in this scene. Then, since it's the background, I'll place it in the center. Now check the Inspector Window on the right. We've used it earlier, remember? The inspector window is a tab where you can adjust the properties of each object when it is selected. So, to center the position here, I will change this to 0 0. Now you can see that this background image object has been positioned at 0, 0 center. After you have placed the background, look at the main camera. If the camera is shown like this, it means that the actual game screen will come out like this. Now, there shouldn't be any empty spaces like this in an actual game. Right? Since we will be playing the game in vertical position, let's change the composition of this camera. To do that, there's a tab called 'Game' next to 'Scene'. In the game tab, you can see the part of the scene that the camera is showing, which is the part that will be seen on the actual game. You can see that it's cropped, right? Then let's adjust the ratio of this to fit the vertical length of the smartphone. To do that, I usually need to look at the 'Scene' and the 'Game' at the same time. So I'm going to cut out this 'Game' tab and paste it to one side. Then I can look at it together with 'Scene'. Let's adjust the windows so that they occupy half and half. Now, let's adjust the game screen to the smartphone's vertical ratio. To do this, click on 'Free Aspect' at the top and adjust the aspect ratio from there. Since everything is horizontal, I will create a new aspect ratio by clicking the plus button at the bottom. Label it Mobile. Set the Type to Aspect Ratio, and set the ratio to 9:16. That is the smartphone vertical ratio. Click OK. Now you can see the white border of the camera in a 9:16 mobile ratio. See? It has changed to 9:16 ratio. And you can see that the actual game screen is also cropped at the 9:16 ratio. However, in this case, the entire background will not be shown. It will be cropped. Of course, you can make it like this, but if you want to show the entire background you've created Select 'Camera'. You can select it here. Drag it and match the background to the camera. Now the background objects are filled perfectly inside the camera. Match it like this and press Control S to save it. You will notice that there was a star here before, but now it has disappeared. When you make something, get into the habit of saving it. Make sure to save periodically and obsessively to prevent losing your creations. And in this scene, the background image we added, this object is currently named img_0, so it can be a bit difficult to distinguish. So, I'll right-click on it and Rename it as Background. It's a background object. Now, I'm going to add a bird. I will bring an image of a bird and add it to the game screen. If you add it like this to the scene, it will appear inside the camera and appear on the game screen. If it goes outside the camera, it disappears. Now, back inside the camera, and it's back in the game. This bird is added here as an object named img_3. I'm going to right-click and rename this as Bird. However, there is not only one image of this bird, but there are several like this. The reason why we have so many images is because most games are animated. And by showing these pictures sequentially, we can create a flapping effect. To add such an animation, since there is no animation window currently, we need to press 'Window' to add a new window. Scroll down to 'Animation' and click it. Now you will be able to see the animation window. Let's place it. I've placed it next to this tab called 'Console'. The console is mainly used for taking logs and debugging while coding. I'll explain this later as I use it. First, let's make an animation. Select this Object called Bird. Next press the 'Create' button here to make an animation. Now you can create an animation like this and save it. I'm going to save it as BirdFly. When you click Save, the animation is saved and a certain timeline is created. Now, I'm going to take this out and paste it over here. Go to 'Project' and select the images you need for the animation drag and drop them here. You will be able to see 3 diamond-shaped images inside the box. If you zoom in, you will see that each dot is an image. Click the arrow on the left Then you can check the actual image too. Here, if you press your space button, it runs And you can see how the image of the bird flapping is added in the game screen. But the flapping image is too fast, right? So to make it slower, make it wider here. To make the gap wider, select all for the diamond And extend this and you can see the seconds are being extended. Let's extend this gap. You can use the mouse wheel for zooming in And zooming out. So after some extending job, press space to play again And the bird is flapping, but in an unnatural way. The reason is, here, the image spreads out here, Down, the wing is facing down, right? So after it comes to the center, to the top, It goes right to the bottom, which makes it awkward. So to resolve this, it should go up and then reach the center Before going down, right? So copy and paste one more of this. Ctrl C, Ctrl V then this is what you get, right? Drag this in and get it in with the uniform length. Uniform, right? So it goes to the center and then the bottom And you need the same interval for that So I'll copy the final image once more To put it in the same interval. So, the wing facing down, center and up And then center before down, it's more natural-looking, right? Press the space key to run, and you can see that The flapping looks more natural here. And since this looks a bit too slow, let's speed it up Let's select all and reduce the interval a bit. Keep it to around 0.21 and when you play The flapping looks alright now, right? So that's how you complete the animation. Since the animation is applied to the Bird object here To check if it actually works Play here And sometimes you may not see it even when you play it. The reason is, look at the inspector section of background And one of the properties of background says 'order in layer' Meaning the order of the layers Since this is 0 and the Bird object is also 0 So it doesn't know what comes first Which keeps the background first, above the bird. To fix this, I'll increase the order of the bird by one. Bird's order, 1, change it like that And the bird comes before this And since the background is behind this, you can see it's the way we want. Set it up like this, play to check And now we see the bird flapping in front. Here's what we've been doing: add the image objects to the scene Adjust the property, add the bird image, add the object, And add the animation. But we have no coding whatsoever, right? This is the strength of Unity. Unity has all the UI for adding basic objects, Changing the properties or animations It provides the UI for those So you don't need coding for them. So like this, Unity provides Many convenient features for game development. Next let's add the ground image. Drag the ground to the scene and you get the ground added. Below the scene, the ground object is added with the name 'image_1' Right click, rename it to 'ground' And here we have the ground When we play it, the ground disappears again, right? This is because its order has not been set Ground's order in layer should be bigger than this bird, So let's use 2. Then the ground is above the background, right? Play to run, and we can see the bird flying And the ground right there. But like this, the bird is moving with the animation But since the ground is not moving, the flying doesn't seem too real, right? So to make it look like it's moving, click on the ground And extend the length. But it will just keep extending like this. To undo the mistake Use Ctrl Z to undo. Then click on the ground object, of its property you can adjust the 'draw mode' on the inspector Change the 'draw mode' from 'simple' to 'tiled' When you extend this, it's not like it just gets extended straightly, it is in type format. There is this regularity maintained and you can see that it is getting extended like a tile. So to give an effect to make it look like the bird is moving forward, if you look at the game screen, If the ground down looks like it's going backward The bird will look like it's moving forward, right? So, let's add that animation. So keep the ground here, same thing, select the ground object Select 'create' at the animation window To make that animation. So now, let's make that 'ground move' animation and save. Then, to make the animation move the ground backward Press this red record-like button on animation, Move the ground, so the movement I'm making is recorded Into this timeline. Try moving it like this, The diamond shaped one, it's called keyframe And you can see the keyframe being added. Click to open, then positions x and y, You can see the axis. When you move this, it's recording in form of keyframe. It begins like this And when it ends here it's not too natural, right? When this rectangle begins. So let's go to around 3 seconds in Drag this and set it here Then after the recording, press space key to run And it moves like this It looks a bit unnatural, right? The ground moved slowly at first, got faster And then slow again, it looks pretty weird. To resolve this issue, select, right click, bottom most saying 'Both tangents' click and select 'linear' And you can see the animation with the same interval. This looks natural, right? It's a bit slow, so let's reduce this by a bit. You can see the ground moving naturally. To see it with the bird moving, first save And click on this 'play' button on top to run the game The bird's flapping, the ground moving backwards It looks like the bird is actually moving. Now, we only have the effect of The bird uniformly flying at one point. But this shouldn't happen at the game, right? We need the gravity on the bird, the bird falling down, And when we tap the screen the bird should jump, jump. To do that, we need gravity on this bird object, right? So let's add that gravity. Left side, hierarchy, bird. Select the bird object and the bird is selected. Let's first move it to the center. x and y as 0, to keep it right in the middle. And at this Inspector, not only the location properties But also new properties can be added. Down here, this animator, the animation we added, It's added as the property of this bird's inspector area And you can add new property with 'add component' Gravity too, we already have the pre-made component for that We don't need to code to calculate the gravity to apply to the bird. We can do that right away so that it falls. How do we do it? Add component, Physics 2D. Inside Physics 2D, apply 'Rigidbody 2D' And this object, the bird object with the Rigidbody 2D applied, It is under gravity now. So save that, and play And you see the bird under the gravity, falling down. Isn't it great? Like this, you can add gravity to the bird simply by 'add component' And adding this 'Rigidbody 2D' without any complication. Imagine doing this with coding, it'll be so complicated, right? But using Unity Engine, the good thing is to really easily Add physical features only by adding components. But the bird shouldn't keep falling down. We can make it stop when it hits the ground. Let's do that. It can also be done with the Unity-provided physics engine. Same thing, select the bird object, property, Add component again, Same thing, in Physics 2D Let's make the collider named Capsule Collider. Collider is, now we get a boundary here. Drag the mouse wheel to zoom in Selecting this capsule collider component You see the green circle here? That's the range of the physical hit. The physical thing is applied within that boundary. Meaning, we should set the physical boundary around the bird's shape, right? Then, keep the direction horizontal Click on Edit Collider And it is already set perfectly. We can extend it like this. If we make it fit the bird's shape as much as possible, The law of physics would get applied better, right? Set the boundary. Same thing, you apply the collider on the ground So that when the object hits the ground object It doesn't move anymore. To do that, select ground object Add component, same thing, Physics 2D Select the collider, since it looks rectangular I used Box Collider 2D component. And you see the green area here, right? But it should match the ground surface To do this, of course you can use Edit Collider again But checking on this Auto Tilting You can see the green line extending according to the box size. Then, between the things with the colliders It's like the physical hit in reality It no longer falls down, it just hits. Let's run it to check. Save with Ctrl S and run with the play button The bird falls and it just Sticks on the ground after the hit. Until now we've done: Add the image to the scene, make object Change the property, change the location, add the animation, Add collider things like Rigidbody 2D And add physics law. We used 0 coding whatsoever. Since Unity provides a lot of basic features We can do many things here without coding. But one new thing we need is, when we touch the screen The bird should jump up. But this feature is hard to run with the basic Unity function We will be typing our code to add our code To the object. To do that, select the bird object, below RigidBody 2D Collider 2D, this feature, Just like we added with add component, Let's add this code we need on this bird with Component. Click on Add Component, there will be many properties But to add our own, Click on New Script at the bottommost You can add the script we made as the property of the bird object. So let's name the script. I'll name it 'Bird Jump' And 'Create and Add' The script called Bird Jump It's added like RigidBody and Collider, so it's added as the component. Now, into this empty script called Bird Jump Let's write in the actual codes. Before that, let's select what code editor to use to edit the code Unity, select Edit Preference. in between there, select External Tools And External Script Editor Click on that and you can select the editor to use for editing the code. Visual Studio Code, if you listened to my class You'll be now very used to it. You can use this, but many of you can't get the autocomplete with this So if you want the stable use for it Use the Visual Studio Community Version For the more stable autocomplete features. So let me show you how to click on and use this Community. Close. And double click on the script And you get the Visual Studio. You could log in and use it. Or 'log in later' to use it without logging in. Select the theme you want, click on start. Community Version needs a log-in to use it for free. Let's log in. I've logged in. So I can use it, let's close. And inside the solution search, inside the assets folder You can see the Bird Jump script we made. Here, the autocomplete, Even if it didn't work for you at Virtual Studio Code It's working well here. If the autocomplete doesn't work, go to control panel, remove programs And you can see the Visual Studio Community installed here. Click on 'Change' And you can change the setting to Visual Studio Community. Scroll down, and game, 'Game development using Unity' Please make sure that this is checked and installed. If not, you should check it and install it. But Visual Studio is pretty heavy So some of you may want to use Visual Studio Code. Let's see how to set Visual Studio Code. You can use either of the two, your preferred one. Same thing, Edit, Preference, Instead of Visual Studio Community, choose Visual Studio Code How to set the Visual Studio Code Is there in the Settings video from before. Close the window. And run the Bird Jump script And you see the Visual Studio Code here. Click on 'Yes, I trust others' And the folder opens up here. The good thing about using Visual Studio Code is, It's basically connected to Visual Studio Visual Studio takes a long time to run when you click on it. So let's go to a lighter one, Visual Studio Code. But to use Visual Studio Code You need a few extensions installed. V5 Code screen, to your left, click on this block-shaped icon To install the Extension. Basically, it says 'Do you want to install C# Extension?' You get this, you can install this Or you can search it from the market to install. So let's install the extensions we need. We need around 4. C#, Visual Studio Code It has the extension to be able to use the C#-related grammar Install this. Installation complete. Then, search at Unity And we get Debugger for Unity. Let's install that as well. It provides the debugging feature related to Unity. Next, select this Unity Tools And install this by clicking on this. Next, there's Unity Code snippets This is an extension that autocompletes the Frequently used Unity Codes. So C# and three Unity series, install these And you can develop at Unity much more efficiently. Unity, you must've learned with that basic extension installation, It's been using the language C#. But even if you're new to C# language You don't need to be scared Because most programming languages are basically the same. So if you've learned about any language before, Variables, conditional statements, loops, functions, classes, You must've learned about these These exist in all languages. There are some minor differences like how to use them But overall it's all the same. So if you've studied more than one basic programming language You can follow along easily. If you have listened to my class on Python, which I filmed before, I will explain it so that you won't have difficulty in following the class. Since we've installed many extensions, there may be errors So let's turn the VS code off and double click on the Bird Jump script To turn it on again. The extensions from before, it must be all applied well, right? But it says it's downloading something. Let's wait for that to finish. Yes, after a while the installation is complete, looking at the warning message here It says that .NET Core SDK can't be debugged So let's do 'get the .NET Core SDK' here. So like this, it can install .NET SDK Let's install that. Download the installer And we're able to install that SDK that it needs. Close it again, double click on Bird Jump script To run the VS Code. As soon as it's on, it says Select Project We've been working on the project called Flappy Clone, right? Select that. We still get this.. Saying .NET framework v4.7 is not installed. It says go to this link to install that So let's copy and paste this. We'll download that 4.7.1 thing. Download that Developer Pack. It's all installed. Let's close it and open it again. After opening it again, we can see that it's all working fine. So let's see what the codes written here mean. To zoom in the text, 'Ctrl +' To zoom in the text. Let's see what the codes written here mean. Starting with the first 'using' construction, It's like 'import' at Python It's the expression used to import the external module or library. In other words, the Unity Engine modules or collections used at Unity, these things are brought, It can be thought as typical codes that we import from Python libraries So we imported all the necessary modules and inside the modules, we have classes In C#, the classes are organized like this We created a script called BirdJump, right? The script is created as a class by default The line behind the colon is the succeeded class In other words, BirdJump will succeed MonoBehaviour, but you don't need to know that much in depth. Just think that this class is not a class without anything, but it's a class that succeeds from the class that has many different functions called MonoBehaviour, so you just need to know that it has a lot of basic functions The class has 2 kinds of functions They are the start function and the update function The function of each code, for 'start', when the code starts running, the code that only runs once goes here and for 'update' the code that runs in every frame in the game goes here. It may be the first time hearing the term frame for some people. In simple terms, when we watch a video clip or an animation, for example when we watch an animation where a person is walking like this, it looks like the person is walking, but it's actually a connected clip of single images that are slightly different from each other. In other words, we are not watching a video, but rather images that pass by really quickly. So you might have heard of the unit called fps fps is the abbreviation of frame per second which indicates how many frames pass by on the screen per second In other words, if a video is 24 fps, then 24 images pass by in one second. In other words we have 24 of these images that passes by in 1 second 30fps would be 30 images in 1 second, 60fps is 60 images per second Getting back to the code, I've mentioned that the update function is run in every frame, and games, too, have the concept of frames just like a video clip A game with 60fps means that 60 images pass by in 1 second on the game screen Therefore, in the case of this update function, 60 images per second This syntax is run To summarize it again, 'start' is for once at the very beginning, and 'update' runs in every frame. Let's check if that's really the case. Let's just simply look at the print. When you want to print a simple sentence using C# in Unity, you can use the function debug.log You can write in the message that you want to print in the parenthesis Write "" (quotation marks) in the parenthesis, and let's write a phrase like "It's the start" It works the same way as how we print for Python or or console.log for JavaScript. You can test out simple things using debug.log in C# Unity You can copy this and paste it in update Let's type in "It's an update" and save the file If we check how this code is run, let's lower the window and press the play button The game is run, and if you click on the console tab, you can see that there are many rows with "It's an update" You can stop the game and if we look at the top we can see the message "It's the start" Then we can see the rows of "It's an update" So, for each second that passes by in this game, the update is consistently run according to fps, and start is only run in the beginning Okay so we looked at the overall flow of the codes of C# script in Unity If you create the script, this is what it would look like If you input start, update, or other codes that you want to use, the codes will be reflected in the object, so the start will be run once and the update will be run in each frame So we looked at the basic flow of Unity script, so let's write the code for the jump If you come back to Unity, we are going to put in the jump function as a script to the bird object We already added the rigidbody2D attribute to the bird object so it's good for us. After adding rigidbody2D, the gravity dragged the bird down, right? So there are a lot of physical elements in rigidbody2D We can make the jump function easily using rigidbody2D In other words, we are going to import rigidbody2D from the script We can execute the jump function To do that, let's code it We need to import the rigidbody2D component from the bird, and we are going to give it a jump function First, let's create a variable that we can assign rigidbody2D to When we create a variable on C#, unlike Python, we need to write the type of the data in the front and then right the variable For example, on Python, you would just need to write 'num=1,' On C#, we need to write 'int num=1' and we also need to add ; at the end to indicate that's the end of the sentence So, we need to write the type of the data, write the name of the variable, then we can assign a sign to it, or we can just leave it like this if we were to just declare it. As such, the data type with rigidbody2D class, having class means that it is that data type. If I show you, rigid, it's auto completed right? I will import rigidbody2D data type, create rb variable, and declare it for now rb is the variable that refers to rigidbody2D In other words, the data type of the variable, 'int num' means that it's a box called num that can include int If we named the variable rigidbody2D rb, then the box rb now can contain the items that are of the rigidbody2D class We created rb that could include rigidbody2D, let's write the code that puts rigidbody2D component in rb in the beginning, when it starts. To bring a component to rb, we can use get component It's auto completed here, right? Use the square bracket after get component, open and close parenthesis, and write the name of the component inside the square brackets We are going to import rigidbody2D, and you can just tab for auto complete This means that we are going to import the component named rigidbody2D into rb Since we imported the component, now we are going to work on update Update runs in every frame, so we can make it jump when the screen is tapped So, we will use if phrase If you don't know how to use it, don't worry, it will be autocompleted If you press tab, then it will automatically fill out how if phrase is used In Python, it was : and then the phrase below, right? In C#, we can type in the syntax for true and false inside the parenthesis and in the middle parenthesis, we can write that the code inside will be run when if is true The mechanism is not different, right? So for the if phrase, when we click, when we touch, Unity considers both mouse click and smartphone touch the same for testing purposes in mobile and computer. Input inside if phrase input.getmouse, it's autocomplete like this, right? There's getmousebutton down, up when you want to check what happens when you press the button, you can use getmousebutton down. You can open and close the parenthesis to sense the click, and insert 0, which becomes the left mouse button We need to make it jump when the left button is clicked, right? To make it jump we are going to bring in the physical component from rigidbody2D called rb.velocity. Velocity is an element that shows the speed We need the direction of force to be upward, so there's vector 2, and when we write vector2.up, vector2 indicates (0,1) Some of you may see this for the first time. Vector is like coordinates that could be defined with a comma Vector 2 is a 2 dimensional coordinate with (x,y) Vector 3 is (x,y,z) but since we are making a 2D game, if we use vector2, we can indicate it as (xy,y) vector2.up is (0,1) If we multiply a number to (0,1) like number 1, the numbers get multiplied and becomes (0,3). If we input the velocity that we got from rigidbody2D to (0,3) it will have a velocity of 3 in upward direction, y So we can give the jump effect to the bird Unlike Python, we need to use semicolon at the end to complete a syntax in C# To summarize, we use physical component in rigidbody2D to make the bird jump First we need to create a variable with a class to import rigidbody2D We created rb variable, and at the beginning, when it starts, we used getcomponent with rb variable, and assigned rigidbody2D component to rb variable Next, we used if getmousebutton down. When the mouse button is clicked, which is the same as touching the screen, when the mouse is clicked, every frame, we can see this update in every frame, right? So we check if the mouse button has been clicked in every frame, and if clicked, we use the velocity inside rb, using the velocity component in rigidbody2D, set the speed with vector2.up, in the upward direction by 3 to make the bird jump It may be confusing at first, but since it's a frequently used concept, creating variables to assign components to, and using that component, I think you should remember that flow. Let's use ctrl S to save the project periodically. As I have emphasized in other lectures, if you understand the bigger flow for such codes, you don't need to memorize the detailed parts It's because if you just remember that you need to import rigidbody2D to make it jump, you can just search on google like this, on the engine you are using, framework, and language, and what you want to do with it, then you will find a lot of pages that tell you how to make it jump using rigidbody2D There are other ways to do this without using exactly what I did, If we pick one, there's a question I want to make my 2D character jump There are a lot of questions and answers like this on Unity official community This is the great part about Unity It's a commonly used 2nd gen game engine There are so many questions and responses, and there are codes you can refer to on Google. You can just pick one and use it There was a question if you should use rigidbody2D for jumps, there was a response that you can do it this way Bring velocity from rigidbody2D and use vector2 It says it here, vector2.up is the same as (0,1) that I've mentioned We multiplied 3, but you can also use jumpforce, using a specific float value and use it as a variable format If you refer to what other people did, you don't have to memorize the specific codes. You can just search for the overall flow, and you can find writings in other communities and see how the codes have been written. You can pick out the parts you want to know and use them for yourself. If you're not just going to be making Flappy Bird, and if you want to make other games, you just need to have an understanding of the bigger flow, on how to bring a component and what to do there. You will find a lot of codes you can refer to on Google. Get in the habit of searching for the codes and use them Let's save and do a little experiment Come back to Unity, bring the script and play You can see that the bird is jumping when you click the left mouse button But if you feel that the jump is too small and want the jump to be higher, you can just adjust this number, right? Let's stop and we gave the upward direction number 3 before But we can create a variable like we saw on Google, and that might be actually more comfortable to work with Float. This is a number type with decimal places Let's create a variable called jumppower and put it here Of the variables used in this class, there is nothing to it right now. But if we write public in the front, public is a concept of access modifier It will be familiar if you've studied Java before In Python, we don't really use access modifier The explanation might get too long, so to be brief, if we don't attach anything to it, then outside access, access from other classes to jumppower is not possible and if we put public, then as the word explains, it will be open If we save this and go back to Unity, we can see that there is now the variable jumppower in the script component, and we can see the number 0 In other words, variables that have been granted public, can not only be defined with a number in the editor, but in Unity editor, outside of the code editor the jumppower can be accessed. Let's give it 3.5 If we save and execute the code, jumppower has gotten a bit higher with 3.5 If we increase it even more we can see that the jump is really high. Like this, if we use public, we can adjust the number directly on Unity editor which makes it more direct and faster in adjusting the values. I think 3.5 was just about right, so I'll set it to 3.5 You can change this value to whatever number you want Let's save Then we execute, we can see that the bird can jump We also need to test if this works on our smartphones There are two ways to run a game created on Unity on a smartphone You can USB debug it by connecting it to PC via USB, or you can create an APK file, download and install the file on the phone We will use the simpler method, which is using the USB to debug it Turn on the Android smartphone, go into settings, go into Software Information on the Phone Information Tab, at the bottommost, Then there's a number called Build Number in the information Keep tapping it, around 10 times, you will get a popup message that the developer's mode has been turned on Go back, and go back to the front screen, go all the way down, and you will see a new menu called Developer Option Go in here At the bottom, you will see USB debugging If you turn it on, you can connect it directly to Unity and run the app Turn it on, connect it to PC using USB cable, and you will get this popup screen, click it, select transfer file for USB usage purpose, and if you get another screen asking 'Will you allow USB Debugging' you can click allow access. After connecting it via USB, drag the sample scene, the one we created and put it in the scene folder in assets Then in the folder, you will get the file Then let's go into build settings So the default is set to PC Mac, and we can change the name, but make sure you've selected the sample scene, and click Android because we are going to run it on an Android device Then on the computer, it will say the device is installing. connect the Android device, click switch platforms at the bottom Then the Unity logo, PC Mac has now been changed to Android The currently connected device, it says Samsung Android Drive Error, from developer Samsung website you can download the Android USB driver. Let's install it. I will leave the address in the main text and the comment Close it and if you connect it again, you won't get any errors and it will work properly Then you will get another popup on the phone asking for access to the phone data, allow it and also allow USB debugging Click build and run below Then you will be asked to select a location to save Android app file, APK app file, and you can save it where you want I will save it in the background I will save it using the title 'JoCoding Flappy' Save it, and the app will automatically be installed. If you run it, you can play the game that we created on Unity, through smartphone If you can't connect it via USB, you can just click build save APK file You can send the APK file to your phone via email or whatever way possible, move the file over to the smartphone and open the APK file You can install it and execute it If we review what we talked about last time, we went over how to download image to Assets folder, categorize the images, and we added each image to Scene as Objects We also added animation, added gravity with Rigidbody2D and we added the script we made to the bird so that it can fly when we click it If we play here, the bird drops, but when we click it, it jumps up to here. Then let's create the obstacle that the bird can dodge as it flies To do that, let's drag the pipe image to the Scene from Assets We can see that Object has been added on the left But the size is a bit too small, so let's enlarge it If we drag it from the end, the image is now unclear In that case, if we press Shift and drag it, we can enlarge it while maintaining the ratio But this will be too easy for the bird to go over Let's copy it and create one more Click Object, Ctrl+C, Ctrl+V, we get another one at the same spot Let's click it and move it up, but if we press Shift, we can move it up without moving it to the side Let's drag it up and create a small gap for the bird to go through Let's make that but the shape of the pipe is a bit weird right now There's the protruding part at the end, and it feels like it should be here It's upside down so let's rotate it There's a Rotation option in Transform on Inspector tab You can rotate it around X axis, Y axis, or Z axis, and when you rotate it like this, you can rotate it around Z axis If you write 180 here, the pipe will be rotated 180 degrees, and the head part will be now at the bottom You can see the shape But if you just make it like this, it's useless, and it needs to move left Both of them needs to go together so let's group them together to manage them as a single Object To do that, right click on Hierarchy tab, and click Create Empty Then create an empty Object called Pipe The empty object doesn't have anything and it only has the Transform location value So if you move this, you can see it move in Scene Let's move it here, and click the 2 Pipe images with Shift+Click drag this and put it inside Pipe Then both pipes will be in the Object called Pipe You can see that they are grouped as a single Object called Pipe If we move the location of the Pipe you can see that the pipes move together When you move the position, sometimes it will be moved to the back It's because the Order in Layer of the images in the Pipe are set to 0 The background is 0, the bird is 1, and the ground is 2 The Pipe and Bird should be the same, in front of the background and behind the ground so that it could move normally We need to change Order in Layer of both pipes to 1 Save the file and when we move Position, we can see it moves normally like this Let's set the Pipe to move left automatically when we play the game There's a component called Transform inside Inspector of Pipe Click the component of X coordinate in Position, and if we change the number, it moves left like this In other words, we shouldn't do this with the mouse, but create a code like how we created the code to make the bird jump, and if we add the code to change the X value of the Position and let the position change according to time, we can make the Pipe move left Let's add the script Likewise with the bird, click Add component, click New script, and create a new script Let's create a script called Move Click Create and Add Then the Pipe component has been add to the script called Move If we revise the code, double click Move, it will be opened on Virtual Studio Code Then Start will only be run once, so we can create the code to change X coordinate by bringing Transform into Update, which is run every frame In BirdJump, we imported Rigidbody2D component with GetComponent to use the component, but in Move, we need to import component called Transform This is a component that is included by default, so we can import it without using Get Component To do that, you can just write Transform and you can bring Transform from Object There's another element called .position You can change the coordinate here If you import position, when we try it, we can assign position using Debug.Log Save the game and run the game. You can see the coordinates in the Console window If you pause it, we have three coordinates. 4.8, 1.0, -7.0 This is because the Transform displays up to first decimal place, and you can see it show like this X and Y axes are shown as default and Z axis is only for 3D games, so it's pointless here Let's just set it to 0 Then if we run it again, we see 4.8, 1.0, 0 This brings Transform component and prints it Let's change the X axis here When we created BirdJump last time, we brought Rigidbody2D component and also imported velocity component and added Vector2.up Vector2.up is 0,1 and when the jump power is 3, it was 0,3 Rigidbody2D only has 2 coordinates because this is a 2D game, but Transform includes Z coordinate as well So this uses Vector3 So we will have 3 pairs of numbers for Vector3 Here, it means bring transform.position and if we use +=, it adds the value on the right to transform.position, and saves the result If you are familiar with Python or JavaScript, Java, such languages, you will know this If we use Vector3 here, there will be three coordinates and the autocomplete will show like this If we use .left, internally it will mean -1,0,0. If we add this 4 times, the position will be changed once to the left in every frame But there's a problem if we use it like this In the case of Update function, as I explained before, it runs once in every frame The frame is not the same in every game and according to the specs of the computer or smartphone, FPS might differ For example, on some computers, it might be 6FPS, and if on another computer it's 3FPS, even if it's the same game, if there's a code in the Update function that the bullet will move right by 1m, the Update function will be run 6 times on the 6FPS computer and the bullet will move 6m per second But in the 3FPS computer, if the same code is run, it only moves 3 frames, which is 3m per second Then when the two players play the same game, the 3FPS player will be at a disadvantage We can't let that happen, so we need to normalize them In Unity, to adjust this phenomenon, Time.delta Time is provided delta Time signifies the time that the previous frame took to be complete How this is used is, as before, there's a computer that runs on 6FPS and another computer with 3FPS, it multiplies delta Time to the Update function When delta Time is multiplied to each, what happens is 6FPS moves 6 frames per second, so the delta Time, time it took for the frame to be moved is 1/6 seconds In 3FPS, it's 3 frames per second so delta Time is 1/3 seconds If we multiply each of them, if we multiply delta Time to 6FPS or 3FPS computers, it's 6m *1/6 and it becomes 1m per second Then in 3FPS computer, it moved 3m per second When we multiply delta time, which is 1/3, it moves 1m per second as well So if we have multiple computers with different frames, by multiplying delta Time, we can make them the same even if the FPS is different As I've explained Update function can make the moving distance different for FPS, so to adjust for that, we put in * Time.delta Time Then in any FPS environment, it will be adjusted and the same distance will be traveled in the same time Let's run the game after doing that Save the game and run the game Then we can see that the Pipe is moving properly We can see the coordinates change as well But it seems the speed is too slow In that case, as we learned, create a speed variable in float type called public float speed make it public, and multiply speed Then it will move faster to the left by the amount of speed Then we made speed public, by changing the values, we can adjust the speed Let's input 1.5 and save it. If we run the game, we can see that it's 1.5 times faster So according to the difficulty of the game that you're trying to make, you can adjust this value and play it But now, even if the bird hits the pipe, it passes by So to make it crash into the wall, select pipe Object like how we did to the ground, add Physics2D - Box Collider 2D with Add component. Then, we can see that Box Collider has been added Do the same to the above pipe If we add Box Collider 2D in Physics2D, we can see that the Collider has been created and when the bird crashes into it, we can see it crash into it because of Collider So until now, we created Pipe Object, put in the two pipes, and made it move left, then made collision possible. If we only create one Pipe Object, when we run the game, the Pipe object will only pass by once, so that won't be a game. We need to make multiple number of the Pipes to appear according to time for it to be a real Flappy Bird game. To make that, you need to understand the concept of Prefab Prefab is not unique to Unity, and it's used in architecture as well It refers to creating all the parts at the factory and assemble it on site Likewise, in the game, certain Object is used multiple times If we register it as prefab, we can continue to produce it Prefab creates an Object, and in this case, register Objects like the marine, create it as Prefab, and through Generator, we create multiples of the Prefab Then the registered Prefab and the Objects will be created as Objects with the same attributes Now we know what a Prefab is, we can create the Pipe Object as Prefab and duplicate the object Before that, in the Move code, we wrote Debug.Log for debugging but it might get messy if this continues to be printed, so let's delete it Save the file It's simple to make Pipe Object into Prefab Click Pipe Object, drag it and add it into Assets folder We get Pipe and a file called Pipe.prefab In other words, if we drag Game Object into Assets folder, it will be automatically converted to Prefab Then if you look inside Hierarchy, unlike the others, Prefab will be colored in hexahedron shape with blue This is an indicator of Prefab So we saved it as Prefab already, so you can delete this If you drag Prefab into Hierarchy again, you can add Prefab and you can see that the same shape is created Since we created Prefab, let's create Generator that duplicates the Prefab Right click on Hierarchy, click Create Empty, and create Empty Object called PipeGenerator Then we have an empty Object Then in Inspector screen, let's add Generator script Click Add component, click New script and add a new script called MakePipe Add the name of the script, and click Create and Add Then we have a new script in PipeGenerator Let's write the code that duplicates Prefab Pipe Double click on MakePipe Duplicating Prefab is really simple. First, get GameObject with public variable, and assign it to pipe variable Then if it's assigned to public variable, as I've mentioned we can go to Unity and check MakePipe script in PipeGenerator You can see that the variable is opened as public, and we can see it in the Inspector window It's a Game Object Type, so we can click and drag Pipe Prefab and put it inside Pipe Then Prefab Game Object has been registered as Pipe In other words, in Unity, in the variable that has Game Object type called Pipe, we put in Prefab Then we need to continue to duplicate Pipe, so let's write the code for duplicating Pipe in each frame. The code to duplicate Pipe is called Instantiate. If we put in Pipe variable we made on top, in here, the code will be run and the Prefab Pipe Pipe we registered will be created through Instantiate. Let's do this and try running it. Save the file and run the game In every frame, a new Pipe will be created and endless number of Pipe is created It's too much if it's created in every frame Go back to MakePipe code, and if we leave Pipe in Update function, it's created in every frame. Let's change it to be created every second As I've mentioned, it may differ across devices, so if we want to run it in the same amount of time, we use Time.delta Time, which is auto completed. Let's click it and we can make the same things happen across devices with different FPS First, create timer variable with float real data type and assign 0 to it Then use Time.delta Time in every frame in timer with += which means keep adding it So if we add delta Time and when timer becomes 1, then 1 second would've passed by regardless of FPS If we go over it again, if Time.delta Time is 6FPS, If it's 6FPS as in previous example, delta Time is the time it took per frame, so it would be 1/6 seconds then this keeps being added to timer to become 1 When the Update function is run 6 times, the timer will exceed 1 If it's 3FPS, it would be 1/3 so after it runs 3 times, timer would become 1 So we use if here, this is auto completed too. if timer is larger than 1, Time.delta Time will be different across FPS, but timer will start from 0 and when it exceeds 1, regardless of FPS, 1 second would've passed Then we write instantiate inside if statement and create Pipe once, and reset timer to 0, then we create Pipe every second like this. Let's write the code and run it Save the file and run the game, and we can see that it's created every second But even if it's 1 second, they are still too close If we want to easily adjust the distance apart, as we learned in previous session, create float timeDiff variable, and set it to public We can adjust the variable from outside We set timeDiff to 1, but 1 second is too close so if we set it to be bigger than timeDiff, we can create Pipe at certain moment when it's larger than a certain time, so we can come back to Unity and change timeDiff variable, 1 is too close to each other, so to 1.5 seconds. Save the file and run it, and you can see that their distances are a bit further apart You can keep testing the game to find the right distance apart Another problem is that the Pipe is created but they are in the same position and the hole will be in the same position, making it boring Let's change that so that we need to jump differently. The Pipe would need to be continuously created and it's created here We can change the starting Position So let's take the newly created Pipe and move it along the Y axis And then You can see that the gap you can jump through changes like this. So let's make the y axis location to appear Randomly when first made. To do that, to the pipe made at the Prefab Import the transform component to change the y axis. Come to the coding section, through 'instantiate', pipes are created Run this code to get GameObject. Let's import that GameObject to change the location. To do that, first make the data type variable Called GameObject. Make a variable called newpipe And put the instantiated GameObject into newpipe. Then this newpipe, into the new pipe goes the GameObject. Here, import newpipe.transform And let's add the dot position axis. =, and to pinpoint to the specific axis type in 'new' and 'Vector3' And (0, 0, 0) And the position value is Vector3 x y z It means I'm placing it onto this axis. It can't be (0, 0, 0), let's see Where it needs to be. Looking at the pipe location now It's good to keep the x axis from the back here So the x value should be over around 5. But see here, it's the free-aspect. Opening it again, the screen looks pretty different. To adjust that, click on that free aspect To turn it into the mobile screen we made before. Mobile is 9:16. Now it looks better. Again Then the game screen looks like this. And the x value here Let's start from around 6. Then starting from 6, x axis decreases Y axis If it passes too much, it's above the ground So we could extend the pipe to go up. It should extend with it along the way So shift and select the both To extend this more. Extend it like this When y value is the highest It's around 5.7 And the lowest, around -1.7 Let's create a random value in between those two. Another tip here, Many of you would be not used to C# Unity. So I'm sure most of you don't have the random number generator method Memorized in you. So it's not something to memorize. Just Google 'Unity random' Of course getting a random value at Unity is such a common thing to do, so So many different documents Talk about how to get the random number at Unity. Then, if you know what you need to do Everything exists at Google So just make it a habit of searching everything for your developing To make your job so much easier. So get into any document you see And use the method. Let's go to the official document. It's in English but We can see how it works. So as we did before, position, new, Vector3. It's all the same, so It says it uses random_Range to create the random number. Copy that here, into this Vector3 We put the random y here. Paste here The Range for that, We said from -1.7 To 5.7 at the highest. This f is for float. For real data type, we use this 'f' So let's use it here. That's done, and the x value We said it should start around at 6 So that it starts from somewhere invisible at the mobile screen. Starting at 6 Let's get the random y value. Do this, save, Play to run And we can see various locations here. The pipes have such a narrow interval. And some are floating like this Let's stop that from happening. So, at the Pipe Generator Time Diff, not 1.5 but something wider For the bird to move around. So let's give it around 4. See here, passing here It's too late now. Let's change it to around 3. Let's check how 3 looks like Through that public variable Play it yourself to adjust the difficulty And this is very convenient. I think this is enough. And of the created pipes, Some of them are too up in the air So let's edit that too. The reason there's the gap Is because this pipe is in between 1.7 or 5.7 Within the range it's alright But the problem was We're not using this Prefab here But the Prefab from this project here And since we used the copied Prefab here We need to apply this change. So this Prefab, at the inspector window It's floating right here, and click on that Overrides selector here You can choose to apply or reverse the changes And apply here. Click on 'Apply All' So that all the pipe Prefab at this asset Has all the changes we made in there. So if you change the Prefab at Hierarchy You should always apply it to the main Prefab. Make it like this, run Now the pipes are bigger And there's no weird gap in between It looks alright. Try playing it yourself, and if you feel like it's too easy With the gap too big You could change that again. Let's adjust that. The gap seems too big So narrow it down a bit The gap too, if it's too down into the ground it's weird So 5.5 Let's keep it around that Same thing, if you changed the Prefab, save And always 'Apply All' at 'Overrides' To apply changes. And at the coding part too Let's change it to around 5.5. Save and try playing it See, we can check that the Gap is narrower now. Play it yourself to adjust the difficulty If it's too easy, narrow down the gap or It's also easy because the bird's jump is too small. So make it jump higher And keep the pipe distance narrower Then it'll be a more fun, a more difficult game. For this, you can put in your random range For your game. I think this is pretty difficult Yet not too bad. You can adjust it to the difficulty you want. Another problem here is We keep getting this pipe But it never goes away. So as the pipes stack up As you run the game There are more pipes the memory should take care of, so It's good to make the pipes disappear After some point. To do that, at the coding section this 'newpipe' where we made the pipes Through 'Destroy' Put the 'newpipe' in there And it deletes the newpipe GameObject. But you cannot delete it right away. To delete it after some time Comma here, To type in the second for it to disappear. It even shows you what to add with the auto complete It says 'amount of time.' So let's make it disappear in 5 seconds. It should be in float form, so 5.0f Let's type in that. Save, run the game The pipe appears, and after 5 seconds It disappears. But it cannot delete in between. Let's keep it around 10. Keeping it at around 10, instead of 5, will Make it disappear after it passes the screen. Yes, like this, we can check that The pipes disappear after it passes the screen. Then we can save the maintenance memory. According to the pipe speed this part may change So you can adjust the time for Destroy as You play along with your game To keep your memory free. Next, let's add the text for the score And as the bird passes the pipe Let's keep the score up each time. To add the UI aspect like text or button We don't make it as the Unity GameObject right away You make the parent object called Canvas first And then add in the UI aspects. Let's learn how it works by doing it. First, right click into the sample scene To set the Canvas on the UI. Then you get the Object called Canvas. The name for this Change with 'Rename' Since we're adding score Let's name it as 'Score Canvas.' The Object in the form of Canvas is formed. The unique thing about this is, Check it at the scene Score Canvas is, Not into the game screen like this It's a bit white chunk Not related to the game screen We can see a big rectangle here. The reason for this is, This is the render mode, the current Score Canvas It's the mode on how to show it on the screen And now it's set as Screen Space Overlay Meaning, According to the size of the smartphone This screen size may change And if you set it as Screen Space Overlay here Regardless of the screen size It will just create the canvas Filling up that game screen. So this isn't too clear at this scene Just looking this big. You'll understand better by adding the UI aspect. So right click into this Score Canvas To create the Text Object, at UI. Then since we created it on Score Canvas The text is now into That Score Canvas. And see the 'new text' here? This, looking it at the scene, is a huge rectangle Like this but The normal Object Had the Transform component Whereas inside the Canvas we get This Rect Transform. What is this? Rect Transform is, for instance, If you want to Keep a button Always on the right top of the game You just created it like this But if you just set the Transform location value It's just the axis calculation, so When someone plays it The button may not be on the top right But somewhere weird. So regardless of the screen size We set the specific point With this Rect Transform. If you set the location through Rect Transform We get the datum point of Anchor And with that point We place the button like this So it allows setting the datum axis point So regardless of the screen size We can place the specific UI where we want. So let's use this Rect Transform And Anchor To place the Anchors And let's place this text in that comparative location. Or the text may go into Somewhere weird depending on the size of the screen, So let's set the Anchor first. To fill the Anchor all the way into the screen, Minimum as 0, 0 for both x and y And Max as 1, 1 then You see the Anchors wrapping the whole canvas. So Anchor isn't the specific points only But you could set the whole space to Shape the location for your UI. Since we have the Anchor values Let's keep it floating, Left Top Let's keep this both 0 And the Anchor wraps around the whole But this isn't floating here We set the location like that, so now We can see the text Not floating in that screen at all. So first, align the text You align it to the center like this, And increase the font size, to around 70, We're just using Arial here If you want a specific font, you drag in the font you want To change to that font. So let's bold the font Since it starts with 0, let's type in 0. And change the font color into white Let's put it on top of things. To do that, adjust the Anchor value So that any type of screen can have that. To do that we need to understand the Min and Max of Anchor. Min and Max of Anchor Is the datum point adjustment For instance Let's keep the Min up by 0.2. Then the rectangle, the datum point, Has decreased to the x axis, the horizontal direction By around 20%. So it's 0,1 around the x axis. So keeping it from 0.2 to 1 means From the 20% point to the end. So let's fill in the x axis And keep the y axis like this. To do that, the x axis Can be 0,1, and y axis, let's change that, Into 0.2 The y axis, the vertical length, from the bottom to 20% up It's gone up like this. Meaning, this is the 0,1 area. So let's change that To make the rectangle look like this. It looks pretty big, so let's keep it to 0.8 And we get this. Whatever the screen size is, Let's keep the score 80% from the bottom And 20% from the top And that every screen can have that. To keep that, we faced the bottom value in there. Have this as 0 and No matter the size of any screen The one we placed around the Anchor, 20% from the top, the whole x axis At this area Up, down, center. We've se the horizontal and vertical area. Inside this, Left, top, right and down Keep it as 0, 0, 0, 0 So that it keeps that comparative proportion At the certain spot. And save. Next let's write the C# script for the score. To do that, inside Text Object Go down Add Component As we've been doing it, New Script Let's make the Script Called Score. Create and Add. And we added the Score. Inside this, First, in this class Let's make the actual Score number The variable to save inside the text. The score doesn't go up by decimals So make the variable called Int Score And keep it 0 at first. This score is, Whenever we pass through a pipe The score will go up and it'll show right away So let's keep it public so that We can change if from the outside too. Additionally, To approach this Score from outside to use it It should be, Although it's the variable inside the class, to approach this From somewhere else to keep the score up We need this 'static' in front of this. If you only know about Python You may find this 'static' new. Since some of you may not know about static Let me briefly explain. When I explained about Class at Python, I used an example The class is a blueprint And the instance, the houses made through that blueprint I used this example here And inside this blueprint, the class, The number of houses to build, that's the Count. And the owner of each house as Owner This Count isn't the important variable for each house It's the variable made For the whole blueprint to maintain the Number of the whole houses in terms of class. So this variable isn't something Used in this Instance, but it's used in terms of Class The variable maintained Uniformly throughout, we use Static in front of it To use it. What this means is, It'll get too complicated in too much detail But in short, Static variable isn't the variable maintained at Instance. Even without creating Instance, even at Class We can maintain this variable, and this gets the name 'Static.' If you're learning about Static for the first time It may still be confusing But just to keep it simple Adding 'Static' here allows us to Make the variable maintained in this class, even without making Instance. That's the gist of it. With Static added, we can also maintain it By approaching the class from outside To edit the variable. Then, we've made the Score And inside the update function Every frame, this Score, The Score variable now 'Static' Should change and show right away on the screen. So the UI component we're dealing with here is Using UnityEngine.UI Add this, and 'using' here means to import in the code It's like 'import' at Python, I already told you that. So import in unityEngine's UI, and whenever you do something You should add this 'using UnityEngine.UI' And inside the update function UI text Bring in this text component And the text value inside the text Should be changed to the current score. As we learned it the last class, Using GetComponent Bring in the component called text And here Let's add '.text=score' If you just write this, the score is an 'int' An integer number So keep it 'string' So the text is the string, the text data type. So it says it can't be changed At C#, when we transform such We use .ToString. And then the score is now ToString It was an int, but now it's a text data type. At Python it was Str and Score. It's the same expression. Of course you don't need to memorize this Google this C# int to string, something like that And right away with the first result It says 'ToString method' and all. Like this, if you don't know about C# grammar Then as you did from the other languages Type in the language name, and search for something you want to do And every grammar is here on Google. So there's no need to memorize these details Just Google them, and use the most of this auto complete function Then it will be alright. Then instead of meaninglessly memorizing grammar You can invest time to make more useful functions. Then, I'll pause and save the work before I proceed. Next, let me zoom in on the space between the pipes. I'll create a function that will make the score go up whenever the bird passes the gap between the pipes. To do that, I'll open the Pipe Prefab. Right-click on Hierarchy and select Create Empty to create Game Object. Then I'll rename it to ScoreUp. Then I'll click 'Add Component' here. To detect the collision when it occurs, I'll use Box Collider 2D which I used for the ground earlier. Create Box Collider 2D. It's created right here. Then, I'll use Transform - Position to make the score go up when the bird passes this space between the pipes. Let me elongate the box by using Edit Collider. Then, I'll write a script so that the score will go up when the bird passes between the pipes. To do that, if you see what's under the Inspector and Box Collider 2D, you'll find 'Is Trigger' with a box next to it. If you check the box, the collider will be set as a Trigger. Here, I'll briefly walk you through the difference between Collision and Trigger of the collider. First, Collider is a component that defines the boundary of a physical element. And we've done this several times in the previous session, We applied Box Collider 2D and Capsule Collider 2D like this. Sometimes those colliders can clash. When objects clashes, two different things can happen. One is Collision and the other one is Trigger. Let's go over the difference between the two. First, the collision will automatically be selected when Collider is applied since it's a default option. When Collision is applied, if two different objects collide, the laws of physics will be applied and one object won't be able to pass through another object. And if you want a certain code to be executed when the collision occurs, you can add another function like 'Enter' after 'OnCollision' so that certain events or behavior can occur when the collision happens. As you saw in the video, if you check 'Is Trigger' box, the collider's collision property will change to Trigger. If another object collides with the object on Trigger, they will overlap instead of colliding. If you want some kind of event to occur when this bird passes between the pipes you can use a function like OnTriggerEnter or OnTriggerExit so that a certain code can be executed when the event occurs. To do that, I'll click 'Add Component' and 'New Script' down below. I'll name the new script 'ScoreUp'. Then, I'll hit 'Create and Add' to create the new script. Go to ScoreUp. This time, I will use neither of Start nor Update. For Trigger, you can use OnTrigger method that's already been defined. OnTriggerEnter is for when an object enters and OnTriggerExit is for when an object exits. To make the score increment by 1 whenever an object enters, I'll use OnTriggerEnter2D. In this method, when an object enters the Trigger... We can import Score we've made earlier. Since this '.score' variable is declared as static, I can import it from class right away. Here, I'll let the score increase by 1. ++ means 'increase the score by 1.' So, I typed this in. This won't work in Python. In Python, you should type +=1 Well, you can type this here too. It doesn't matter. Anyway, after typing these, save the script. If you look here, it's got '+' sign on the icon. It means it's only been edited in Prefab and hasn't been applied yet. Here, I'll click Pipe Prefab, Overrides and Apply All to apply it to Prefab. Then, I'll save and if I click the play button here, I can see the score go up whenever the bird passes through the pipes. Yeah, it's working fine. The bird won't die even if it hit the pipes. And some odd things are happening here. I'll make some changes so the bird will die when it hit the pipe. To do that, I'll create a new, Game Over scene so when the bird hit the pipe, the scene will switch to Game Over scene. We've been only working with SampleScene so far. Now, I'll create an additional scene called GameOverScene so if the bird hit the pipe in the SampleScene, the scene will switch to GameOverScene. Before I do that, since SampleScene sounds kind of awkward, I'll rename it. Here, click Asset folder, go to Scenes. We've only been working with SampleScene so far. Since this is not very intuitive, I'll rename it. Click Rename and I'll change the name to PlayScene. And if I click Reload, now you can see the name has been changed to PlayScene. So, PlayScene is where the actual game is played. And I'll make a new scene called GameOverScene so 'Game Over' will appear in this scene. To create a new scene in Unity, go to File and click New Scene. I'll make it with Basic 2D. Click Create. Then, I'll get a new scene named Untitled. It'll contain main camera as default. Then, I'll name the Scene and save first. Right-click and select Save Scene As. I can choose the folder I want to save it in. I'll save it in Scenes where I saved PlayScene. I'll save it as GameOverScene. If I click save, now I have GameOverScene here. Then, I'll start creating some content. The characters don't have to move in GameOverScene. So, I'm going to add some UI components to Canvas. Then, I'll right-click and create Canvas where I can put UI. Then, under Canvas, right-click and under UI, choose Panel. Then, I'll insert a background image into this Panel. Add Panel and then I get this as a basic background. Since I have the image I want to use as a background, I'll go to Assets and from edited images, I'll choose 'Background' and it to Panel. Click and drag the image and drop it here. Now the background image is applied. Since it's for 'Game Over,' I'll darken the image a bit. Select Color, add some shades and increase Alpha value. So, I'll darken the image like this. Then, Under Penal, right-click, go to UI and add Image. I'll use this to add this Game Over image from Asset folder. By default, no image has been assigned to Source Image so the box is white right now. I'll insert 'Game Over' to Source Image. It's out of proportion. It's because the size of the image was adjusted to fit the box. I can fix that by clicking Preserve Aspect. Now, the image regained its original proportion. And by using Anchors under Rect Transform, I'll make the image to appear in a specific area at a specific rate regardless of the size of the screen. To do that, I'll make X axis go from 0 to 1. Then, I'll let Y axis go from 0.8 to 1. And if I enter 0, 0, 0, 0, 0 here, you'll get this. It looks too full so I'll change X axis range from 0.3 to 0.7. This will create 0.3 space on either side. And if I put 0 and 0 again... Well, I think this is too small. I'll add 0.1 space. 0, 0 Now, 'Game Over' was inserted nicely. Save here. Then, I'll add 'Score' text. As you did earlier, go to Panel and right click. If you click Text under UI, you'll get 'Text' here. To differentiate, I'll rename it as Score. I've got 'NEW TEXT' here. I'll change the font style to Bold and the font size to 50? You can't see the letter because the box is too small. So, I'm going to enlarge it a bit. This seems too big so I'll decrease the font size to 40. Then, I'll choose 'Center' for the Alignment so the text will align at the center. And to allow this text to adjust its location with respect to the size of the screen, under Rect Transform, I'll put 0 to 1 for X axis and 0.7 to 0.8 for Y axis. Now, it's placed here. Then, I'll type 'Score' and put 0 for the value for now. Then I'll change the font color to white. And in addition to the current score, it would be better if I will also show the Best Score. To do that, I'll make a duplicate with Ctrl+C and Ctrl+V Then, I'll rename the new text as Best Score. I'll place it a bit lower at around 0.5 and 0.7. Now, I've got another text. Then, I'll change the text to 'Best Score.' so the best score will show right here. I'll add the code for the score later. For now, I'm just going to leave it as a text. Then, I'll add 'Retry' button here. Go back to Panel, right-click, UI and select Button. Then, a button will appear on the screen. I'll show you how you can let the player restart the game from the beginning by clicking this button. Since we've got an image of a button, let's use that. Select the button image and drag it out to Image under Inspector window... Well, what it shows now by default is UISprite. I'll switch it to my button image. It's out of proportion again. If you click Preserve Aspect, it'll appear in original size. The button comes with a text by default. But since we don't need a text, I'll right-click and select delete to remove the text. Now, I have the image only. Then, I'll change the location to the button by using Anchors. Let X axis from 0 to 1 and Y axis from 0.4 to 0.5. Then type 0, 0, 0, 0. This looks good so I'll leave it there. I've just added and arranged some UI components on the scene. Now, I'm going to start adding some functions. First, I'll show you how to change from PlayScene to GameOverScene. Save what you've been working on. Go to scene and double click PlayScene. Now you are back to PlayScene window. Let's make the scene switch to GameOverScene when the bird hits something. Go to Bird Object and open up a script called Bird Jump. If for Game Over to appear when the bird got hit... Check the Collider 2D box. You can make Game Over appear when two different colliders clash. The Collider box is checked for both the top pipe and the bottom pipe. In other words, I can make it to switch to the GameOverScene when the colliders collide. Since the ground also has a collider, you can also make the scene switch to Game Over when the bird collides with the ground. When colliders hit... Well, earlier when we tried to make the score go up when the object passes between the pipes, we use OnTrigger. But here, we are using OnCollison function instead of OnTrigger. Since it's easy to mis-misspell, I recommend you to use auto-completion. Let's use OnCollisionEnter2D function. If you click it, it'll auto-fill the function. What this function does is that, when colliders collide or overlap, what's written under this function will be executed. So what we want to do here is that... We want to switch the Play Scene to Game Over Scene when the collision happens. In Unity, we are supposed to use what's called Scene Manager when switching between scenes. To use Scene Manager, like we added UI when we dealt with UI, under UnityEngine, I'll add '.SceneManagement' module. Then, by utilizing 'SceneManager.LoadScene' method here, I can switch between the scenes. I can type in the order of the scene or the name of the Scene here. Since we named the our scene 'GameOverScene,' I'll fill it in and save. And one more thing! Go to File and click Build Settings. Now, only 'PlayScene' is added here. To switch between the scenes, I need to add 'GameOverScene' here. To do that, under Scene folder, I'll click GameOverScene and drop it here. Now, PlayScene is numbered 0 so I'll be played first and GameOverScene is numbered 1. So, as I did with PlayScene, I can load this scene by using Scene Manager. After this, let me close the box and play it. If you click the play button, when the bird hit the pipe, the scene switch to 'GameOverScene.' And you want the game to restart when the player hit Replay Button. I'll show you how you can do that. Pause the game and go back to the Game Over Scene by clicking 'GameOverScene.' You want the scenes to switch when the player hit Button under Panel. To make a certain function to be executed when the Button is hit... First, right-click the space under Hierarchy. Create Empty Object by clicking 'Create Empty' and rename it as 'Replay.' Then below this object, by using 'Add Component,' I'll add a new script. Here, you can choose New Script but to speed things up, in the search box, you can just type in the name you want to use for your new script. I'll create a script named Replay. And if I press 'enter,' 'Replay' was chosen for the name of the new script. Then, if I click Create and Add, the new script called 'Replay' is created now. Then, I'll write Replay script by double-clicking it. The function of 'Replay' should be very simple. I don't need Start of Update. All I need is one function that allows the player to switch from one scene to another. Then, I'll create the function. Public void. This may sound new to you. It just means that the function doesn't have a return value. So, it's public void and I'll create a function called 'ReplayGame.' And inside this ReplayGame, as I did before, I'll import 'SceneManagement' from UnityEngine and by using LoadScene of SceneManager I'll create a function that'll allow the player to go from GameOverScene to PlayScene. After that, from the Button under Panel... Well, for the Button, by default, if you look at the button component, you'll see what's called 'On Click.' The button is usually there so a certain event can take place when the player clicks on it. If you click '+' under On Click... You can use UI to make certain functions to be executed when the button was hit. We made an object called 'Replay' earlier so... Drag and add it here. And if you click No Function here, you can execute the function listed under Object called 'Replay.' Under Replay, you are lots of functions you can choose from. We made what's called 'ReplayGame' earlier so... Choose 'ReplayGame.' Now, if you hit 'Button,' the scene will switch to Replay Game. I'll save it here and play. If I hit the button... You can see it went back to the beginning of the game. And when it dies... Well, since I haven't made any changes to Score yet, the score is 0. And another problem is that even if I restart the game, the score accumulates instead of resetting. So from 2... It went up to 3... And if I restart, the score starts from 3. So, we need to make some changes so the actual final score and the actual Best score would be displayed when the game is over. And I'll also show you how to make it reset the score when the game restarts. First of all, for it to display the actual final score when the game is over, I'll go to Penal add a new script under Score. By clicking Add Component, I'll add a new script and name it CurrentScore. And if you open it up, you'll see Current Score. And below this script, you can import the final score and display it on the screen. To do that, as we've done before, I can important text component and if I change the number in the Text Properties, I can change the score. We've done this a few times so far, so you must be familiar with the step by now. To import UI component and make changes, type UI next to UnityEngine. Then type GetComponent and Text Component here. Then, type in '.text' and type in score. Earlier, we made the score to be saved in a static variable called 'score,' under 'Score.' Here, 'int' can't be saved in string. So by using 'ToString,' convert 'int' to a string and save. Now, the CurrentScore will be applied at the start. And the current score needs to be applied only once. So you don't have to make any changes in updates. In fact, you can just erase them. And if you save and play... Now, the actual score is applied and updated. Now, it's displaying the number only. If you want to add the letter 'Score' before the number, Type Score: and + Score here... This will go before the number and the number will follow after that. I'll hit the play. Now, you see both the word' Score' and the number '1.' And another thing we need to do is. We don't want the number to accumulate after the game ended. So, I'll show you how to reset the score at the beginning and to keep track of the Best Score. First off, in PlayScene, ScoreCanvas, Text and Script, I imported static. For this to reset to 0 whenever the Scene begins playing. For this to reset to 0 whenever the Scene begins playing. we haven't utilized start yet, but if we reset the score of start to 0, when the scene runs, start will run first so it will be started from 0, so it won't be accumulated We also need to save the best score Copy score and create a new variable called bestscore Let's continue to compare bestscore and save it Let's just create the variable and inside the script of birdjump, when the bird dies, if the score is higher than best score, it will be saved as best score, or else, thrown away. We can code it that way OnCollisionEnter2D is when the bird dies and the game is over, we can use if The current score is saved in Score.score, right? If Score.score is bigger than Score.bestScore, then we can put Score.score inside Score.bestScore. Then when the bird dies, if the score is higher than the best score, it will be reflected in best score Or else, it will just pass through this part of the code and the previous best score will remain as best score Afterwards let's go back to the game over scene, and in the best score in the panel on the canvas, let's add a script to reflect best score Click Add Component, and let's use a script called best score and add it Double click and revise the script You don't need to update it You need to modify the UI component inside start Bring it and write '.UI' use Get Component and bring TextComponent Here at '.text' this time, write 'Best score:' and bring the static variable that we created called '+Score.bestScore', then we can reflect the best score on the UI Let's import it and save it. After saving it, let's test it Then when you get 1 point, the best score is 1, 2 when 2, and when you die at 3, you can see that the score has been updated to 3 When you die at 1 point, the best score will remain at 3, and the current best score is 1 You can see that it's working properly when you click replay, you can see that you start from 0 points What we need to add is that right now, if the bird goes out of the screen, the game doesn't end We can't do that, so we are going to create another collider, so that the bird dies when it hits the top edge So let's go back to the play scene, and right now there's nothing but right click, create empty, and create an empty object called upside Here, box collider 2D You don't need to go into the menu to go to Physics2D's Box Collider and you can easily find it by searching it Select Box Collider 2D and create it next, we have the Box Collider 2D but we are going to move it to the top Adjust the location, Y axis, and spread it out over the X axis and create a collider that covers the top Then, when the bird flies to the top, the colliders will clash, and we can change the screen to the game over screen Let's test it Save and execute, and we got the game over screen But I think the collider is a bit too low, so let's raise the upside If we raise the upside, if it flies just a bit over the screen, we will allow it, but if it flies any higher, it will die. Let's save First, we created this pipe with prefab and we often call this prefab as pipe generator or pipe spawner, but the pipe generation keeps creating the pipe that we made with prefab so it doesn't need to be here from the beginning You can delete the prefab here, and the pipe will still remain inside ss. Let's save, and we are done with the basics. Next, let's learn how to create effect sounds and complete the game For the effect sound, if you search 'royalty free sound effects' on Google, if you search it, you will get a lot of websites The websites I recommend are 'soundeffect-lab.info' you will land on a Japanese site If it's hard for you to read Japanese then you can just use the Google Translate Addon, and you will be able to read some of it. There are a lot of great music that could be used in games that are royalty-free If you look here, they provide sound effects that have open access If you go into battle category, When there's a battle in the game, you might want to add like a sword slash sound, right? You can choose from here, download it, and use it There's a flapping sound like the 'Dragon flap' here. You can use that but it's too much for our game There are a lot of effects here Listen to them and if there are the sounds that fits your game You can choose from various categories If you can't pick one or you might want to create a sound of your own So I will now tell you how If you go to your Windows menu, if you search for record, then there's an application like this If you turn it on, you will see this screen You can connect a mic to the computer or earphones and you can directly record it I will try to make a flapping sound of a bird Try it couple times, save it and play it If you want to save some part of it, you can crop the file Let's crop and save the front part You can crop it like this, and save it If you save a copy, if you run it, then you can see that the sound effect has been saved Then you can right click the file, open location, and go into the folder You can see the recording file here. Let's create an effect with the name flap It is saved as an m4a format, but it's not supported on Unity It needs to be in either mp3 or wav Let's convert the file format If you search on Google, m4a to wav, then a lot of websites will support the conversion without any downloads or installation of softwares I will convert the file here on Convertio Let's choose the flap effect and convert it to wav Then you can download the converted file like this Now we have a wav file Then put the wav file in the ss folder Then you will see that it's been imported If you click it, it plays Now, let's play this sound whenever the bird flaps Click Add Component inside Bird object, and add audio source Then we get the audio source like this, and Play On Awake is selected as default. It means that the sound is played when the object is created but the flapping sound should not be played right away right? So let's uncheck it Then click the flap effect, and put it inside the audio clip Then in the Bird Jump script, let's add the code to play the audio source The flap sound should be played in Bird Jump, when you click it. Here in velocity.up It should be played here. Then use Get Component, and import the audio source component. We can use the play function When this is executed, audio source is imported and plays the effect that we added Save it and execute it, and whenever you click it, you can hear the flapping sound Let's also check if it works on your smartphone Go into build setting in the file, and check if play scene and game over scene is added correctly Like last time, turn on USB debugging, select Build and Run, and run it Click Build and Run Let's save it When we play it on the smartphone, the game works, but the letters are very small. Let's modify the size of the letters First, in the inspector, there's a component called canvas scaler This sets how we are going to modify the canvas according to the screen size. In the UI scale mode, it's set to Constant Pixel Size as default, but if we change it to Scale with Screen Size, it will be modified to the screen size. Then we will set the reference resolution I searched this on Google so it's going to differ across devices, but let's set it to 1440x3040. Set it to 1440x3040, and the text got a lot smaller, right? There's a checkbox called best Fit inside the text component inside the text object, and if you check it, then you can set the ma and min size of the font Let's set minimum to 70, and 300 as maximum Let's save it Likewise in the game over scene, let's change it to Scale with Screen Size for the Canvas Scaler to 1440x3040, check the Best Fit inside the panel Set the min to 50 and max to 170 For best score, set Best Fit set minimum to 50 and maximum to 170. It got a lot bigger like it initially was, right? Let's save it and execute it again Let's build it once again. We can see that the font size is right and the game runs properly The replay button works well, the sound effect works properly and the score and best score works properly as well. So we have set all the basic functions of 'Flappy Bird' If you are a beginner in game development, it might be difficult because it's new, but if you think about it, a lot of the same patterns repeat You add objects, inside the inspector, you modify a lot of the components, you can add new components, and in the script, you can import certain actions. There are a lot of common things throughout This was an example to start learning how to develop games in the overall Unity Not everything is the right way, so you can modify the 'Flappy Bird' game or create other games that you want, and test them out You won't be able to memorize everything you need to know for the game you are making, so make sure you Google often and see how you code the functions you want. I hope you can code the games that you want to make Putting in ads and how to make profits, how to upload the game on the store, and marketing. Let's learn how to do them What you need to check is that when you come to Unity hub, in the install tab, click on the settings icon next to the Unity version, if you go into module you will see Android build support from SDK, NDK, and OpenJDK. Everything needs to be installed to proceed If you haven't installed them yet, check the boxes, and click install. You can install them After everything has been installed, go back to the project and execute them. Sometimes you will get an error even if you install all of them so let me tell you how to fix it Go to Unity Editor, and go into Preference under Edit If you go into the External tools menu, there's a window that searches for the directory of JDK, SDK, and NDK If you installed it properly, the JDK directory will show up like this If you have an error, the directory will be incorrect So if you unclick this, you can set the directory again. Click the browser, and you can select the directory of JDK If JDK, SDK, and NDK is not downloading, there's a way to manually download them Let's download JDk first. I will leave the Oracle address in the details and comments for JDK Go into the website, and download Java SE Development Kit version 8 If you are using Windows, download 64 bit if you are using 64bit and 32bit if you are using 32bit To check the bit of your Windows, open System Preferences, and it will show what kind it is I am using 64bit, so I will download it You need to create an Oracle account. If you are finished logging in, the file will be downloaded Click it and install it Make sure you check the directory and you need to set the directory to the installed location The installation is complete. Now find the installed directory on Unity JDK and designate the location Next, let's see how we can set SDK Go into the address where you download Android Studio and download Android Studio Download is complete. Let's install it Installation is complete Click finish and when the screen pops up, click okay, and our purpose is SDK so ignore everything else Cancel it If you click New Project, Open SDK manager will be opened. You can download Android SDK Check the directory by clicking Edit and if Korean characters are included in the directory, I recommend you to change it to English directory If you click Next, then it will be installed like this The installation is complete, click finish Put the directory in Unity Click the Android version that you want to support and apply it There will be an additional installation You can download NDK in this address However, there's a specific version required for Unity, so I will post the address on the details If you go into the address, you can download the NDK version for Unity I will leave the address in the details section You can unzip it to a directory of your choice, but this also needs to be English-only When you are finished uncompressing it, copy the directory and input it in Unity So after checking that all JDK, SDK and NDK has been set completely, close Preference window and go into the build settings of the file Then check the box called Build App Bundle, which is used for the app to be uploaded on Google Play Store Then on the left bottom, go into Player Settings You can change the settings related to the app. Let's zoom in Let's change the values inside Player Company name, Product name are used as App ID, so there needs to be a value for the two for the app to be launched In other words, write a unique company name. I will write jocoding If you use the same name as the product name, you won't be able to launch it. So make a unique company and a unique name for the product name Mine is 'Jocoding Flappy Bird' so let's change the name to 'jolappy' Please change the names to a unique value This space is to designate a version number to differentiate the version when you update it later I will leave it at 1.0 Next, let's add default icon and icon. The icon is the icon that you see on the smartphone home screen when you install it So let's create an icon image and register it Use an editing tool like Paint or Photoshop to create an icon I will use paint tool. Click adjust size to chose the pixel, and set the size of the canvas We are going to make our icon rectangular, so uncheck the size ratio, and set vertical 512 and horizontal to 512 as well and set vertical 512 and horizontal to 512 as well Press 'Confirm' and we now have a 512-pixel square canvas. Here, you draw an icon image that you want. Or if you have an image that you hold rights to, you could copy and paste that image onto this canvas and embellish it furthermore. I'll insert a new image here and paint the canvas. I'll use this method to make an icon. Then click on File to save it as a different name. We save the file name as 'icon', and the format as PNG. Click Save. Place our newly made icon inside the assets folder Again to Projects Settings, we hit the 'select' button on Default Icon and add the icon we made. Then you could see the default icon added here. Next, press Resolution and Presentation and set up the Orientation here. Orientation means the direction of the phone. There are largely 4 ways of a direction of a phone Firstly, Portrait means a position where your home button would be placed at the bottom when you hold your phone in a conventional way. Portrait Upside Down is flipped upside down. Landscape Right is where the home button is located on the right. Landscape Left is where the home button is located on the left. The game might require you to play it vertically or play it horizontally. So you can fixate the rotation degree of the phone. The basic setting for the Orientation is Auto Rotation. So they provide all four orientations for the screen to rotate. You can untick some of the boxes to fixate the orientation. But in Flappy Bird, you're supposed to play only in a vertical direction. So we'll fix this as Portrait, not Auto Rotation. Next, we'll set up the Splash Image. Basically what Splash Image is - If you take a look at this game view and hit the Preview button you can see the game starts after a Unity logo, the initial image as such is called as a 'Splash Image'. This Splash Image is set up to appear as default if you're using a free version of Unity. If you're paying for Unity, then you can entirely turn off this Splash Image or completely change it into a Splash Image that you want. But also in free versions, you can do a bit of customizing. Click on the plus sign on the Logos menu at the bottom to add a logo image and make it appear along with the default Unity icon. Click on select of the Logos menu and select the JoCoding image that we had split from our initial image. And when you click on preview again, you can now see the JoCoding logo shown above the Unity logo. The image looks a little low-resolution under the flappy menu of animalface.site, Under this image, the one we've initially downloaded I've uploaded a high-resolution image of the JoCoding logo. Right click on here, and save the image with a different name and you can get a more high-resolution image. Place our downloaded image inside the 'assets' folder And change it to our new high-resolution image. Look at the preview panel and you can see it's more high-resolution than it was. Additionally, with controlling these options you can adjust the Splash Image. I'll just stop here and move on. Next, go into Other Settings. And then you'll be able to control a diversity of values but do leave most things untouched and I'll explain to you the things you have to change. First, the Package Name inside the Identification menu. This is the one we've talked about, after com., comes the company name that we had set above and following is our name of the game, in this order. This package name has to be a unique value. If you type in what I wrote like this, you cannot submit the app. It has to be your own unique value. Next up, versions- you'll just have to add on the numbers as you do an update. Next is the Bundle Version Code. If you submit an identical version of it when you do an update, which is to say if this version code is the same, then it will throw an error, recognizing it as the same app. So when you're doing the update For this, you just have to up the numbers along with your update. We'll just go with 1.0 and 1 for now and move on. Next, according to Google Play's new policy, here's what you have to do with the Target API Level starting from November 2021, when doing app updates you have to target API Level over 30. So we should target API Levels over 30, and over Android 11. So click on this Target API Level and set it as 'Android 11.0(API level 30)' to safely publish your app. Next here, Configuration Currently, the Scripting Backend is set as Mono Click this Mono to change it into IL2CPP and currently, ARMv7 is the only one checked here We're going to also check the box on this one, ARM64. Starting from August 2019, you need to support 64-bit in order to get it into the Play Store. Revise it like this and close the Other Settings menu. Next, we move on to Publishing Settings. In this Publishing Settings, We're going to make a Keystore and then a Key. What's a Key and a Keystore, you ask? Firstly, because it would be trouble to let anyone modify your app so a Key is needed to certify which app belongs to who. So the right to modify and release an app is all held in a single Key. And what manages this Key is called a Keystore. Make a Keystore and also I will make a Key assigned to this project. For that, you need to click on Keystore Manager, consequently clicking on Keystore and then hit 'Create New' to select 'In Dedicated Location'. And then you can make a Keystore file and save this 'user.keystore'. Then we have a Keystore file. Set up a password for this. You shall never forget your password. Make it and save it somewhere else and take good management of your Keystore, please. After setting up a Keystore password, we'll make a Key. Keystore is a store where you store these Keys and Keys are the Keys allocated for each project. Here, I'll make a Key designated to this Flappy Bird clone. Alias is a substitute name, I'm going to name it 'jolappy key'. And then write down your password. If you lose this password, you cannot modify the app so make sure you keep record of it somewhere else. And Validity. You can set up how long you want your key to be valid. I'm going for 100 years. Then, write down your personal information. Your name, organization, city, region, and country code. Click on Add Key afterwards. And then we have a Key saved, named 'jolappy key'. And designate this as a Key to protect this specific project. Click on 'yes' to save. And then the designation is complete. You need this Key to actually release a app via Play Store. Don't lose this Key and your password. Now, when we connected this with USB and ran it on Unity it worked well but after publishing it on Play Store and downloading it to play it I got an error, so I googled it. Like this, 'unity app only crashes google play'. If you search with this, probably there would be lots of people with the same problem, wouldn't it be? So if you're stuck, always type in search box first Unity, and then state your Framework, language, and tools and after that state the problem you're facing. You'll see solutions of those who have had faced the same problems. Here at the second post, we have someone who have had the same issue as me. When seeing the answers, they say opening up Unity and adding this code inside the Application tag of 'Manifest' is supposed to solve this problem. So we're going to add this code. Inside the Publishing Settings that is at the very bottom, Underneath 'Build', there's something called 'Custom Launcher Manifest'. Tick this box. Ticking this we have a new file, Inside this 'Project Files', inside 'Plugins', inside 'Android', and you'll see something called 'LauncherManifest.xml'. If you open this via VS code, it looks like this. Here, the application part appears only like this but We'll copy this code we saw at Stackoverflow and paste it inside the application. We're missing a quotation mark here so put it in. Add a new line of code like this and hit Ctrl+S to save it. Now that we have the Player Settings ready, check if the Build App Bundle box is ticked We'll hit 'Build' to make an app file for the Play Store. Hit 'Build'. Then you'll be able to save it as an aab file. I'm going to name it jolappy and save it. Hit 'save'. In order to target API Level 30 you need to do a sdk update. So I'll set up this by clicking on 'Update Android sdk'. I got an error, so googling by this error message says that there's something wrong with our Unity Hub; Go into your installed location, C\Program Files\Unity Hub and then Run the Unity Hub as system administrator, and it's supposed to function normally. So we'll proceed by running Unity Hub as system administrator. We'll close the panel that we had, and again build it as 'jolappy.aab'. The window appears once again like this, and this time we updated it to run as system administrator to see its working perfectly well like this. If you go on to check the savings directory, you can see that an abb file has been created. And now we'll publish the file on the Google Play Store. If you look up on google 'Google Developer Console', the first thing that pops up is a page named Google Play Console. Go to here. and then you'll see this screen. Hit 'Go to Console' button. In order to use a Google Developer Console, you need to have a Google Developer account, not just a standard one. A Google Developer account is where you pay fees to Google to obtain the rights to publish an app on Play Store. More detailed information regarding the Play Store is on my previous video comparing between stores, so please refer to that. If you don't have a developer account, choose the type, whether it's for Personal Use or an Organization or a Businesses and click on start to make a developer account. Fill in your information such as developer name, contacts and Click on Create Account and Proceed to Payment. If you pay the registration fee of 25 dollars just once, you'll eligible for using your Google account as a developer account for a lifetime. Register your developer account and you'll see this screen once you log in to Google Play Console. Click Create an App button on the right. And you can fill in the details of the App, including the name, language, whether it is a game, and whether it is free of charge. So we'll fill in the information required. I named my app 'Jolappy Bird'. And for the Default Language, because Google Play Store is used world-wide, I'm going to select English which is used by most countries. I selected 'game' because this is a game, select 'free', check all the boxes and create an app. Click 'Create an App' located at the bottom right. We'll adjust the settings for the app release. If you look below, there's a toggle to-do list beneath 'App settings' and it shows you things you have to do to get it published. We'll do it one by one. First, go into 'App Access Rights'. This is for enabling a limited access according to the user's logging in or membership. But we don't have those things so we check the 'Can access without exclusive rights to access' and then hit save. And then, we go back to Dashboard. You could see the list being fulfilled one by one. We'll work on the rest. Go to the Advertisement section and indicate whether your app contains ads or not. We'll be going to put in ads in the course of a future update so I'll select the 'yes, there are ads' option and save. Again to the Dashboard, to go into Content Rating and start the questionnaire regarding the Content Rating. Click on 'Start Questionnaire'. Fill in the email address you'll get a response to questions regarding the Content Rating. And then choose the categories. For the App Category, because I made a game we'll choose 'game' and then click on next. No violence, no fear, right? Fill in the answers for all these questions. When you're done, click on save and hit next. And then you have your Content Rating. Click submit here to complete the rating process. Come back to Dashboard and fill in the target audience. Tick all the boxes above 13 and they say, if you want to let children under 13 use this app you'll have to add your Privacy Policy. We'll stop here and move on. Can it draw children's attention... this is quite subjective, but I'll go with no. They say Google decides whether an app can draw children's attention and if they don't agree with you, they can update the app. I got a rejection email from Google saying that they cannot publish my app. They say my Target Audience is inaccurate I set my target audience as above 13, but they say I have an animated character and a young character hence it can draw the young audience's attention and therefore requires me to reset my Target Audience. So let us set it again. If you look at the very bottom of your Google Play Console there's a tab called App Content below the Policy menu. Go there and inside the App Content menu click the 'manage' button on the Target Audience and Content menu. I've checked all the boxes that are above 13 but we need to also include those who are under 13. We can't currently check those boxes here This is because of the Privacy Policy we see on the top here. We should add in the Privacy Policy in order to check those boxes. So we'll first register those. Click on 'start' to register. We'll have to register our Privacy Policy url in here. To easily make a Privacy Policy, We'll use this tool from privacy.go.kr called 'Making your Privacy Policy'. I'll leave the address on the details and the comments section. So using this site, we will Make our Privacy Policy and an associated url. Firstly, we newly name our Privacy Policy as 'Privacy Policy'. It's a private institute and also fill in the name of our organization, the name of your site, and a site url. For the site url, we'll use netlify which we already have discussed in our second lecture of html. Google 'netlify' and go on to their official website. You can either sign up or log in if you have an id. And then right click on your desktop wallpaper to create a new folder. We'll name it 'privacy'. And inside this folder Right click, subsequently click on 'create new...', 'create a text file', and then make a file named 'index.html'. In this step, you'll have to change the file including its format. If you cannot see the format of the file which is html You must check the box that says 'show file format' to see the file indicating its html format. Again, you should tick this box inside the 'View' menu. Then after you make it like this Drop this privacy folder into the Netlify's Sites menu. Then it becomes deployed and creates an address like this. The address is too complicated so we go to this site setting and by clicking on the 'Change site name' menu and name it 'jolappy bird'. We'll change the address to 'jolappybird.netlify.app'. So now that we have created with the address 'jolappybird.netlify.app' an 'index.html' file with nothing written in it so a blank page is shown. But now we have a jolappybird homepage, don't we? So copy this url and paste it into the Privacy Policy making site. and the implement date, fill in with the date you're making this. And then click on 'next'. And there's some mandatory sections as well as optional. Since we don't provide information to third parties or consign our documents, so we'll set them as 'will not state' and move on. Click on 'next'. And then tick the relevant boxes and fill in the content. We do not run a homepage nor manage membership, we don't do this- Provide content, that's for us, right? Hit 'next'. The period for retention of personal information, since we do not keep personal information by membership or such, so we select 'destruct without delay'. The basis of retention, we write as 'provide game'. Read this through and if there's no abnormality, click 'next'. If you click the search button of mandatory options There's nothing we collect, right? So we just have to move on, but they insist we select an option So we tick the Record of Service Usage and put it up. And we move on. And for the destruction method, we implement a technological method that does not allow reconstruction. We tick this and move on. We also finish this part with a ticking periodical self-examination. You can check whether you'll use cookies or not. We do not, so we'll tick this on and move on. And then we'll have to write down those responsible for Personal Information. You can just skip this step. Check it again, and then click on 'next'. We do not have previous records, so we'll delete this part and move on. Now we see the options we've checked became a Privacy Policy text and is shown right here. Click the download button to download it. The html file we downloaded, which is about the Privacy Policy we'll right click on this to change its name to 'privacy'. Now you put your privacy.html file into this 'privacy' folder you made when making a privacy site. Now we have this folder that contains both index.html and privacy.html files. This folder goes to netlify again, into the Project, we made on netlify that we just deployed Go to the Deploys tab and once again drop this folder here. And now the update will begin. If you go back to the site, after the url we can go onto our newly made 'privacy' page and we can see that the Privacy Policy we just made is perfectly registered like this. So now we'll copy this url and paste it into the Privacy Policy page of the Console. Then hit 'save' to save it. So our privacy policy is now all set and if you go back to Target Audience and Content tab because our privacy policy is all settled we can now check all these boxes. After you check all these boxes hit 'next' to confirm it. We do not collect sensitive information on this app, so 'no'. We check this 'We comply to all regulations' and go on. And since we're going to use Google AdMob Because the Google Admob is one of the providers that is in Google Play certified ad network Check this, and move on. And let's participate in the 'app for family.' The category is a bit vague But let's go with 'brain game.' And save. Go back to the dashboard Click on the news app. This app is not a news app So let's check 'no' And go into 'COVID19 contractor tracker app' This is not a COVID-related app So click on 'no' and save. We're almost there. Click on 'Select app category and provide contact' It's a game, let's select a casual game. And the tag, Let's select the tags we think are relevant. Physics-based ones are pretty similar, so I checked on that. Reading the arcade tag It's the short game that aims for as much score as possible So I think it's similar. The description for casual matches, so let's check that too. Select like that, and let's click 'apply.' So we now have the tags. Next, let's write the contact to show at the store information. You only need to write the required email address. And external marketing. It's good to advertise it outside Google too, so check that And save. Go back to the dashboard, app setting, and finally Let's set the information to add on store. I've written some simple description of the game And some in-depth description too. I've written the basic information for store in English So I used English for description as well. Next, graphics. Add the app icon and the graphic image. The sizes of the images are all here. 512 X 512, 1024 X 500 There's that standard specification like this. So just as we made our app icon before, Use tools like Paint or Photoshop Fit the given size standard to make the app icon and the graphic image. So I've added the icon and graphic image I made. The video isn't required So if you have it, you could add it now Or you can just skip this. Next, let's add the screenshots. I have three screenshots of the game screen on the smartphone. And drag and drop into the screenshot section. Then as you see, the game screenshot is here. Tablet's screenshot, make it 1200 X 1920 for that 7 inch tablet And 1536 X 2048 for that 10 inch tablet screenshot. Or if you own a tablet You can make the screenshot yourself. If you added the image yourself Save. And go back to the dashboard The basics are done here Click on 'Tasks' under 'Add the app on Google Play' And do each. Let's select on 'Country and region' And you'll select the region you'll release the game. Click on 'Country and region' And tick the first box on top And you can release it for the entire 176 countries. I'll click on 'all 'for 'country and region' to release the game. 'Add' for adding the countries. Next, click on 'make a new version' to the right top. And upload 'app bundle file.' It used to also allow APK files too But now they only accept AAB files. Drag the file you just made And upload it here. Then you can see how it fits right in. Add and save. It saved alright, click on 'review the version' and run it. Click on 'release as the production track' at the bottom. And click on 'release' So it's ready to be released It shows 'reviewing' So before your app is released or updated You go through the reviewing session. When you first upload yours at Play Store It usually takes around within 7 days. After one day, my production status is activated. Click on 'see at Google Play' And you can see that it's on Google Play Store now. Next, using the Admob, Ad Network at our app To add the advertisement. Let me talk about what Ad Network is Ad Network is, the platform that connects the corporation that wants advertisement and the app developer. The corporation that wants the ad, they post the ad they have For instance, Google, They upload the ad through Google Ads And we use Google AdMobs To allow the corp-added advertisements on our application. So the medium service of ad Is called Ad Networks. We'll be adding advertisements using Google AdMobs. Later, using Google Ads We could be the host of the advertisement So we will also add our game advertisement To Google Ads later too. Google has Ad Network services While Facebook or Unity Ads have their services too. But for us, we'll be using Google AdMob. The reason we're using Google AdMob, Looking at the market percentage in the global advertisement, Google is 21%, no.1 in all countries. That's how much advertisement it's getting from corporations, right? So, even when many customers use our apps If we lack the advertisement we may not be paid enough But since it's no.1 in the market, we'll be able to get our profit, right? And as many people use this, It has a lot of related guides And when we encounter an error There are more people with the same problem This means we can find the solution easily on Google. So let's use Google AdMob To add advertisement to our app. Let's first register to AdMob. Go to admit.google.com And you get this AdMob homepage. I'll leave the link in the description and the comment. Go to AdMob Register to the right top To register. I already am registered so I get this If you're not yet registered in Please refer to my previous video to do that. If you log in after the register You get this screen. Click on 'app' to the left menu And 'Add app' And you get this screen to add the app. Since we used Android as our platform Select Android And since we added the app to the App Store Click on 'Yes' And 'Continue' And either add the url of the added app store Or you can search to find yours. If yours is just added, it won't be found with the search In the beginning, you can only access it with the link. Copy this link here to enter And search you can see the app here. Add here 'Continue' Next click on 'Add app' And let's set the 'app-ads.txt for app' For the app we added. We need this because We need a certification saying 'I'm the certified seller of this app' To do that, make the file app-ads.txt And upload on my website. In order to make our own privacy policy We made privacy called 'index.html' and 'privacy.html' Right click, make a new one And create a text document. And name it 'apps-ads.txt' And open the Memo And click on this 'how to set app-ads.txt' Copy that Paste in your 'app-ads.txt' and save. In addition, we don't have the publisher ID. If you get the publisher ID, you need to update this. You can check your publisher ID at AdMob setting And it looks like this with all set. And then go to the developer website and add our site address. For that, go to 'Netlify' that we used For our privacy policy And go to this site we made 'jolappybird' and go to the tab 'Deploy' And this folder 'privacy' with this 'app-ads.txt' added For another deploy. And then, go to this site and add '/app-ads.text' And you get this. Now add the site to our website. To do that, go to Google Developer Console Go to the left 'store setting' And you get the 'store register information' And for this website, copy the website, The main website where we added 'app-ads.txt' And paste to this website. And save. Then, the app's website is this And we also set this 'app-ads.txt' at AdMob So we're certified as the 'seller that rightfully' 'Owns this app.' That's how you go on with the AdMob ad. Next, let's do the ad unit. 'Create ad unit' And make the ad unit. Ad unit means, there can be a banner ad to our game Or the whole ad that covers the entire screen Or there could be a reward after the ad The reward whole-screen ad Or something similar, but the player can choose to see it The reward ad And the native advanced ad, This means the ad I can fit the app design Or the ad when the app is opened. So each of these ads Are called ad unit And I can add that to my game. Let's add this basic banner ad and the whole-screen ad For this class. If you can do these two The others aren't that difficult, so for the sake of learning We'll be adding these two. So let's start with the banner ad. Select banner ad. And name the ad unit. I'll name it as 'lower banner 1' Open advanced setting You can choose that type of the ad 'eCPM' is the minimum price you can get, you can set it here too But it's the best to let the Google optimize it. So you don't really need to touch that advanced setting Go right into 'create ad unit' Then you have the ad unit And an app ID for that app And we have the ad unit code called 'lower banner 1' That we just made. So you need to add these things For adding that ad. So since we made one lower banner ad, Let's make another ad unit For that whole-screen ad too. The ad unit name, I'll keep it simple 'whole-screen ad 1' After you do 'create ad unit' you get the ad unit ID that corresponds To the one we just made, 'whole-screen ad 1' And I'll press 'complete.' Now, at Google AdMob page, I can collect the ad unit for the app Both of them together here. We should add the ad ID later So remember that it's here Let's go to Unity now to insert the ads. To add AdMob ad at Unity Google 'Unity AdMob' And you et that 'Google Developers' homepage That provides the guide on using AdMob at Unity. Let's follow along with this guide. Click on the first link. Then at Google AdMob There's a whole guide on installing and using Unity SDK. First, download the mobile ad Unity plugin And use it at Unity. To do that, click on 'plugin download' at the bottom And you are redirected to the Github page The version may vary But you get the latest Unity Ad plugin. then, down there, at 'Assets' Download the file named 'GoogleMobileads.unitypackage' This version may be upgraded a bit According to when you're downloading it. If you want to try the older versions since yours isn't working, There's 'Release' on top And click there to check out the older versions To download the version you want. We'll be downloading the latest one at the moment, The 6.12 version. Download the 'Unity Package' file. Download the AdMob package. Run Unity Editor, Drag and drop inside the Assets folder And you get this automatic package import screen. Now click on 'import' to your right bottom And it imports in the packages Needed for AdMob at Unity automatically. You can click on 'Go Ahead' so that It upgrades the things that need API updates on its own. If you want to keep this file in case something happens, Cancel, copy this file And then run to keep your original file. But this much of a game won't have that big of a problem So I'll click on Go Ahead. And we get some folders here That's the completed import. After the import, you get this warning message. It's about whether you want to share the log for the plugin called 'External Dependency Manager plugin With Google And I'll do that. Click on Yes. And the function called 'Enable Android Auto-resolution' It's saying whether you want it or no This is a function that automatically runs the library-related dependencies I'll say 'Enable' There's an error while they do the Auto-resolution. Checking on it, it says there's no setting for JAVA HOME at PATH. Then, I can install JAVA Regarding JAVA HOME to automatically add And I've never installed JAVA on this computer So I don't think they have the environmental variable here. Then I'll do the manual JAVA HOME environment variable setting. Open 'My PC' at your Search Right click, properties Go to the 'advanced system setting' to your left And click on 'environment variable' under 'advanced.' Then you can manually add the environment variable. 'Add New' And I'll name the variable JAVA HOME And 'Find Directory' at the variable number 'Edit' and around 'Preference,' where The JDK is set. 'Copy path' to copy the path Or you can manually go in there. Select this 'OpenJDK' path And 'Yes' And you get the route here. And 'Yes' here And 'JAVA HOME' has been set as the JDK route well. And 'Yes' to save. Next, to do the 'Auto-Resolution' again Go back to 'Assets' And go to this 'External Dependency Manager' And 'Android Resolver' here And click on 'Force Resolve' here. Then you'll be re-doing the process from before. Since the JDK route has been set You can check that it's working well. Then regarding 'Android Dependency' The resolution is successful, it says. Click on 'OK' to finish. Now we're all set to use Unity AdMob. Since the plugin is all set Let's move on to the next one. Then importing plugins is done Now you need to set the AdMob app ID. Unity Editor, inside Assets Get to 'Google Mobile Ads' Into 'Settings.' And then to the right screen, 'Inspector' And 'Google Mobile Ads' and you get the space to enter in the app ID. You add your Android and IOS ones. For Android, when we add the app to the Google AdMob we registered in before, You get the app ID here. Go to 'app setting' to the app you added And you get the app ID here. Copy this and put it in this 'Android' part. And we don't have one for IOS, but we don't want it empty So go to the 'Google Developers' homepage with the guide to add AdMob And there's the App ID link to 'App ID Setting' Click on that And you get the explanations Regarding the Android IOS app ID merge. Go to 'IOS app merge' and you get the sample App ID. So let's copy and paste that for now. And save. Since the AdMob App ID setting is done Let's add the banner ad. In the left 'Ad type' click on 'Banner' 'Start' to follow along with the guide here. First, you need the banner view. Then, with this code down here, Let's make the banner view. Then we need to make the game object Where the ad script will go in. Inside 'Hierarchy,' right click, Click on 'create empty' And let's make the game object called 'AdMob.' And click on 'Ad Component' 'Bottom Banner' Let's make the script for that. 'New Script,' 'Create and Add,' to make the script. And let's copy this code in this script to d this. First, it says we need to use 'Using GoogleMobileAds.api' Copy that, into 'Using' And copy the scripts inside the class. Copy like this And paste inside the class, the same thing. Then delete '...' We can't have two 'Start' So let's delete one 'Start' And make a variable called 'Banner View' Add the code starting the MobileAd to the 'Start' variable 'Request Banner' Is in there, the code requesting the banner. So 'Request Banner,' according to Android or iPhone We've made the ad unit ID AdMob. Change that, and there's the sample code to make the banner view. And the basic ad unit here Is the test ad unit. If you use the actual ad ID that we made for this ad unit You may be suspended. So you may be banned from using AdMob. For developing, you shouldn't use the actual ad unit ID You should use the sample, the test ad unit ID So that they know that it's for the test So that you don't get banned. If you add the actual ad unit ID You may be paid when this is clicked So you can't be paid like that, right? So for testing, you should always use the test ad unit ID. So please leave that as it is Never change it. Let's apply this for now. After finishing that code Moving on, you can set the personalized ad publishing rank too The ad size too, using the variable called ad size You can change its size too. And as it's here, you should always test it with the test ad. So if you add the real ad, even without clicking on it Even with it begin exposed you may be banned. So please remember that Never use your actual add ID. Now, to write the code to load the ad The upper one's already there So copy the two lines of code at the bottom To paste it below our code. But see here, inside the banner view add Put in Ad Unit ID and size And 'Ad Position' is 'Top here. Here, when the ad appears at the top It may be very annoying with the score, right? So I'll set the Ad Position not to top But just '.' to autofill. At here, 'Bottom' I'll make it come out on the bottom. Select 'bottom' and save Then save the editor, and if you execute the game, it will run like this, and you will see the banner at the bottom The size of the banner is too small, right? So let's modify it and increase the size. We need to modify the part called 'AdSize' that we used when we created banner view. As shown here, we can change the size of the ad with 'AdSize' in the banner view for detailed information, there's a link here called banner size reference, and if you click it, it tells you detailed information on how you can set the banner size. So you can use the ad banner with a certain size Here, it only says 'Adsize.Banner' Banner is 320 x 50 You can change this to a large banner, or you can change the banner type to an adaptive banner or smart banner If you look at adaptive banner, the banner will be fit to the screen size, and you can see the adaptive banner here. Let's try it out There's a sample code at the bottom. Let's copy all the codes up to deleting the banner and use it right away Let's copy it directly and paste it in the part that creates the banner view Then we delete the banner if it's there and use the 'adoptiveSize' adaptive banner and change the size to 'Fullwidth' and change it to the full size on the screen and create the banner view. Change the setting like this and save the file Go back to the editor and if you execute it, the ad is now 'Adaptive Banner' and it will be fully scaled to the size The size is about right now. Since we are finished with the banner ad, let's add the Interstitial ads as well If you click the Interstitial ads it tells you how to create it If you think what would be the right timing to add the ad, it would be after 'Game Over' and when you click 'Replay' button. Then the ad will pop up, and if the game restarts after the ad, it won't interfere with the overall flow of the game, and it will be the right timing for the ad, right? Go back to 'Scenes' and go into 'Game Over Scene' Then, let's code for the ad to pop up when the 'Replay' button is clicked on the 'Game Over' screen, and when the ad closes, the game restarts First, the bottom banner can stay as it is in the 'Game Over' scene, right? Then copy AdMob in the play scene, and paste it in 'Game Over' for now the lower banner will appear. In the 'Game Over' scene, we brought the initialize function as well. Then the lower banner will be the same so let's save and check. In 'Game Over' screen, we can see that the banner works properly. Now let's code for the Interstitial ad to appear when we click 'Replay' and go back to the game To do that, inside the replay function, we need to write the code that will pop up the ad. Now, when we click 'Replay' button it's set to run 'Replaygame' function inside the 'Replay' script. If you check the script, the function will run when you click the button, and the scene is changed. So instead of changing it right away, we will let the scene change after the ad is popped up Let's make the Interstitial ads pop up first Go back to AdMob guide and bring the code directly. Likewise, paste 'using GoogleMobileads.api' inside 'using' and copy the code and paste it inside class. Change the indentation with tab, and likewise for the code below, you can add the code that loads the ad. Copy from top to bottom and paste it at the bottom Likewise, let's change the indentation Then, we have completed the function that requests for the Interstitial ad, and let's copy the name of the function to change the screen to the Interstitial ads instead of just change the scene We will comment out 'SceneManager' and make it into a code that the computer can't read and write the code that requests for Interstitial ad, and execute it. If we look at the guide, we need to include the code 'Interstitial ads.show' for the ad to show on screen. Let's copy the code and paste it at the bottom We completed the code that 'requests for the ad, and when it's loaded, show' Next, go back to Unity, save the file and execute it. You can see that the ad pops up properly when you click 'Replay' If we 'Close Ad', nothing works at the moment. Let's set the game to restart when you 'Close Ad' We just need to utilize Ad Event Ad Event lets you set what will happen when an ad screen has been requested, when the ad shows or the request has been failed, or other various actions such as closing the ad, when it's clicked, etc. We need the game to restart when the Ad is closed, so let's use the code that calls an action when the ad is closed, 'Called when the ad is closed' Copy this code and paste it below the part that creates Interstitial ad, and organize the spacing. We also need to set 'HandleOnAdClosed' function At the bottom, you can see 'HandleOnAdClosed', right? Copy it again and paste it below 'ReplayGame' function We have an error message for 'EventArgs' This is below system, so if you change it to 'System.EventArgs', the error message will disappear Change the code, and when you close the ad, 'HandleOnAdClose' function will run In other words, you can write the code that you want to be executed when the ad is closed. Delete the default code, and undo the commented out 'SceneManager.LoadScene' from before, cut it out, and paste it inside 'HandleOnAdClosed' Just organize the codes, and now, when you click 'Replay Game,' you will see the ad, and now we have 'HandleOnAdClosed' function, when we click close, the function will run and the scene will be changed to play scene, and the game will restart Let's test if it works Save the file, execute on Unity Let's test it When we click 'Replay,' the ad will pop up, and when we click 'Close Ad', the scene changes again, and you can see that the replay works. We have the bottom banner, and the bottom banner on the 'Game Over' screen is also showing well We created a structure where the interstitial ad pops up when we click 'Replay,' and the game restarts when we close the ad The way we put in the ad is not the only way, and you can include various ads according to the flow of your game, to places where it doesn't interfere with the game We ran into a problem, where the interstitial ad doesn't pop up even if we click 'Replay' on our Android smartphone Let's fix that In the script that we wrote for replay, it pops up the interstitial ad, but when we run it, the ad pops up, but this canvas, The Sort Order is 0 on the initial screen and the Sort Order of the ad on the screen is also 0 They have the same order and we didn't decide the Sort Order so 'Game Over' canvas can come on the top That's why the ad might not be showing like this. So you always need to have higher Sort Order for the ad than the canvas You can adjust the Sort Order of the ad, but you can also set the Sort Order of the canvas to -1. Then, we have both the interstitial ad and bottom ad in the front, so they will both be visible. Then let's change the Sort Order of the canvas to -1 To do that, open the replay script import 'public Canvas' and name it 'myCanvas' Since it's public, we can see 'myCanvas' on the replay script now Then if we drag the canvas that displays 'Game Over' screen, to 'myCanvas,' 'Game Over' canvas is now in 'myCanvas' After saving the file, we can change 'myCanvas.sortingOrder' here below the 'Show' code that shows the ad Let's designate 'sortingOrder' to -1. Then the canvas would be -1 and both ads will show Let's save it at this point. If you test it out, then the lower banner is showing properly, and you can confirm that the 'Sort Order' has changed to -1 But even when I did that, the ad was not showing, so I searched on Google, 'unity admob interstitial ad not working' and in the Q&A document They say that it takes up to 3 seconds for the ad to load So it worked well during the test, but in the actual web, it takes 3 seconds So in the current code, it's set to show right after the request so the ad doesn't have the time to load, so the if statement is skipped over So I looked up the solution and I found that you can write the code like this When I took a look at the code below, there's an improved version of the code and I'll use it. Let's copy the whole thing, and let's comment this out for a second, and paste it inside Then let's organize the lines a bit, then request the interstitial ad with 'RequestInterstitial' and start the Coroutine called 'StartCoroutine' and repeat the IEnumerator called 'showInterstitial' This is the code If the ad is not loaded, there's an exclamation mark so it's the opposite The code is 'execute this code if not loaded' Mark the message 'Debug.Log' and wait 0.2 seconds. That's what the code is We don't need the 'Debug.Log' message so let's delete it After the interstitial ad shows, we need to change the order of the canvas Let's add the code to do that, and complete the code I'll erase the previous code Then the ad will be requested once, wait 0.2 seconds, and when loading is complete, the ad will be shown We have revised the code so let's build it again and update it. But before that, there's a test ad ID in the script of the lower banner and the interstitial script When you distribute the app, you can just change the ID to the actual ad ID. We have the ad ID for the banner ad and interstitial ad inside the ad unit that we created on AdMob So click the copy button from the bottom banner, copy the ad ID, and put it inside Android 'BottomBanners' Let's save the file In the interstitial part, copy the ID of the interstitial ad, and paste it in Android and save the file The important part here is that even if you test it on your device, if you see the app and click it, this will be considered as a fraudulent act, and your account may be suspended Please be careful. Even if you test your app on your device, you put in your ad ID, so we need to set the test device, so that this traffic will not count Register the test device, and then you can use the device to prevent your account from being suspended Let's register the test device together First, go into AdMob website, and go into setting on the left menu Go into the third menu, 'Device Test.' Let's click 'Add Test Device' You can now add a test device Freely name your device I'll name my device as 'Galaxy A32.' The platform is Android, and it tells you how to find ad ID How to find the ad ID is, go into the settings on your Android smartphone There's a menu called 'Google' If you go into the 'Ad' tab, you can find your ad ID in the 'My Ad ID' at the bottom You can register this After putting in the ad ID, you can add ad test device If you add 'shake the device' you can check if the ad is working properly by just shaking your device I set it to 'shake' and I will save the file Your device has been registered as the test device You need to add the test device for the app to be tested properly If you do not add a test device and test your app, if the ad is exposed, your AdMob account will completely be suspended and you might not be able to recover it So you must register your test device before testing it When you are finished, build the revised app again, and upload a new upgraded version To do that, go into 'Build Settings' Then go into 'Player Settings' Then at the bottom in 'Identification,' you can change the version and the version code You must change the version code for the update to be reflected If you build this directly, it will be considered as the same app, and Play Store will not recognize the update and there will be a clash So you must change the version code to '2' You don't have to change the version After changing the version code, as you have set in the previous build, I am told that you must target above 'Android 11 API Level 30' When you are done with the settings, let's build it in the Android smartphone Use the USB and connect the smartphone, and in the bottom right corner on 'Build Settings' press 'Build and Run' to create aab file, and use the USB to build the app on the Android smartphone You can see that when you run the app on your phone, the bottom ad is displaying well, and when you click the replay button, the interstitial ad is showing well, and when you close the interstitial ad, you can check that the replay works properly as well We are finished checking the app, so let's update it on the Google Play Store The ad might not show for some of you, and it's because it takes 24 to 48 hours for AdMob to review the new update So the review needs to be complete for the ad to show properly Let's update the app When we update the app, we can release it right on the Play Store but you can also test it internally for limited number of people before launching it Let's find out how to do that Move to the app on Google Play Console, and go into the 'Internal Test' menu on the left menu, 'launch,' and 'Test' Press 'Create New Version' We can upload the app bundle here Let's upload the app bundle Press 'Save' and press 'Version Review' Press 'Start launch as Internal Test Track' you can run the version that's provided to the internal testers without any reviews when you click 'Launch' To test the app, go into the second tester tab and add a tester Press 'Create e-mail list' and let's create a test list called 'Jolappy Test' Input the emails of your friends and colleagues that will participate in the test You can add Gmail address After adding it, save the changes you can create the list Select the email list, and press 'Save Changes' at the bottom right. If you give the tester the url link that's created at the bottom with how to participate, If the friend or colleagues are added through the link, they can install the app internally before launching it on the Play Store and you can test the app If you open the test link, this screen will pop up along with the invitation message If you click 'Accept Invitation', another message will show that you are participating in the internal test and you will see 'download it on Google Play' link at the center If you click it, you will be guided to the Play Store Page where you can download the beta version Then you can press 'Open App' and you can download the beta version on the Play Store After checking that the app works properly with the test, you can select the version that's without any bugs in the 'Launch Internal Test' tab, and press 'Promote Version' at the bottom right If there are no problems in the test, you can convert it to production right away and release the app Then let's press production and promote the latest version to production Press 'Review Version' at bottom right and press 'Start Production Track Launch' and 'Launch', the tested and reviewed version will be released on Google Play Store as a public version Once Google's review is complete, the app can be officially launched After being launched if you search the app on Play Store you can check that the app is showing properly If you install and launch the app, the game will be playable, the ad is working properly, and the interstitial ad is also working properly If you want to promote the app so that a lot of people will use it, please refer to the next lecture If you found this helpful, please click subscribe, like and turn on the notification alarm. Thank you.
Info
Channel: 조코딩 JoCoding
Views: 1,990,676
Rating: undefined out of 5
Keywords: 플래피버드, Flappy Bird, Unity, 클론 게임, 게임 만들기, 게임 개발, 게임 개발자, 유니티 게임, 유니티, 코딩, 게임 코딩, 유니티 강의, 씨샵, C#, C# 개발, 게임
Id: EqoU1PodQQ4
Channel Id: undefined
Length: 204min 9sec (12249 seconds)
Published: Sun Jan 23 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.