Learn Game Development From Scratch with C# Unity | Kerem Aydin | Skillshare

Learn Game Development From Scratch with C# Unity

Kerem Aydin, Software Developer, Unity Developer, Gam

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
21 Lessons (1h 57m)
    • 1. Installing Unity

    • 2. Installing Android SDK ( Software Development Kit )

    • 3. Creating A Project in Unity Editor

    • 4. Using Sprites Pack & Asset Store

    • 5. Using Physics in Unity

    • 6. Creating Prefabs

    • 7. Scripting in C#

    • 8. Unity Default Functions

    • 9. Writing First Function

    • 10. Using Unity Input Functions

    • 11. Camera Script

    • 12. Game Manager

    • 13. Game Over

    • 14. Scoring with Coins

    • 15. How To Create New Scene

    • 16. Adding UI Components

    • 17. How To Save Data

    • 18. Test Your Game

    • 19. Monetise the Game

    • 20. Building The Game

    • 21. Audio Adding

12 students are watching this class

About This Class

Hi everyone,

Welcome to the my "Learn Game Development From Scratch with C# Unity " course.

Gaming on the Go

Mobile games have a long way since Game Boy, but like any game on any platform, mobile games are made to keep us having fun.  

This time you will not just play and enjoy but also learn to create video games with Unity C#.

My Unity course utilizes a unique teaching method which will allow you to gain a thorough understanding of concepts. If you interested in game development with Unity and C# and is looking for an interactive, project-based course then my course will be a perfect starter for you to develop your own games.

By the end of this course you will learn to;

  • Navigate the Unity Engine and discover unique features like the Asset Store
  • Detect collisions, receive user input, and create player movements
  • Collect and destroy game objects
  • Build 2D Unity games & work with sprites
  • and also you will gain confidence in translating theories of physics into working game code

With my Unity course you will also have a brief idea regarding the gaming sector. As the mobile is set to be the dominant trend for the foreseeable future, I believe the same can be confidently said of mobile gaming as well.

If you want to start a new career or if you want to have a new hobby which can turn into a profitable business in a short-term then do not wait!  

Dive in now, you won't be disappointed! 

Because by the end of the course you'll be very confident in the basics of coding and game development, and HUNGRY to learn more.



1. Installing Unity: game development with unity. Hello and welcome to game development with unity. My name is Kareem. I didn't I am unity developer and a game designer. Now, throughout this course, you will learn how to use the Unity game engine, how to code with C sharp programming language and how to monetize your game with Google Ad Mom Matt and how to build your game for IOS and Android devices. I'll use a Mac book for game development, but you don't have to use Mac exclusively. If you have a windows computer, steps will be generally the same and maybe some small differences which aren't so important . Firstly, you'll need a download unity from their website. So to find a website, you can write Unity, unity, three D or Unity game engine or something similar into Google. You'll find it. Ah, I always find that the first website will be unity three d dot com, and you need to enter this website to download unity. You see the download link and directly go to the download page from Google and at the Unity Website. You could also see the get unity buttons that will take you right to the download page. So on the download page you'll see the Choose your unity plus download button and click this button to go to the Unity Options Page. Then you'll see different unity options to download The 1st 1 is free and the others of the paid options. But don't worry, because all unity versions include core engine futures, and you don't need to pay any fee toe, learn unity and to make your game. So, therefore, just choose the personal and on the next page, click to confirm the terms of services. I've already read it to us for you and then download the unity installer So on the download's finished, Go to the Downloads page and find Unity. Download assistant over in the Unity download assistant by double clicking it. Now you'll see an introduction, a unity download, click on next, and then you're gonna see the license and accept this to continue. So in this next section you will see the unity components to download. At this point, you should definitely choose android build support and IOS build support, since we're going to develop a mobile game. In this tutorial, Siri's also don't forget to choose mono develop, since we will use modern develop to code in C sharp programming language. Now, I also suggest to choose documentation, standard assets and example project, since since he's gonna be useful components to help us learn unity, also confined the documentation in its website. But if you work off line with the unity, downloading the documentation is gonna be a lot better. Obviously, you don't have to log on every time you spark it up, so the other options are up to you. If you think that you will work with unity to make a game for the Web, you could also choose Web G L support. But we're not going to cover that necessarily in this particular course. Next, choose a destination point for unity, then continue to download the download. Install will take a few minutes, cause that just depends upon your Internet speed. 2. Installing Android SDK ( Software Development Kit ): and now you're done. Now you have a great tool to make your own game. But to make a game for android devices, you need to download android sdk. As you know, software development kit means a whole set of software development tools to allow the creation of applications for a particular platform and Android distribute its own sdk for android development on easy Way to get Android SdK is to download Android Studio well, pretty much. Take the same steps to download Android studio. Just act an android studio to your Google Search bar and you will see the Android website to go to the website and find the download link for Android Studio. And again, when you collected down the link, you will see terms and conditions for Android studio except this by clicking the I have read and agree with the above terms and conditions and then download Android Studio is also take a few minutes according to your Internet speed, and after that's complete, install Android studio and open. When you first open the Android studio, you will need to create a project since we need open Android studio to get android SdK. Application options are not important. Give a name to the project company domain and choose a destination for the project. On the next page you will see a P I options for different android devices. But we don't change anything here Since we don't need to just click next and in the next page just select an empty activity. And on the next page, just click the finish button And now Android studio is really open. So the top center, you will see it down Arrow, which is sdk manager. Click this button to open sdk manager And when you open sdk manager, you will see a system settings under the appearances and Behavior section and now choose android sdk toe first at the top you'll see the android sdk location and ah, why don't you copy us to a sticky note or however you stay organized since we're going to use this later in unity and you don't want to have to go back and chase it down Now choose an android, a p I for android development. I prefer a V I 25 which is android 7.1 dot one newgate to install. You're probably gonna think that well Why didn't we just choose the latest one? And I will answer you by saying I prefer the one before the latest version, not the latest version, since sometimes you might face Ah, major bug with some of those later versions that developers just haven't recognized yet or haven't solved yet. Um, so anyway, there's no real big difference with the latest one and the previous one before the latest eso. I will generally choose the previous one before the latest to avoid facing any of those major problems. Because you know what? Let's just design a game. So now go to the SDK tool section to select other important parts or android development. In this section, click android SdK, build tools, android sdk, platform tools and android SDK tools to download. You don't necessarily need to select the other option is gonna be aware of them if you wanna have a look, but now click. Apply and confirm the tools to download Download is done. Click finish to close the download window and click OK to close sdk manager. So we're done with Android Studio. The next step is to install Java development kit, since Android Studio is using Java programming language for development will also need J T . K. So go back to your browser and now right J. D. K. Into the Google search bar, and you will see the website at the top. Go to the website and you will find that J. D. K. On this page. So same things we did before will select the previous version rather than the latest version. Collect the download button and accept license agreement to download, Choose a suitable version for your operating system and download and install it with the default options. 3. Creating A Project in Unity Editor: So this is the unity editor. Now We're ready to open unity to start game developed. You can create an account to open unity or you can work off line. To have an account is necessary to use some of the unity services such as analytics, but we won't use any services in this particular project. So therefore, you can work off line throughout this course, maybe a little information about this first window at the top, right? You will see project and Learn sections. Project section shows your last open projects in unity, and you can see the path and the unity version. Bath is obviously your project path, and the unity version means that your project is opened with this unity version, most recently on disk shows your project on your computer and in the cloud shows who collaborated projects with your team members. Learn section shows some tutorials, complete project and useful resource is for unity. You can use some of these projects for your further learning process. Now the top left, you will see new and open buttons, so let's click the new button to create a new project given aimed here project and choose a location. Choose to D rather than three D at this point, since we will develop a to D game now, later on, you can add some assets by using the ad asset package button, but right now we won't use this feature. Also disable Unity Analytics and click the Create Project Button. So now you see different windows for game development. But which one is for what? Let's have a look. Look at the scene window first. This is your workspace to add game objects. Cameras light you Y elements, graphics, etcetera. You can change the view with the buttons at the top. Right near the scene, you will see another window called Game. This is how your game looks when you run your game. If we run the game now, we'll only see a blue screen. You can change resolution with second button at the top. Right now, this is the free aspect, but we could make it stand alone, which is 10 24 by 7 68 And now we can add a new resolution whatever we want. For example, we will develop a mobile and let's add a new resolution of 10 80 by 1920 now look at hierarchy. This is to show all elements in the scene, for example, Now we have only main camera and are seen by double clicking and Mac and right clicking and windows. You can add new game objects to the scene. Also, you can see child parent relationships in this part, so click the main camera at the left and look at the inspector window. This window shows selected game objects, features and components. Name, tag and layer are some important features for a game. Object transform is a component which all game objects have. This shows the position, rotation and scale of the object. The other components are specific to camera object, and you may not see for the other game object. On the other hand, you can add new components by clicking. Add component at the bottom. Look at the project window. This window shows all elements you will use in your game. Project Assets folder is a default folder, and if you want to use an object in your project, it should be included in the Assets folder or in a folder within the Assets folder. Now you can search an object you're looking for with search. You can also use favorites to access easily some of the objects that you use all the time, such as all of your materials now near the project window, look the console window. This is another useful window for game development. UNC logs that you want to print warnings and errors in this window. You also select what kinds of logs you want to see by clicking the buttons at the top left . For example, you can de select logs if you only want to see errors and warnings, or you can select only errors. You didn't clear all logs if you don't need to see any by clicking the clear button. Or you can click clear on play to delete all logs when the game is started up. So at the top you see some header buttons, which are also useful for some unity features to modify your unity project. So in file, you can open a new scene and save your scene, or you can save your project in window. You can add other unity windows to lay out, or you can change your layout in help you access the unity manual and scripting reference. We're going to be using these buttons when we need to throughout the course is at the top, right? Can you see the layout button to change the layout? This layout Is it the fault? Lay out when you create a new project, and you can change this with this button. On the other hand, you could make your own layout by changing positions of windows, and you can save your custom layout. 4. Using Sprites Pack & Asset Store: preparation for development to work systematically and easily find all objects. We will create some folders for some different things. So now let's create the scene's folder under the Assets folder. To do this double click on the Assets folder for Mac and Right Quick on Windows Select, Create and folder. Change the name to scenes now Savior Seen in the scene's folder. You can save your seen by clicking file Save scene, or you can use hot keys to save something. Use Command s for Mac and Control s for Windows. Give a name to your scene and select the scenes folders. Save now. Find some useful assets for your game. You confined graphics, sounds or other assets on different websites with free or paid options. Unity also has a very big asset store to find many assets for games. So now open the assets store to find graphics for your game. You can have the assets store to your layout by using the window button if it doesn't exist in the current layout. So once you're in the asset store, you can search for anything you need. I will write sprites pack to find the pack that I'm looking for. You can filter your options. Let's choose free on Lee to eliminate paid options. Click to T Sprites pack and the publisher is Unity Technologies. So if you didn't download anything before the assets store, you will see download button. Otherwise you will see import button, So click, download and then import. So now you see the sprites folder under the Assets folder You can find some cute graphics to use a new project. Um oh, I'm gonna choose Bird Hero Underscored zero For my character, you can search by writing Bird Hero underscore zero or you can find it if you open bird hero Sprite Dragon, Drop this bright to hierarchy and and double click To make it an object in the inspector window, you can change the name as player or whatever you want. Also, you can change the position, rotation or scale with transform component 5. Using Physics in Unity: using physics, we created our first game object, and now it's time to add some dynamics to the game object. We will create a character which falls normally and jump when clicked on the screen. First had gravity to the game object. To do this, we need to add rigid body to D component now to add this component, click add component and you'll see that there are different features, such as physics or physics, to D. We will create a two D game, and therefore we will always use two D features. You can see different components to add, and there's a way to add the component you want. Another option is you can search by writing the components name. You can write rigid body to D, and you can add this component so richard body or rigid body to D or similar components with some different features. Obviously, rigid body is for three D and rigid body To D is for two D development. The rigid body component is necessary to enable game objects to act under the control of physics. As you can see, there are different numeric features that we can modify. We will modify gravity scale for the game. Object to fall down. When you increase gravity scale, the game object will fall with a bigger gravity force, and when you decrease it, it will fall with a smaller gravity force. Now the words it will fall down slowly. So now when we run our game, the character will fall down. Next, we want to make our character collide with other objects in the Game four game over or to collect coins that we had. Therefore, we need to add another component, which provides collision with other game objects. We will follow the same steps as we did before to add rigid body. So click add component and find Circle Collider to D To add that game object. I choose Circle Collider, since the game object shape is like a circle, but if you want, you can select Capsule Collider or other types right now. Modify the collider features. Let's decrease radius a little bit and make it 0.45 Then change offset a little bit to fit the collider to the game object. A little better exit. I think that looks good 6. Creating Prefabs: create pre fabs. So we've successfully created our game object, and what will want to do is use it for different scenes, or what happens if we accidentally deleted. So right now, we'll create a new folder under Asset and give the name pre fabs, then Dragon Driver Modified Game object to the pre Fabs folder. You can add your game objects to different scenes this way, or you can copy as much as you want without having to go back and creating objects from scratch so our main character is ready. So what about the enemies in the coins? Let's make some enemies for our game. Flappy Bird is a simple game that a bird is trying to avoid colliding with columns. So let's say that we need some columns to avoid colliding. To create columns, go to the Spice folder again and look for suitable sprites to use his column. I will use column sprite for this, and you can find me a surge in the Sprites folder. Dragon, drop this sprite to hierarchy and change position a little bit. Yeah, I think the scale is good, and I think I'll just leave it right there. We have a column tow Avoid. But we also need another column, since the character should pass between the two columns in the game. So copy the columns Sprite by double clicking and duplicate. Or you can use hot keys. Commander Control D. The new column also has the same rotation with the old one, and I don't think that this is what we want. So let's change the rotation of the column to do this. Change the Z rotation to, let's say, Well, no directly opposite at 180 degrees. So now the column rotates around Z axis about 180 degrees, and that's modified the position of the column by driving it up. Excellent. I have two different columns, and I will change their names to avoid confusion between them. Um, that's just simply change the name to call him up for the upper one and column down for the other. Now, on the other hand, you probably noticed the player seems a little too big for the game, so let's change its size by decreasing changes position as well, and make it close to the left side of the screen, since it will have to go to the right, and I think that would be better for the player. So we have our columns now, but we want these to collide with the player, so therefore we add colliders to these game objects. Box Collider to D is the most suitable one for these. And let's modify the colliders for a better fit. Now we don't need to add rigid body to these game objects, since we don't need these to act under physics, for instance, you know the gravity like we did earlier. So now let's save these game objects also in the pre fabs folder. Okay, great next. Create coins for scoring, so find coin sprite and sprites holder and drag and drop this sprite into hierarchy window . I want the player to collide with the coins, but also I don't want coins to act under physics. So therefore, I'll only add a circle collider to D and select Trigger. Since the coins or the trigger for this game, 7. Scripting in C#: are a good job. Let's right the first script. So we create a character and enemies, but our character is only falling down. So we wanted to move to the right during the game and jump when we when we click or press the screen. So to do this in unity, we need to write some coat Unity is supporting three different programming languages, which are C sharp, JavaScript and boot. Most popular one for Unity is C sharp, and we will be using C Sharp for scripting. Unity is powerful libraries and functions for C sharp that you can use in every kind of game you create from simple mobile games. Two huge console games. So choose player object and add a new component as a new script and give that name as player. Now you can directly right player to search, and it will give you an option as new script at the bottom. It's another way to do it. So create a Scripts folder under Assets Folder and then drag and drop the flare script to the scripts holder. Let's edit the script to add some functions to the player object over the script. You can double click on the script on the project folder, or you could open by clicking settings, Icon of the player script in the inspection window so the script will automatically be opened with model develop, which installed along with unity. You can also use visual studio if you have that, but you don't need to install it, since you can always use modern developed. So we talked a little bit about scripting first lines of scripts, which are starting with the word using our name spaces, which basically are a collection of functions and classes. For example, system dot collections and system dot collections dot generic are common C sharp name spaces and used for many useful classes, such as a list or a ray list. Unity engine is used for specifically unity functions like Start an update. Now you can't use functions and classes if you don't call name space at the top. Also, we will use other name spaces throughout the course when we need them. The public word is an access modifier, which decides this class can be accessed from other classes or not, so this is set to private. Other classes can't access this class now. The class. Word says that this is a class and player is the name of the class. You should be careful about the name, since the name of the script and the name of the Project folder should be the same. Otherwise, the script won't work. Now it's time to declare some variable for our character. The player will jump when users touching the screen, and thus it should have a force variable. All right now, we don't need to access the other classes so we can now make a private variable type can be an energy or a real number. Real number may be better for force, and let's declare it as float. You can also use double to declare real numbers and unity. But now let's just juice float and you'll see what happened. Now the name will be force and give that some value Player also has a speed to move. Declare another variable called speed. This will also be a private variable like Force waas. But the variable type wouldn't be energy or float, since the speed would have both X and y components. We need something with X and y. Fortunately, unity has his kind of variable called vector to. So let's declare speed variable as vector to, and it will also be a private variable. Now let's declare a public variable player will have a score, which increases when it passes between column. This would be a public variable since we need some other scripts to access this variable to show up on the screen. So let's declare score variable as an integer, since it will increase by one for every path. And don't give it a value right now so that when the game starts, it will be zero. By default. Declare another public variable to publish your score onto the screen. We will declare score text to publish on the screen, and this variable should be accessible from other classes. Therefore, let's make it public good. Now we need to declare it as text type, but we can't do this now since text variable is in another name space and we need to add it to our script. So let's add it now you can find which name space is required to add text variable via Google search. We need unity engine dot you Why name space to add this variable and add this name space. Now there's no problem and we can add this name space to our class. Now we want to access rigid body to modify some variables. Such a speed from the script speed at a private rigid body to D variable and give a name to it. This variable also is a variable in unity engine name space. Great. Now, for all variables and name spaces, we need to add a semi colon to end. Otherwise, this would give us some serious errors and just wouldn't work at all. This is always necessary in C sharp. 8. Unity Default Functions: default functions. In a normal application, you can use buttons to call AP functions, and they have generally a main function to call another function. On the other, hand it in game, you need to call some functions maybe 30 times in a second, since the game is at 30 frames per second. Fortunately, Unity has already thought about that and has some useful default functions to use in these games. For exactly what we're talking first, the awake function is a unity function called after all objects in the scene initialized and before the game starts. This function is useful function for reference between script start function is another useful function called first when the game starts, this function is called before all update functions. This is a useful function to initialize values before the user starts to play. Now the update function is a function called After Wake and start functions. Both awakened start functions air called once during the game, respectively. However, the update function is called it every frame. Once, in other words, we have game at frame rate of 30 FPs. Then the update function is called 30 times a second. This function is one of the most used functions in unity and also it's very useful for functions, especially like the jump function. So we will use this function for the player to jump late. Update function is a function very similar to update function. This function is called at every frame just after update function. This function is useful for actions like the camera to follow the player. We will use this function as well for the camera to follow the player smoothly. Unity has some other functions for games, but these four functions are pretty much the ones that are most used, and we'll talk about these functions in our next tutorial. 9. Writing First Function: your first function. So we talked about unity functions. And now let's write your first function for the game. First, we want that the player will always move to the right. Therefore, we need to add speed to our player game. Object acts under physics if they have rigid body, unless we need to access the rigid body component of the player, then change its velocity. So we declared a rigid body variable. Let's equalize it to the players rigid body Now. To do this, we will use the get component function. Get component. Function is a function of the game object class and we can access other components of a game object from the script. Now we can access rigid body from a script, so let's change its velocity. The rigid body component has a velocity variable that we can modify, so let's make rigid body equal to the velocity that we already defined. Now it's time to write our jump function. This function doesn't need to be accessible. Therefore, we could make it a private function, and secondly, we need to write a return type every function returns of value after doing some processes where they are and then this type can be any variable, such as an inter juror float war game object. In this function, we don't need to return any value. That's our function will return. No. So let's write Void, which says function returns nothing. Excellent, then given name to your function and open round brackets in round brackets. There would be input parameters for the function, but we don't use any input parameter for this function. For other functions we will use in Paramus, then open curly brackets and now right processes that we want our function to do, right. So we want to apply a force when touching the screen and us. We also need to access rigid body. So the rigid body class has a function which is AdForce, and we will use this function to give a force to the player. AdForce function needs an input parameter to run and parameter type is vector too. So we want to add a vector which has X and Y coordinates, and why should be equal to one and X should be equal to zero. Since we want the movement to be up, we can write new vector 20 comma one inside But also we can use transform class to do this Transform class has an up parameter which is a parameter we want. And we can multiply this with our force variable. By the way, we only need to change force variable to modify the jump. 10. Using Unity Input Functions: the input functions. So we wrote the jump function and when we call this function are player will jump. We want to call this function while touching the screen. In other words, sending a call message to our game the ah using whatever hardware were using. So in other words, sending a call message to our game using hardware. Therefore, we need to use input functions to call the jump function. Unity has pre defined input functions to call functions while touching the screen or pushing buttons. You can use hardware such as a keyboard or a mouse to play games made with unity. And all of these games are which is in the unity engine name space. So to use a keyboard input in the game, you can call get key function of the input class, and you can enter any button on the keyboard as the input parameter to call the function. The function will return true any time the button is held down. You can also use get key down and get key up functions to call other functions with a keyboard, get key down. Function will return true once if the user starts pressing down and get key up function will return true once if the user releases the button so similarly, the get mouse button down and they get mouse up. Functions are useful input functions to use a mouse in your game. Now, for touchable screens like phones or tablets, input class has a different function called Get Touch. This function returns true if the screen is touched and if the number of touches are important for a game, this function is the best solution. But on the other hand, we don't need account touches. Since our jump function is pretty simple, it's just click and jump. Therefore, we can use mouse functions for our game to call our jump function. Let's use the get mouse button down function. We want to make it so that if the user touches the screen at any time, it just calls the jump function. Therefore, we will write our jump function into update function. You follow now. In addition, we want to add that the player will jump if and only if the user touches a screen. So we need to add a condition to the jump function and to do this, we will use if statements the if statement basically provides it. If a true returned in brackets, then the functions in if statement will be called. So let's write if and open round brackets well, right input dot get mouse button down function and parameter will be zero. This means that if the user starts pressing down the first mouse button, this function returns true and all the functions in the if statements will be called for mobile devices. If users start pressing screen, the same process will happen. Then right jump function in the if statement with round brackets and semi colon, your function will be called as soon as the users starts to touch the screen. Get mouse button functions are also useful to test your game in unity. Editor. Since you contest your game using the mouse when you run it on Unity editor, you can also find other input functions for other game platforms on Google Search, or you can find it in the unity documentation. For example, if you want users to use a game pad for your game, you can Google Unity game pad input and find some useful documents 11. Camera Script: All right now, let's have a look at the camera script. All right, so we've got it so that our player is always going to the right and jumping when starting to touch the screen. But there is one important problem here. The camera is not moving with the player, and thus the player overflows. So we need to avoid this, and the camera should follow the player. A simple way of doing this is to make the camera as a child object of the player. So now the camera will follow the flare during the game. But this is not the movement that we want. So since in our game, why position of camera should never change and it should follow the player through the Exline. Ah, so therefore, let's try it another way. Let's go to the hierarchy and at a script to main camera using ad component, give a name like camera control or I like to use camera manager or something like that. Now open the script to edit and modify him for the camera to follow the player we need to access the player game object, since the camera will follow its position by the time. So to do this, let's declare a public game object variable and make its name player. Now go back to the main camera object and look at the camera manager script. You will see that you can modify the player variable an inspector now in the hierarchy Window Dragon Drop Player. To this view, the player is now accessible from the camera manager script. Now go back to camera manager script, and now we need to calculate the distance between the camera in the player. If we know the distance, then we can add this distance to the player when it's moving. Or and by the way, the camera will always follow the player. So let's define a private vector three variable called offset. So we're defining a vector three variable rather than vector to sends. Even though the object is in two D, the position will always have X, y and Z coordinates. So now we need to find the distance between the player and the camera. We will find this variable at the start and then adding the difference in the update function. So let's offset set equal to transformed out position the camera position. Since our script is added to camera and subtract the player dot transformed up position, which is the players position. And now we have the distance between the camera and the player. So we will add this distance to the players position in the late update function because in order for our camera to follow the player, the late update is better than the update function. Is it because a player movement will be in the update function for a smooth follow? The camera will move after the player. Now. We also need to add on lee the X coordinate of the difference, so therefore will declare a new float variable called difference and set this equal to the X coordinate of the player position. Plus the X coordinate of the offset variable makes sense now, said the camera position to the new position said its position equal to New Vector three variable, which X component will be the equal difference Variable and Y and Z components will be the same. So after that set, the camera will always follow the player during the game, according to its X cornet, and the Y component of the camera will never change now to make the background image move along with the player. We can create a script for the background, as we did for the camera. But on the other hand, we can just make some background image as a child object of the camera, since the camera in the background will make the same movement. If you want, you can try a different movement with a different script. 12. Game Manager: Which brings us to game manager. We have a player to play and a camera that's following the player. Also, we have some enemies to pass and some coins to score. However, we're developing an endless game, and we can't add enemies and coins manually all the time. We need something that will always create new enemies and coins. We actually need something like a manager or a controller to control the game from one script. So let's create an empty game object in the hierarchy window and give a name like game manager, then at a component to this as a new script and give that the same name. So I don't need to add another component to this game. Object, since this is just to control the game and we won't even use it in the screen. Now this over the game manager script and edit to create the enemy's coins. And while some other functions, let's see what we've got. First, we need to access the column and the coin objects to create them continuously. So let's declare three different public came objects. One fur column down, one for call him up and one for coin objects good once that's done. Also, we need to declare their positions to create. So let's declare three private Vector two variables. 1st 1 is column down position. 2nd 1 is column up position, and the 3rd 1 is coin position. Okay, so we declared Variables we need. And now let's go back to the Unity editor and Dragon Drop. Call him up, calm down and coin from the pre Fabs folder to the game manager now initialize the column and the coin positions at the start function make their expositions the same, since they should be on the same line. Oh, and also this is the time we need to initialize there. Why positions? So in order to do that, we can use the random class to initialize. Why Component of Column. A position which is a function of unity engine name, space, Random class as a range function, which gives a random number between two numbers. So set column opposition equal to a new vector to which X coordinate is fixed and why component is random dot range with a max and a minimum value Good. So four column down position said this equal to a new vector to which the X coordinate is the same with a column up position, and the Y coordinate is the Y coordinate of the column up position, minus a certain distance. So let's decide with his distance will be, um, you can decide this distance by trying a few different positions in the Unity editor, and I think, yeah, I think that's a good distance. That's a good choice. Oh, and also do the same process for the coin, then right, create new columns function to create columns continuously. - Now this functions returned, type would be void, and it has no input parameter. So we'll just use the instant she ate function to create new columns and point the instance . E eight function is a unity engine function, which takes at least three input parameters. The first is the game object. The second parameter is position, and the 3rd 1 is rotation. It then creates the object at a specified position and with a specified rotation. So first right, the function to create column down our parameters would be column down as object column down position as position, and we don't need to rotate our game object so all rotations would be equal to zero. And we can write this as quit Ernie in that identity. So the attorney in class is used to represent rotations and unity and quit Ernie and Dot Identity is an identity rotation, which all coordinates R equals zero. So by this time we've created the column down, and now we write the same function for column up. So just copy and paste the function and change the first parameter as call him up and the second perimeter as column up position. We will also change the third parameter since we want this column looking down so we can write this as a new vector three with zero and zero and 1 80 as the parameters. Or we can use the angle axis function of the coup attorney in class. This function takes two parameters, which the 1st 1 is number of degree to rotate, and the 2nd 1 is Rotation X. We will rotate the game object 180 degrees around the Z axis. Thus the first parameter is 180 and the 2nd 1 is vector three dot forward, which represents the Z axis Tu. Instead, she ate the coin. We'll do a similar process, but for coin will need to be careful about its position right, since its position should be between the two comb. So let's measure the best position for where the coin is gonna be, um, by looking at editing positions in the scene, right? So remember when we first created columns in the coin using these instance? E eight functions, right? So now first will create column and coins using these in Stance E eight functions. And now let's give new positions to create next columns and coin. So to do this, we will modify the column up position column down position and coin position. So basically, we will add a certain distance to the expositions of them and choose a new Y position in column opposition, then will subtract some distance from the Y position of the column. Opposition for column down position and coin position. - Great . So now that the new columns function has been created and is ready, um, now we're gonna call this method for continuous column and coin creation. To do this, we will use invoke repeating function of the unity engine. This function is used to call a function repeatedly and it takes three parameters. 1st 1 is the function name to call, and so we'll right that has create new columns. Second is to invoke the function. After the game starts, we will write zero. Since we don't want to wait to invoke our function, just have it. Startup is a game start and, lastly, the repeat time for the function. And let's right to, since I think two seconds is better to repeat for this function. Um, if you want, you can try more or less, but I think two is a good option to repeat. All right, so now the game Manager script is ready, and the columns were being created continuously when the game starts. Excellent. So in the future we can add some extra functions for the game. 13. Game Over: game over. So over this course, we've created our game and everything seems just about right. But there is something missing in the game. The player is always playing the game and the game is never finishing, so we need to construct a game over function for the player to challenge its skill. So with that, let's write a game over function so well, right this function to the player script, since the player will fail when the game is over. So we want to set it up. The player will fail when the player touches one of the enemies or if the player is just out of the screen. So when the game is over, let's make player movements disabled and restart the game. Also, I I want that the game should wait a few seconds before, So to do this, uh, let's use a new class called core routines in unity. A core routine is a function that can suspend its execution until the given instruction finishes. So this is a very useful class to construct a wait time Ah, measured in frames or second so we can make it to the game. Functions will wait for the next frame or a few seconds to use Core routine functions in function functions need to return i e numerator So let's right, I e numerator game over and open brackets. We don't need to enter any parameter for this function. Good. Then make the players movements disabled. To do this, we will use a rigid body variable called I s Kin O Matic, which we consent for True or false. When we set I s Kin o Matic is true. The player would be taken out of physics control, then set rigid body velocity to zero. So now our player is basically motionless. Then it will restart the game. But before that, let's make it wait for a little bit. So let's write a function toe. Wait for a few seconds, we will return a yield instruction. So right, yield, return new Wait four seconds and now input seconds as a parameter. After that, right. The function to restart the game. To do this, we need to load the scene again with the load seen function of seen manager class. To use the scene manager class, we need to add seen management name space now. Right? Seen manager dot load scene and enter the scenes number that we want a low. Our game scene number is zero so right zero to restart the screen. Nice. So our game over function is ready and will need to call this function whenever the player touches the enemies. So to do this, we'll use another unity engine function called on Collision Entered two d. Now here there's some really useful functions to send messages to game objects when there's a collision between objects, so these are on collision. Enter on collision exit and on collision stay. These functions are for three D objects, however. Similarly, there are functions for two D objects, such as what we have here on collision entered two D on collision. Enter two D function. Return type is void, so it needs an input parameter, which is Collision two d Collision to de is another class and unity engine, which includes collision details such as incoming game object involved in collision. So now right function and let's call it game over function in here. But this should only be for enemies, so we need to separate the enemies from the other object. Now we can do this by tagging enemies. So go back to the Unity editor and find columns in pre Fabs folder. Now click the tag button an inspector, not a new tag. Call it enemy and choose Enemy as the tag for both column times. Good return, editing the script and now at an if statement to call the game over function. So now we're gonna make it say that if another game object in this collision is an enemy than the game is over. So that means we need to use the compare tag function of the game object class and the game object is incoming game object in Collision. Let's call. It's compared tag function and input the parameter as a string. So let's right the tag for enemies and spell it out. E N e m. Why perfect. So it's like this after the if statement, we will call the game over function, but the return type for this function is i e numerator. So that means we will use start core routine function to call the game over dot start core routine function, which will start the core routines. Input parameter can be the functions name as a string or we can call the function with rounded brackets. Now the game would be over whenever the player collides with any enemy, so there's still something else. We also want to make it so that if the player scrolled out of screen than the game should also be over, right? So in order to do this, let's check the suitable positions to call the game over function, then in update position. Use an if statement, - so let's look at this. If the player position is too high or too low, then call the game over function. So let's write in if statement and check the y coordinate of the flares position. Check the Y position for both up and down, and now we have two different conditions for both up and down. And if one of them is true, then the game should be over. So that means here we should use the or sign to check this excellent 14. Scoring with Coins : So let's move on to scoring and let's score with coins. So we've created the enemies and the coins. And if the player collides with the enemies of game is over. However, when the player collides with the coins, nothing is happening now, so we want to make it so that the score will increase by one. So let's create a new script for the coins to give a name coin or call a coin controller or something that you will remember easily open the script to edit and let's had a public player, variable player classes, a class that we created for this game. So in the start function, set this player variable equal to player component of player game object. To do this, we will use the fine function of the game object class in brackets, right? The name of the game object we're looking for and fine class finds the game object with this name. Good. Now the function will return the game object, but we also need just the player component. So therefore, we will also use there get component function to get the player component. So we access the player and now let's write the function for the score. So we want to set it up so that when the player collides with a coin, then the score will increase. Right. Um, therefore we're gonna need to use on trigger Enter two D function. The on trigger Enter two D function is yet another function that sends messages as on collision. Enter two D. But this function has collider to D type input parameter, so we don't need to write any. If statement sends in this game, only the player will collide with coins. So let's increase player dot score by adding to plus sign to the end of player dot score. So they're two different ways to do this. But adding two plus sign is my favorite one. Then update score text. Since the score has changed and lastly, we don't need this coin anymore, So let's destroy this game. Object Now the player is scoring when the player collides with coin. Pretty cool, huh? 15. How To Create New Scene: So let's create a new scene. Well, we basically have great gameplay, and now I want to create a start screen, which has a start button. So in order to do this, we will create a new scene and save this scene in the scene's folder. This would be the start scene, and let's give its name a start and then let's set it up. So when the game is open, the start screen should be the first screen. So let's add this screen in the build setting click file and builds heading to add scenes. If they're not already included in setting, So Unity will automatically open the first scene in build setting. Therefore, make the start scene as the first scene. Then let's had an empty game object to the scene, as we did in in the game play scene and give a name to this game object, which shows this is to control the screen. I will use smart menu, but you can use different names like start manager or start controller. Just don't do it as a game manager game controller. Since we use those names already and believe me, it'll get confusing for you later on, so I like to keep it simple. Good. Then at a component which will be a new script that has the same name with your game object , Then open into it. That's right. A public void function called start game and use the scene manager class to use the load seen function. But before calling this function, don't forget to add unity. Engine dot seen management name space. Now you need to enter the index number of the scene that we want to open. This function would open the gameplay scene and index number. This scene is number one. You also look at the index numbers of the scenes and builds headings. The scenes in the build section as numbers for every scene and those are the index numbers . So we've created the function, and in the next videos we will have the start button to use this function. But for now, let's continue to make the start seen better. So sure, this start scene is ready, but it looks to me kind of empty. So let's add some objects for an elegant look. We can add bird hero underscore zero Sprite to the screen, and there's really no need to add any component, since this is just for a look. If you want, you can change the position, rotation or scale, or you can use different sprites for the screen. Oh, and also I would like to add a background for this scene. 16. Adding UI Components: unity. You? Why? So I think we need something more in the start, seen something that looks attractive and really get Somebody wanted to play it. Uh, we don't have a start button just yet, so let's create a button by double clicking and choosing the button from the U. Y. Menu. As you see here, canvas and events system objects are created automatically when creating a you element. So canvass is the area that all you I should be inside. Canvas and canvas elements have different components from all the other game objects. For instance, it has wrecked transform rather than just transform. Wrecked transform represents a rectangle that the U element can be placed inside A whereas it transform represents just a single point. Positions X, Y and Z represent the pivot point of the element, and with and height represent their measurements of the element in terms of pixels, rotation and scale parameters air the Samos transform. Now, if you notice all you elements have wrecked transform rather than transform good. So the canvas component is to select the render mode for you, Elena and ah, and we've got three different options to select. But for this game. Let's just choose the screen space dash camera. Also, we can change the render camera, but but for this game, we already have that one. Camera Canvas scaler is an important component to control overall scale and pixel density of the U Y elements in the canvas. This will affect all you elements under the campus for the U. I scale mode. There are three different options, and the default is constant pixel size. Now this option doesn't take the screen size into account. Therefore, it's not really a good option for mobile games. The reason is, mobile phones have various sizes, and you I elements should be scaled due to the screen. Size and constant physical size also doesn't take screen size into account, and thus scale with screen size is the best solution for this game. So we've selected scale the screen size, and we need to determine the reference resolution. So I'm gonna make this 10 84 x and 1920 for why, for screen match mode, we have three different options, so let's choose expand. I think this is the best solution right now since sends match with or height scale the canvas area with Ah Haider with as reference, which means the U elements may be disproportionate for different resolutions. Good. Now the shrink option crops the canvas area, either horizontally or vertically, and therefore, for us, it's not a good option to choose. So now choose the button and change its name to start button this button and all buttons actually created in unity would have a child object, which is text on the button. Um, for this button, we don't actually need text, since we already have a sprite that has text on it. So let's delete text and click the button to edit. Now the button has wrecked transform, and let's change its position so you can set its pivot by holding down the shift button. Also, you can set its position by holding down both shift and all. But so let's change the start button position this way and also change position X and y for better positioning. Yeah, that looks about right. Good. Now the button has an image component, and with this component, you can change the buttons, image and color. So let's find a good image for the start button in the sprites folder. So if you write. Start in the search, you will see all the different options to use. I think I will use start hover sprint for the button. Don't change material or ray cast target choice, since we don't need to change these right now, now there are four different options for image time. Let's keep it simple. You can try all the other options to see the differences later. For example, the filled option is an interesting option to choose, since it's showing a part of a button image, and you can choose the film method and origin for different interesting buttons. The button also has a button component to edit button. We can select the button transition with this component. Color tint is the default one, and it provides it. If you click the button, it's color will change, and you can select, of course, the colors for the different states of the button. However, for us right now, the most important part is on click function in the button component. This basically starts the functions when users click the button and there are three different options to call functions which are off editor and run time and run time only off disables functions. Editor and runtime enables functions always and run time only enables functions on Lee when users are playing the game or testing the game in Unity editor. So to call the functions via on Click, we need to add a game, object to it, so click here and find between the game objects or, you know what, You can just drag and drop the relevant game object. So let's drag and drop start menu to on click Good. Now we'd be able to see the functions to call, So to call a function here, the function should be public. Now let's find the start game function and add to on Click, and the start button will open the gameplay scene when we click Good job. 17. How To Save Data: so now we can move on to save data. Great. So far, the game has all the features for a game that you need, and it all seems pretty good. But we can make it better by adding a few new features. For example, we can have best score to show users and users may want to claim or to beat the best score . And to do this we will use another function of unity engine. Let's open the player script to edit and add functions to keep the best score. So here you can add a new image or variable named Best score. Then, in the start function, set the best score variable equal to player press dot Get into best score player Press is another class in unity engine, and it's useful to store and access player preferences, weaken store and access strings, integers and float. Ah, so we called the best score for the game and now compared with the current score, so we're going to do that over in game over function, since we don't need to compare during the game. Now, let's open an if statement in the game over function and compared the score with the best score. So if score is better than the best score, then that makes current score the best score. To do this. Use, set and function of the player press class. This function will take to input parameters, which the 1st 1 is key and the 2nd 1 is value good. So let's hope in this start scene and at a best score text will make its position to the top center. And let's edit it's fun size as well. You can also edit its alignment and overflow settings like this Good . So then opened the start menu script to edit this text. Here we can access the best record data and modify this text that shows the best score. So we need to declare a text variable. And to do this, let's add unity engine dot U Y name space, declare a public text named Best Score and now make it equal to best score. So now the text component has different variables, and we want to change its text variables. So let's go ahead and write best score dot text and make this equal to best score and then we'll call get in function. But this will return an integer to make it a string. Also, call the to string function just like this. Okay, good. Now at a string before this function and right, best colon and then leave a blank. Now the users can see the best score in the stark scene. 18. Test Your Game: Alright, it's time to test your game. So far, we've developed a mobile game and we tested it after every step. However, you want to make sure that is going to behave in the way that you expected to behave in mobile devices. Even though you can change settings and screen size in Unity editor, it is still not a mobile device. Mobile devices have their own features and, of course, different operating systems. Now, in a perfect world, the best way to be sure that the game is gonna work perfectly on a mobile devices to test it on that mobile device. But it also be really hard every time you want to test the game, to take a build and stall it on your test of ice and going back and forth, and that's gonna take a long time. Fortunately, Unity has a mobile application to test games in mobile devices without actually installing them onto devices. Obviously, it's not gonna work as ideally as in a device, but for quick tests, just to make sure that your good without looks in mobile devices, it's a pretty useful solution. So to install the app, you can write unity to Android or the IOA store, Find the unity remote app and download it to your phone. Open the unity remote application and you will see the instructions. Connect your device with USB cable to your computer, Quick edit, then project settings and editor, respectively. Now, in the editor settings, you will see Unity Remote section and choose your device in here. Now we don't need to change other settings so we can just click the play button in Unity Editor. Now we contest a game without installing it onto the device. This app saves a lot of time. 19. Monetise the Game: Chanel. It's learned how to monetize the game. So many of us want to develop great games that millions of players air gonna buy in play. This may be considered on art, and some game developers just want to show there are two people. But another important point is to earn money from games, and therefore, I think monetization is very important part of this process. Game developers should carefully select monetization type for their game to makes a big difference. There are different monetization types for game. A game can be sold for a certain price or they can be distributed freely, and some features can be sold inside the game. This is called an in APP purchase. Ah. Typically, they can be characters or boosters, backgrounds, objects or some services. Such a ZRA move adds, those can be sold inside the game's. Speaking of which, I think another important type of monetization is showing ads in game for mobile games, the most popular monetization types or ads, as well as in APP purchases. Selling the game is not as popular as other platforms like for PC or for PlayStation, even if there are many games in the paid games categories, but it's just the nature of the marketplace right now. So let's talk about showing ads in games there. Different types of ads, which are interstitial ads, banner ads made of ads, video ads and rewarded video ads. Interstitial ads are full screen ads covering the interface of mobile application. Interstitial ads are useful for transitions between scenes levels or states in the game. For example, showing an interstitial ad immediately after a game over is a good option. Ad networks pay developers if users click through interstitial ATS. Banner ads are small text or images covering a small rectangular area, mostly at the top or the bottom of the screen. Better ads can be showed at any scene in the game, since it's pretty small in size. On the other hand, game developers should be careful when designing the interface. Since if you know you throw the banner ad into the end and then all of a sudden the buttons or to close, it would be annoying for everybody involved. Um, so you got to keep that in mind from the start. I would suggest the ad networks pay developers if the users click on Ben aretz just like for interstitial at so then water native ads. Those are presented as you I components of the mobile application. For example, if the application has a menu consisting of some buttons which are on the sliding menu, a button can be a native at ad. Networks again will pay developers if users click native ads, just like for the interstitial and the banner ads. Now, video ads are advertisement videos that display a short video first and then display an interstitial ad for the same product. Again, ad networks pay developers after users watch video ads, and then they pay MAWR if users click on the link in the interstitial after the video showing video ads after the game over or in between levels are also pretty good option. Now rewarded Video ads are very similar to video ads, but additionally, it has a skip option for users. If users click the skip option, they will see a warning window saying that if you watch this video, you will earn this feature. Otherwise you don't. I think some pretty good options and ah, some of the ones I like are showing rewarded videos in the game shop to earn a new object or after a game over or in order to continue the game. I think there's a great options, so you get the idea. The game developers have many different ad network options to show ads in their games. Some popular networks are Google Ad Mob, Facebook, Audience Network and Unity. So if this game ah well, you know what? Let's choose Google ad Ma to use add mob plug in. Let's Google it search for ad mob for Unity rather than just add mob. Since AD Mob has SD case for Android studio and Ex code also, ah, therefore specifying the platform. You know, you'll just find it quickly. So there it is. Download the plug into the computer than double click to import it into the game. So now we're going to create a new script in the Scripts folder named Add Mob Controller to call Add functions in the game. So I want this class to be a static class, since no instance of this class could be created. I mean, just one ad mob controller to call function. So let's open the script to edit and first will add Google Mobile ads got a p I name space . We need this name space to call. Add mob functions. Now let's write public static class, add mob controller and delete the mono behavior inheritance. Since data classes cannot inherit from other classes and the right ad mob functions we can use add mob documentation. So let's Google it and find add mob documentation for Unity. So now here's an example of both banner and interstitial ads to use in the script, and we can easily right functions by copying from here. We just need to change some parts for easier usage of functions in some of the other script . So first, that's right. Banner ads function, as we can see here. In the example, we need to create a private banner view variable Now. There should be a static variable, since all variables and functions in a static class should be static, On the other hand will need an ad unit I d. So let's declare a banner I d string. No, As you can see here in the example for different platforms, there should be different i ds. So then you declare different bad ideas for the different platforms. So we're gonna build the game for two different platforms. - So we'll write the function as a public static function, since we will call this function from another script and then it will be public. The function should be static, since it is in a static class. So now let's declare a new banner view. They have three different parameters, which at i d add size and add position so we have better I d to use as an ad unit, I d Add size should be better size and then position at the bottom for ad position. We have different options, but we will use the ad position dot bottom for banner ads. I just think it's better that way, especially because you've got a plan that out from the beginning. - So there we go now. The function to call the banner ads is ready. We also add a log function to test if the banner function is working or not. So let's write another function for interstitial ads. This is really similar to the banner ads function, so let's first declare an interstitial i d for the different platforms and then declare a new interstitial ad variable. - The only parameter is ad Unit I D. Since interstitial ads are full screen ads also add a log function for testing purposes. No for interstitial ads. We also need an ad request to show the interstitial and to copy the functions in the ad mob unity documentation and paste them into add mob controller script. And now the ad mom controller is ready and we can call Google ads in the game. So let's hope in the Start Menu script and call both interstitial and banner at and when you write add mob controller, you will automatically see add function. When the users over the game they will see an interstitial ad firstly, and after closing it, they will see a banner ad at the bottom of the screen during the scene open. 20. Building The Game: So now we come to build game pretty much. The game is ready, and now it's time to distribute it. For Android and IOS APS not to do this, we're going to need to modify some settings for both Android and IOS devices. Then we can take bills for Android and Iowa's So that's click file, then builds headings, and there is a player settings but near switch platform. So click on this button now in the inspector window, there are a few settings. I want you to pay attention to the company name, product, name, default, icon, default, cursor and cursor hot spot. So that's right, the name of the company and the product. Now, after that, we can add an icon for the game, or we could leave it empty. We don't need to modify the cursor settings, since we don't have a cursor for this game. Now below name and icon settings, there are settings for different platforms. You will see the platforms you installed the components off while installing unit to find the android icon and open Androids heading. There are different settings for android devices, and let's start with resolution and presentation. So this part just select portrait and portrait upside down and D select landscapes for allowed orientations for auto rotation, and this is enough for this part now, in icon settings, we don't need to add an icon, but for your information, if you want, you can add different icons for different resolutions of the android devices. So here's the splash image. We can add a splash image and modify settings of how to show this blast screen. On the other hand, if you're using unity personal Ah, the unity logo is necessary for your games, but you can change it. Splash style, animation and mode. You can also modify the background color and opacity if you don't want to use a full screen image to another settings. We need to identify this game by giving a package declaring the version as well as a bundle version code. Also, we can choose a minimum. Maybe I level and target AP eye level. The FBI settings may be important for some third party plug ins, so just pay attention to that so we can also modify some of the settings in configuration. For example, we can make Internet access required if we develop a multiplayer game, but now we don't need Internet access required. So just leave that. So also here do you see you can choose the install location and write permissions to write some user data such as High Score. Um, I would say that the other settings were just not needed to be modified right now, but you can explore those in your own time. Now the publishing settings is to take build for publishing and distribution on the Google play store, so we need to create a key store to publish on Google play. And we should keep this key store to update applications published on Google play. Otherwise, that would be harmful for the developer. But for now, we wouldn't build the game for distribution. Now these xar settings are for augmented reality and virtual reality setting. We can select this if we've developed a virtual reality or augmented reality game, but this time we haven't been using a are or VR. So we'll just leave these options de selected. But I just wanted you to see where they are located. Now go to build standings and make sure you switch to the android platform. That makes further the build system is internal. Now look, There's also a great all system to take Android studio project, but for right now, we'll use the internal build system. Also select development, build and collect the bill button given name and select the location for the bill. Now, if you have an android device connected to your PC, you can click, build and run button. This button will automatically install and start the game on your phone after were built. Okay, so the android a P K file is ready. We contest the game on Android Devices, So now let's take a build for IOS devices. First, let's modify settings for IOS. Click on the IOS icon to open settings for Iowa. Settings for IOS are very similar to the android settings that we did before, and we would do pretty much similar configurations for a lot of the setting. So first, let's go to Portrait's for Allowed orientations and D Select landscapes, as we did for Android. Now we don't need to change anything for icon and splash image. If you want, you can add splash images for iPad. Since the iPads have bigger screens with high resolution that's always a good idea. Okay, so here is debugging and crash reporting. Don't change anything, just leave it. Other settings are a little different than android. First, you see, modify, bundle, identify aversion and build and make them the same as you did with Android. No need to add provisioning, profile and profile I d. Now, if you're using a user's camera, location or the microphone in the game, you need to ask for permission in Iowa's devices. So for this game, we wouldn't use these features. But we can change the target as iPhone only or iPad only. Or here it is for both of them, and we can select the behavior of the game in the background. So there are three different options. Custom is that we can implement a specific behaviour via coating. Suspend means that the APP would be suspended but not quit, and exit obviously means of the F will quit. So, for our purposes, let's elect suspend. We don't need Teoh change any of the other settings or the xar settings. So let's go back to build settings and make sure that it switched to IOS platform. Always wanna double check now click the build button and select location for X Code. Project Unity will create an ex code project automatically. Also, you can click the building run button to automatically open the created project in X code. So let's go to the created X Code project and open the project file. Find unity iphone dot exe code p R O j and double click to open. When the project is open. Open general settings and click automatically Manage signing. After that, choose team and connect your device via USB. Now, if there's no Apple Developer account on X Code, you can add from X code preferences account. Click the plus and she was account type such as Apple I D and then sign into an account. If you don't have an apple, i d. You can create a new one for free. Now choose your device rather than a generic device. Click the play button to install the game on your device and test. Now you can test your IOS game on your own device. 21. Audio Adding: So now let's open unity and you can see what version you're using right here at the top. Of course, you can see that I'm not lying. I'm using version 2018 dot to 2018.0.1 F one. So now have a look at your projects and find your project to open. Since I opened the Flappy Bird project lastly, I can just go ahead and open the project right here. Now, if you can't see your project in the list, you just used the open button at the top right hand between new and the sign and buttons. Unity needs some time to open the project, as you may. Very well, no eso Well, this wait for unity to open the project. Okay, so today I am planning to add some sounds to my game to make my game or, you know, attractive audio. It is very exciting. So how are we going to do this? As you may remember, in my game, a bird is always jumping and collecting coins. If it hits with the tubes game, it's over. So sound for jumping would be a good option to make the game funnier. I need a sound playing when the bird jumps, Then I'm gonna need another sound for coins. And when the birds collecting and coin simple coin sound would play. And this would be a pretty good motivator for a player to continue the game and then lastly , ah, game over sound should be there to game over. Sound would play when the bird smacks into the tubes, right? So after that sound plays, the game will be over and a start menu will be opened bumping a bum. So, to sum up, I'm planning to add three different sounds to my game, which are jump, coin and game over sound. On the other hand, I can add game music for the start menu so you can find lots of game sounds and music on the Internet if you google for them. Um, also, you can find many sounds in music tracks on the Unity Asset store, so today I will search for sounds in the Unity Assets store. So let's go ahead and open Unity assets store in unity, and you can search, sound or sounds for better results. I'm going to look for a sound pack. Let's see if that would have you know many sounds and a folder. Also, I will use the free filter since right now, I don't wanna pay for sounds these air all copyright free so you can see the many free options for your sound pack. Um, let's see Sounds in the first option. As you can see, there's by click and time options in this pack, but it doesn't fit for the game that I want to do. So let's look for another option. So this one has coined game over and jump sounds with many different options. So let's go ahead and download this and import it into the game. Oh, firstly, I need to log in to download. So now I logged in and let's go ahead and download. So as you're looking at here, we can choose options to import into the game. I don't need explosions hit laser and the power up sounds as well as a demo scene, so I'm just going to de select them and import from there. If you want, you can import the hit sounds, but I don't want to do that was I already play the game over sound when the bird gets hit with the tubes so I don't want to play two sounds at the same time. And right here you'll see that the game sounds were imported into this folder. And now I'm gonna look around for some game music. So let's search for game music and use the free filter again to de select the paid options . You can do whichever you want. Um, but here you can see the different options for Ah, here's what I'm looking for. Free retro game music. That's awesome. I didn't choose the 1st 1 since that's the R P G game music and the retro style, I think, is gonna be more suitable for my first. If you want, you can go ahead and look around. Now that you see where it is, it's ah, in the asset sore. Or you can just google and find better music on different websites. As you can see here, there are five different options, and I'm thinking that last three of them don't fit for the game. So I'm just going to import the 1st 2 of them and I'll choose one of them. So the sounds were imported into audio at the top, the assets holder. So now it's time to add the game music to the start menu, right? So let's create an empty game object named Game Music. And let me just articulate that better game music. I don't know what you heard and add the audio source component. So in the inspector window, you can add via searching for audio source, or you can just add it from the audio menu. So now let's listen to both of them and choose one. I did like the 1st 1 so I'm gonna add the 1st 1 to audio source as an audio clip. Now let's talk for a second about the audio source component. Firstly, it has the audio clip variable, which is the music playing, Um, so you need to add the sound. Here. Output can be an audio listener or audio mixer. You can do some modifications on the music with this, but I'm not going to use the feature Now. Mute is an option that just well mutes the audio source. Have you selected it might be useful when testing or you can change this? Who scripting It's up to you now. Bypass effects bypassed listener effects and bypass reverb zones. Those are the options to turn off the effects that you're using. But I'm not gonna used these effects right now because I want to hear them. Uh, so play on awake is to play the audio when creating the game object. So this option is selected. The audio source will automatically start to play audio when a game object is first created . So let's select this option for the game music so that it will automatically start. The loop option makes the audio clip loop when it reaches the end. So let's select this, and the music will continue to play. The priority determines the priority of this particular audio source. Don't need to change that right now, since we only have the one Audio sewers Volume determines how loud the sound is at a distance of one world unit, which is a meter from the audio listener. Interesting, huh? Pitch. It's amount of change in pitch due to slow down or speed up of the audio clip, so value one is the normal playback. Speed will stick with them now in three D sound settings. You can add some effects to sounds by changing minimum and maximum distance. These settings determine where and when the sound will attenuate, or you can use the volume role to change. The sound fades to make him quicker or slower. And now, lastly, run missing and check it. The game music is playing. It will automatically start to play, and it will continue to play until the scene is closed, because that's one of the preferences we checked earlier. Loop. So now go on to the main scene and add other sounds for the game. So let's first select the bird game object in the scene and add the audio source component . Now go to the Jump Sounds folder and that's just audition some different jump sounds at a jump sound, whatever you want and de select the play on awake. Since we don't want the sound of play. When the game object is created, right, then go to edit the player script. Since we need to play this sound from a script, the sound will play when the jump function is called so firstly, at an audio source variable called jump sound or jump source, or whatever you want to call it. But, uh, then you get this component at the start method So after getting that component, go to the jump method on my script, the jump method is called Flap the Bird, then call the play method jump source. That's the object at the end of the method, right? So you can also call play for the method at the beginning. It doesn't matter. I just prefer to call it in the end. Now let's control the sound in Unity editor. So when the bird jumps the jump, sound should play once. Now add the game over sound. Uh, first, let's at a new empty game object called Game Over Sound, then at an audio source to this game. Object. After that's done, check some of the game over sounds in the game over sounds holder and add whichever one sounds good to you just added to the audio source of the game over Sound game. Object. Now to play this sound. When the game is over, go to the player script and play this sound in the game over method. Firstly, at a public audio source variable called Game Over Sound or again whatever you wanna call it, we need this variable as a public variable, since we will add this sound in Unity editor and then you Congar to the game over Method and add game over sound play method. Go back to the Unity editor. Find the game over Sound Game Object and the select Play on Awake Select Bird and add game over Sound to the game over. Sound variable in the player script. Now check. Make sure the sound works. If the game is over, game over. Sound should play once, and then you should see the start menu. Excellent. The next sound is the coin sound, so let's add another empty game object called coin sound, or I'll leave it up to you says we did before. Let's add audio source component and then try a few different sounds and at which every coin sound you like. And remember to de select play on awake. Then you can go to the coin script and add an audio source variable called on an old coin source or coin sound. Uh, whatever you want. You got to remember it because we need to go and get an audio source component. That's start, so to get the audio source component first we need to find the coin sound game on. So in my example, let's use game object dot find right coin sound as a parameter inside the brackets. And that's why I said to remember it, because you've got to make sure that the name of the coin sound object or whatever you've named the object in the unity hierarchy it should be exactly the same name within this parameter. And now you can get the component called audio source. So we want the coin sound to play when the coin is collected. So go over to the on trigger. Enter two D method and here call coin source. Stott play method. All right, Now is the time to check. See if the coin sound is working properly. And when you collect coins, the coin sound should play one Perfect. Now, lastly, you can check it, See if all sounds air working properly. Please be careful that if you muted any sound for testing than de select the mute variable s so that you can hear all of this sounds. Also, you can control play on awake and the loop options since generally, these variables may cause that those sounds won't be working when you want them to. Good job