How To Make Simple 2D Game in Unity | Domen Rajterič | Skillshare

Playback Speed


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

How To Make Simple 2D Game in Unity

teacher avatar Domen Rajterič, Software & Game Developer

Watch this class and thousands more

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

Watch this class and thousands more

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

Lessons in This Class

14 Lessons (2h 54m)
    • 1. Introduction

      0:38
    • 2. Creating Main Menu

      17:36
    • 3. Level and Player Prototype

      9:53
    • 4. Player 2D Movement

      25:11
    • 5. Second Player and Input Settings

      9:13
    • 6. Cinemachine: Target Group Camera

      6:30
    • 7. Adding 2D Shooting

      14:12
    • 8. Health of the Players (Script)

      11:29
    • 9. Displaying Health and Score on Screen

      16:12
    • 10. Adding Timer in Unity

      11:05
    • 11. Pause and Game Over Screen

      12:25
    • 12. Making User Interface Work

      29:31
    • 13. Music and Sound Effects in Unity

      5:18
    • 14. Icon and Splash Screen

      4:26
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels

Community Generated

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

143

Students

--

Projects

About This Class

Hi, my name is Domen Rajterič. I am software developer from Slovenia and this is my Unity class.

If You are looking for a complete course on game development in Unity, this is the right place for You. With almost 3 hours of video material, You will learn all the basics of game development with Unity, from setting up UI, to level and player design. During this class, we will develop a simple multiplayer prototype with complete user interface, sound effects and fully working mechanics for two players. After this class You should be able to start developing Your own games. Tools needed: Unity and Visual Studio (both free).

If you have any questions or problems, I would be happy to help! If you like this class, please leave a review, it really helps me and it is very appreciated. :)

Join our discord server to share your work and connect with community!

Meet Your Teacher

Teacher Profile Image

Domen Rajterič

Software & Game Developer

Teacher

Class Ratings

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

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

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

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

Transcripts

1. Introduction: Hi. My name is Thomas knighted. I'm a software developer from Slovenia. And this is my unity class. If you are looking for a complete course on game development in unity, this is the right place for you. You will learn all the basics off to a day game development in unity from setting up user interface to level and prayer design. During this course, we will develop a simple Amanti per prototype with complete user interface, sound effects and fully working mechanics for two players. After the scores, you should be able to start developing here. Own games. See you in my class. 2. Creating Main Menu: so. So let's begin with creating canoe Empty project. Click on the new. The first thing we need to do is to name our new project. I will leave it as new projects to and template should be two d and he'd create button. This brought process should take a few seconds so we can wait. I can tell you what we'll do in the first video. We're going to create a two scenes one for the manual in the 2nd 1 for the game and we're gonna create men Main manual. Ah, we will add some buttons and ah, we will write the first lines of goat on. The last thing we're gonna do in this first widow is transition from main menu toe the game scene. So we have created a new empty project. As you can see, all we have right now is ah, blue background by default. If you go to the scene, we can see that all we have is a main camera and no, we can add Let's a background and bottles for the main manual and later we will add another scene for the game itself. So let's begin with creating our menu Let's go under the higher higher here. Under the main camera, we can click and we can add under the user interface elements. Canvas can Waas were served as a base off our manual, so let's double click on the canvas. This is our cameras and now we can at user interface elements. The 1st 1 is of course, background. So right click on the canvas again user interface and let's select panel. Vanna will serve as a background. So we have panel and we can add a picture as the background or a single solid color. I will go it single color eso we select banner Let's go under Dick Connor and select white Collar with Alpha Channel to the maximum and under the source image. Right now we have background image, but we want we want our background without an image. So let's select loan. But if you want tohave an image as a background, you can at any picture you want in the project further, and then you can select here your picture, but I will have white collar. And now when we have background, we can at bottles, I will have two buttons. The exit battle and the play button. So now I will go under the banner right click and under the user interface, I will select Battle. This is my bottle and this will be my exit button. So I will rename this baton toe exit bottom. And now, if we extend to this exit button, we can see another element, the text element and let's select text. And we can modify a lot off things like phone size, font style font and, of course, text. I will change the tax too exit and the phone styled from normal to bolt like this. And now again, let's go back to exit Baton and I would like to change this background off the bottom. I will go under the source image off the bottom, and I will select none like this color white. I will leave it as it this and oh no, Let's go another way. I will select black background, of course. Then we need to change the text toe. Let's say white. Let's go with white great and again under the exit bottom. I would love modified this. Para matters normal, Carter highlighted color and breast collar, so I want normal color to be black, then highlighted color. I want to be again black, but this time with Alfa Channel. Let's say one, 55 You will see later. Why and breast color. We can go again with full black. And now if I heat play button, we can see that when I How are our the button? It changed. It changed a scholar, and when I click it, it goes for black. So let's stop the game. And the last thing we need to modify is navigation from automatic two month and disease. Our first battle. We can move it. Let's move it down. Position X middle of the screen. So zero and let's say 200 like this. And now all we need is play button. So let's duplicated this exit button by right clicking partner, right Click duplicate. And to rename these back in tow. Playback them off course, I'm gonna move it like this under the text element, I will modify text well, play. And now, if I started the game, we can see two battles working as we want. But of course, now we need functionality. And for that we're gonna write our first scrip script. Our first lines of coat. So let's go under the canvas. And under the at component, we're gonna add a new script. And I will name mine menu. New script, Name it Menu created Net. And after a few seconds you should see a new element here, a new component called Menu Script. And now, if you double click on the menu, we should get our vision studio opened. Mm. So where's my leisure studio? No, uh, on the second screen. I'm sorry for debt, So that's our new script for the menu. We don't need the start in the object function, so let's delete bought off them. And we need to import a new unity engine component named Seen Management Management. So Unity Engine, Dr Seen Manager Management and we're gonna create two functions. One for the game. Let's say load, game, start game and the second function exceed game. So let's begin with the 1st 1 load game public. It needs to be a public because we want to call this function from the unity itself so public for it. Load game. These will be our first function and the 2nd 1 again public void. But this time, exit game. You can name these functions any way you want. And for the exit gain function, all we need to write is just one line off coat, really simple application that quit. And these will close our game, but not inside of the unity. But after we already built the game, so now under the load game function, we're going to write seen manager dot load scene and now we need to right here. The build index off our seen or window. So let's say manual Hess index off zero and we need to load the next scene after the manual . So if the Manu is zero, the game would be one. So I can write here one or the second away. Let's right. Seen manager dot get active scene dot build index. So now we have the build index off the currency. But of course, we needed the next scene so way are going to write plus one like this and this We load the next scene in the higher and actually, that's all we need to write for the menu script. Of course we need to save it. So comment yes, or go under the file and heat safe button, and now we can go back to unity and we can connect dysfunctions with our bottoms. So let's start with play button. I will move my play button over the exit button like this, and under the play button, we can see that we have on Click Window, which is empty at the moment. But if we if we click the plus bottom and we can at a function to this bottom, the first thing we need is the object with our script with our coat and we add it, coat under the canvas. So let's dragging the canvas. And now we can select all the functions from the canvas object. So let's find the function we need for the play button. We can see the manuscript here and we can find load game here, so click it, and now we added function to our play button and the same thing for the exit bottom. Select Exit Barton. Go under the own click window, select a glass bottle, dragging the canvas object because we have script added to it and select the right function . So under the manual, we need this exit game function and no, we have added functions, functionality, towboat off our buttons. But of course we can't load the game itself because all we have is manual and we don't have the next window, so we don't have the game. So let's create Let's create one, go under the scenes in the project window and right now we have sample scene, which is our menu. I will rename this scene, too. Menu Manu and I will also create a new scene. So let's hit, Create seen and I will name this scene game. So now we have to since and we need to make sure that manual has the built index off zero and the game has the build index off one. So let's go under the fire build settings and we can see here in this window all the scenes that are added in our build right now is empty. But we can, of course, at and let's begin with Manu. So the man you we'll get the index off zero and let's know at our game and we can see that game gets the index off one. So now we have to since add it in our built Manu on the game itself, And of course, we can test this out. So let's heat play button. And now we should have do working bottles. If I click exit, nothing happens because we are in the editor. Of course, we need to build the game toe, half working exit button, but our play button should work. Fine. Let's try it out. Great. We have transitioned toe the game itself and now it's time to start building our game, which we will do in the second video. But for now, thank you. 3. Level and Player Prototype: so after the menu, we should continue with building our game. And as you can see, all we have at the moment in our game window is main camera with background color by default set to Blue course. I would like to change my background color and I will go with white collar like this. And no, as we have our background set, we can at some environment elements. We can build our first level, so I will show you the easiest way the fastest way to create a prototype off your game. Let's go under the assets and under the create, we should see this Sprite window and let's select square and down there in a project. Further, we get this square hit enter and we can use this square as a building element off our environment. So let's dreck the lets drag the square on the screen. We get this simple White Square, we can change the color. I will select black color because I have white bag grant and of course, we can change the scale. I will select the Eakes to be four and the UAE scale toe 0.5 like this and no, this will be our platform, our environment element. I will rename this square to blessed form, and I will also add a shadow to this platform. Ah, it's a simple trick. Go under the platform, duplicated and rename this platform one to shadow. Now we can drag this shadow under the platform. Of course, we need to make sure that our platform appears on top off the shadow. So let's let's modify order in layer off our platform toe one. And now we can go back on the to the shadow. Let's move shadow a little bit down and to see the difference. We need to, of course, change the color. I will say I like this color picker and we'll go with this great color down there and we have a simple shadow. You will better see it. If I hit the play button on the back on the white background, you can see the shadow off my platform. Great. So we have created a shadow. Let's go again to the platform. And now we need toe ette. Ah collider toe our platform so it will detect the collision with our player. So under the at component, we need to at Box Collider box Collider two dimensional hit at. And now if I zoom in, you should see this green line around the platform. These means that we have added a box collider toe our platform. Great. So we have our platform. But of course, one platform is not enough. We need more of them and we can, of course, reuse this platform. And to do that, of course, we need to make a pretty FAP. A prefab is just the element that we can reuse over and over a game in our project. So how you create a prefab, it's really simple. Just select the object you want to transform in the into the brief app, drag it down to the assets for her, and we get this platform object down with blue icon. And this blue I can means that this object is now prefect. And now if I drag this platform from the assets to the game, you can see that we can reuse this platform as many times as we want. So let's at another one here and another one here I will move these like this and this will be enough for the first scene we need now to add a player and a simple player script. So let's stop these game. And so no, we can at a player. We can reuse this white square. I will again select the black, the black color for the player and ah, I will rename my player toe player. Of course, we need to add a few components. The 1st 1 again would be a box collider, two dimensional so that we can detect collisions with other objects and the 2nd 1 is rigid body. We need rigid body, two dimensional to move around. Our player and I would like toe modify a few Ah few values under the rigid body. Two dimensional. The 1st 1 would be gravity scale from one to tree. Let's change the collision. Detection from discreet toe continues, and the last thing we need to do is frieze rotation on a Z axis. And now if I heat in the play bottom, you can see that we get the moving player object and this should be enough to continue with Brother Taik to prototyping our first game. But let's stop this game and because I would like a better result presentation off my player. I will add ice to him. I will duplicate this square element. I will name both off them. I and I will change the scale from 1 to 0.2 and 0.2. And of course we need to move it like this. The other one? No, let's more it. So we kept eyes. And of course, we need to move this ice under the player. So if I move my player around, the eyes follow. And now if I heat play button, we can see that we have player, but with no eyes. Why not? Because I forgot to change the order in layer off our eyes to one because we need to make sure that eyes appear on top off our player. Player has order in layer off zero and ice have ordered in off one and no, everything should work find. So we have environment, we can platforms, you cast player. And in the next widow, we're gonna create a movement script for our player. But for now, that's all. And thank you for watching 4. Player 2D Movement: in this part. We're gonna go over movement, script for the player, and later on, we're gonna at the second player. We are also gonna covered input settings, anti immunity and how you map game Bad. But first thing first, let's begin with movement script for the player. So we have set up a player with box collider enter rigid body. So we have rigid body to move it around. And we have a box collider to detect collisions with other objects. And now we're gonna add a new component, a script. So click at component, and I'm gonna name my script movement. So new script Great in it. Uh, this should take a few seconds, and we're gonna see a new confident here called movement Script. So double click on the movement and we get a new script opened in visual studio, and we will leave the start and object function because we're going to use them. And we're gonna also use the dirt function from Unity engine package called Fixed Update. So the difference between update and fix update is that update is called once per frame, and fixed update is called a fixed amount of times and that's a 50 times per second, and the start is called before the first frame. So let's begin with declaring, Ah, a few wearables We need where rivers for speed for jump hung, hike and player jump. We need to store horizontal input and so on, so on. So let's begin with spit. We're going to declare a public wearable for speed are so we can later change the speed and to the jump force off the player inside to the unity. So let's begin public float. I'm gonna name this wearable speed. Then again, public float, um, jump or jump four. So are something like that. Uh, the next will be private on and we need by a private float to store horizontal movement. Uh, well, use minus one toe one. So private float. Corey Zonta Uh, we're gonna talk about Ah, this wearable later. Then we need toe access to Regent body off our player. We have added a confident here rigid body, two dimensional to the player. But now we need toe connect it with. We need to connect this rigid body with our script. So you're going on, declare private rigid body today. I'm going to call it our beer like this. Then I'm gonna create a variable, uh, to store. Well, you I'm gonna show you inside your community. Um, I created my player facing right. He looks to the right. But of course, later, when we will move our player to the left, we want him toe looked to the left. So we will flip it around and we're going up. Use Julia Well, you to declare BP's facing cried or left, You will see You will get it later when we'll work on this future. So let's no just declare private again Private pull. I'm gonna call it ah, facing right and let's assign a value off. True, because right now he's facing right the next Ah, few wearables will be, uh, about jumping. Uh, our player will be able to jump on. I'm gonna create. We're gonna set up this movement in such a way that our player can have ah, single John double jumps, triple jump or however how many jumps you want. So the 1st 1 is bullion, private again, private bull and let's call it ground it or about their name east. Go around it. Ah, you will detect with this Bulow With this variable. If our player is touching the ground or is in the or he he's in the air, the next will be public, and it will be off type transform, public transform. Uh, something like ground check. Uh, this will be the point, but the lowest. Let's say we're gonna add a point here at the bottom of the player to detect collision with the ground groans Check. The next one will be public float check radius and the last time public layer mask. And I will call this around. Uh, we're gonna store in this wearable What is ground and what is? I don't know, callings, enemy. So, so long. We need to do more wearables. And then we can start writing our gold, our functions. The 1st 1 will be private this time Integer x There. Thanks. That are bars, germs. Something like that. To store how many jumps we have. I'm gonna decorate Dapple jump or maybe Triple Germ. And the last one this time public in teacher Let's say number. Oh, bores jumps So that are all the way rivers. We need that now. We can start coding. We will start in the first function called start, we need to just two lines of code here. The 1st 1 will be bonus jumps is equal to remember off bullets, jumps. Um, the 2nd 1 we need to connect rigid body with our player. So r b is equal toe, get confident and which component we need. Of course, we need rigid body to a deer. So these line off coat will find the rigid body off our player. We have added rigid body and we will be able to move our player around. And that's all we need in our start function. Let's go now in the object function again just to three lines of coat are simple. If statement yes is grounded is equal toe true. Then we're gonna copy paste this line of coat and that's all we need in update function and all the rest were going to write is the fixed update function in the fixed update function . So let's begin. The first thing we need to declare our is grounded, uh, wearable. We need toe assign value. So is ground. It is equal to physics to deal, and we need the overlap surucu breakfast. We need to at three components here. The 1st 1 is ground check, and we need the position off ground check. Then we need check radius and the last component. Ease, layer, layer mask. And we called our layer mask ground. That's all we need. Toe do with is grounded wherever. No, we need to detect our horizontal movement. Input off, player moving cleft. Right. So let's use our horizontal wearable. And we need to assign a value off input that get access and which access we're gonna use. There are to access. One is horizontal, and the other one is I'm gonna write it here is working, girl, but we don't need work tickle, uh, access today. Just who resorted to move left and right? Course I forgot. Seven. Connor. So now we have start our horizontal input in this wherever, and we can actually no move our player left and right. So let's right, R b rigid body, far player dot Velocity is equal to We're gonna declare new work took to, and we're gonna use results input we got, and I'm sorry, and we need to multiply it with the speed off our player and the why velocity steams the same. So RB that velocity is equal to why we are gonna just used these to move left and right. So now if I say for this and if we go back to unity, we should see that our movement script will well at ah, a few components which we can change speed jump grounds Check And let's do this now. So I will set this speech. Do let's say, then jump to 15. We need to tow at the ground check. So let's go under the player and create empty object. I will name this object something like Grown check and I will use these are at the color for better usual presentation. And I'm gonna move these ground check to the bottom off our player like this, I will set it to the middle of the player and to the bottom. So we have our grounds Check. Let's go back to the player. And now we can use these girls. Check here. Check radius. Let's say 0.5 ground. What is our ground? Of course, platforms are our grand, but we can't select here black forms. So let's go under the platform in the prefab and we can see that we can declare a new layer for our platform right now is default. But we can at a new layer. I really use Layer eight and I will name it ground. So we have a new layer. And now let's go back to the platform. We can assign ground layer eight to our platform and we get this window asking if we want to apply this change toe all the objects. But you are the object we objects we have already used in the game. So yes, I want change. Change change, Children. I'm sorry. So now if I go back to the player, we can select what is ground, and we are gonna use our ground layer and the last thing number off bones jumps. So let's say two. I want my player toe have two bonus jumps. And now if I heat play bottom, let's see if our player moves around. And yes, he's actually moving. Great. Okay, so we have now a movement left and right. Um and we should continue with ability to flip our player when we move to the left. And, of course, we are going up at a jump Inc ability. Let's go back to visual studio and let's start with flipping our player around. We need to declare a function to flip our player. So let's go down there and let's declare the fourth function off this script. Some think like Avoid flip and, uh, dysfunction will be really simple. The first thing we're gonna do is to reverse the well you off facing cried. So if the facing cried is now, let's say true, you're gonna reverted to reverse it toe force and vice versa. If the facing cried will be, let's say false. Then after we call dysfunction it will be true and the second line of court will be transformed and we're gonna rotate our player four 1 80 s 00 f 1 80 and can zero. And we can use dysfunctional in the six update method. So we need a simple if statement don't know which way are. Player is facing and betrayed. Our players is moving, so let's say yes, our player is facing right is equal to false and horizontal Well, you is greater than zero. So if our player is facing left, but he's moving to the right when we want to flip it to the right. So let's go flip function here and the second condition and see if if our player is facing right. So if facing cried is equal to true. But her resulting movement is less than zero, so he's facing cried. But it he's moving left. We're going a flip the player around again. So flip and these should work just fine. Let's save it. And this. So I'm off left, right, left, right. So our player flips around. Great. No, the last thing I want to do ease off course toe at a jumping ability, toe the player. So let's go back to the vision studio. And under this if statement, I'm gonna write another If statement this time, uh, we need to detect if our player presses the jump battle. So I'm going to write again. If statement if input Dr, get back down. You're looking for button cause jump. And if bones jumps? Uh, he's one. If bonus jumps is greater 10 0 then what to do? We want to apply, right? Ah, vertical velocity to our player. So, Richard body, that velocity city is equal to director two. You got up were deployed by jump. This is condition if we have more bonus jumps and second as if again, we need to detect input bottom called jump so import dot Get button down, jump and do more conditions. Take ah bonus germs equal to zero and he's ground that is called true what to do In this case, we can copy paste these line of God and I forgot to do one extra line of code here because we need to. We used one bonus jump. So now we have one borns jump less and that it's all we need, I think do jump our player. We can, of course, try it out. They bought them and no, we half hour player jumping current. Great. And we have 123 bonus jumps. So we have and that the movement script we we are able to flip around our player and we're also able toe jump around. And now you're probably wondering what are dose jump bottom and horizontal axis This Ah, we're gonna color in the next video when we go over this input settings and we're going to also, um, talk about a game pet mapping and ah, the funny on the funny part will be adding the second player or the enemy player. So we're gonna be closer to our multiplayer game. But for now, for these video, that's all. Thank you for watching. 5. Second Player and Input Settings: welcome back in the fort with their in this chapter. We're gonna create a second player for the game, and we are also gonna cover the input settings and how to map your game pats. But let's begin with creating a second player. The easiest way would be to duplicate our existing player. So if I select my player, right click on it and we can now see that we can duplicate this object. So let's duplicated and we now have two players. Let's move the second player to the other side and change the color. Do whatever you like. I will select. He's for a collar and now you five press the play button. You will see that if I moved the player one the player, the player to moves toe. If I jump everything, they move in the same way because they receive improved input from the same movement script . And we need to change that, of course. So stop the game. Let's select our second player and we need to remove this movement script. You go, uh, there to the right, remove competent and you're going to create a new confident called movement toe. No script. Create a net, and after a few seconds you will see here a movement to script, double click on it, and these movement to script will actually be almost exactly the same us. Our first movement script. Just three little changes so we can actually copy paste all off the coat from the movement , one to the movement to a little carpet. And the only change we need to do is off course input. We need to change horizontal, toe, horizontal to and jump to jump to two times, and that's all. Let's save this script and go back to unity. No. Ah, we again need to set up a few well use here in the movement toe script. So let's set speed toe, then jump 15. We need to drag in our grand checkpoint, so let's doing that. Check radius 0.5 ground is girls and number off extra jumps is again, too. And now we have two different movement scripts on, and we also now it needs to do two different inputs for two different players. Let's go under the added Select Project Project settings, and you will see under the input we have this array off elements like horizontal vertical fire jump so on, so on and they're all duplicated. So we have horizontal here. Deasy's for the keyboard. So we have left bottom right button as our negative and positive buttons. Because horizontal ah, values go if you if you press left bottom, therefore is Antle has a value off minus one, and you feel pressed the right button or d you get the well, you off one. And if you don't press any off horizontal buttons, we have a value off zero. So right now we have left right, a Indian for horizontal input, and the second horizontal element is for our joystick. So now I can move out my player, one wheat keyboard or joystick, and I will changing one thing. I will change the name off horizontal in the 2nd 1 for the joystick toe horizontal toe, and that will assign this element to the second script. And so we will move our second player with the joystick and the first player with keyboard . You can, of course, set this game to play just with keyboard. So one player place on the A and E on the left side of the keyboard on the 2nd 1 on the right side of the off the keyboard. Or if you have two joysticks, you can set up this game for two joysticks. But right now I have one key birth. So the player one will play with keyboard and the second player will play with joystick. So I have no horizontal to set up. Let's try this out. I have connected my joy. Stick to the computer and no, my second player moves with joystick and the first player moves with key birth. Great. So let's continue. We also need are jumping ability for the second player. So we have jump one element here and it's it has assignment positive bottom space. That's okay for the player one, but we need also jump to. So let's select the second jump element. Let let's change it to jump to, and I will assign joystick bottom one for my for my second player enter and to bring it again to test result. And no, my second player can jump do No. If you have a different joysticks, you will. I need to write a different where you scare for the joystick bottom. Um, I will show you how to do that with PlayStation for joystick, Uh, which I have, uh, I assign it jumping toe the eggs bottle or joystick? Butter one. I moved with my, uh, seeks access, and I will shoot with my, um, joystick bottom. I think I have seven. Yes, I will shoot with seven. Jump with one, and I will move with left mushroom. And if you have a different game pad or joystick Ah, that's the values for the X box joystick on. You can google all the other joysticks. That's just toe the most common off them. Um, I will use as I said, these PlayStation joystick and keyboard for the player one. And that's actually it for the You see there on the second player and move input, uh, player input. And now we can continue with setting up our camera. So thank you for watching. Can't see you in the next widow 6. Cinemachine: Target Group Camera: Hello and welcome back in this widow, we're gonna set up our camera because right now our camera stands still, it doesn't roof around, It doesn't follow our players. And it's time now when we have two players to change that. So we're gonna set up a scene. A machine which is a very powerful component off unity. Let's go under the window and open up Package manager and look for the scene. A machine. If you are using the latest version off unity, you should also you should also installed the latest version off. Seen a machine. But I'm using can order version off unity. So I need to install also the older version off. Seen a machine. I will go it to To. Right. Stolen. And after a few seconds, you should have installed to your senior machine. Okay, see, Machine is installed. So now we can start modifying Cower camera. Let's go under the scene. A machine. We get the new window here and let's select target group camera. And now we get this, uh, you camera set up and you can see here we get a target group in ah, which we can add or the objects we want to follow with our camera. So let's select target Group One and we need toe at all the targets or our players. So let's at player one and also player to and we need to set up radius. I was set to toe both of them like this, and no, you find heat, the play bottom and I move around. You can already see our camera is moving around like this. Great. So we have has seen a machine or ah, target group set up. And the next thing I would like to change is you can see if I fall off the platform. Nothing happens. I want to somehow detect falling off and to, let's say, real haute, the game, the scene if one of the players fall off. So let's do that, I will use a simple trick. I will use this White Square we have, and let's extend it down there In both ways, something like this should be fine. And let's at a box collider to it. So find box collider two dimensional. And now when we have box collider, let's select East Trigger Toe True. And we were gonna at a component something like detector new script Creating that and we're gonna right a simple line off court, which will reloaded the scene if one of the players fall off. So let's double click on the script, and we don't need start or update function. So let's delete both off them. But we need seen management. Beckett. So let's import it. Unity and jeanne dot seen management like that. And now, because we have added a box collider and trigger, we can use a simple method called on trigger entered two D and this function will get called when something collides with our detector. If player one or player to collides with detector dysfunction will be called and what I want to do in this function, I want toe reload. This existing seem so seen management, that load scene seen manager that get active scene, not built index. And that's all we need to do in this simple script. We just want toe reload the existing scene. So let's go back to unity. And now if I pressed the play button, we can try if this is working, so let's fall off. And yes, we have are working detector for our a game. And that's it for this chapter in the next one we are gonna at shooting ability. We're gonna create a bullet, brief app. But for now, that's all and seal in the next video. 7. Adding 2D Shooting: Hello and welcome back in these widow, we're gonna at a shooting ability to our players. We're gonna create a bullet bullet, prefab. And we need to, of course, set up again. Input settings for fire one and fire too. But first, let's begin with creating our our bullet. We are again going to use these white square. So let's drag this square to the scene. I will change the color toe black. Then I want toe decrease the size so I will change. The scale speaks well, you 2.3. And why were you also 0.3 like this? Then we need to add three Components box collider to detect collisions with other objects. We need to add rigid body to move this bullet around. And, of course, we need to add a script, um, to detect input from our players and then applying kit to our bullet. So let's begin with adding car rigid body, a rigid body to Dean. And I would like to change somewhere use here. We don't need any gravity on our bullet, so I will send the gravity scale to zero. I will change the collision detection from discreet to continuous and also, I will freeze irritation on easy access. Then I'm gonna add a box collider box school, either two dimensional print. I will set East Trigger. And the last thing we said we need a bullet script. So new script called Bullet. Great. And that and after a few seconds, we should see a new, competent hear called bullet script. So that's a double click on it. And we now have a new script inside off the visual studio. We don't need the update function, so let's relate it. But what we need is public float speed off our bullet so public public float, spit, and we're going on declare this spit off our bullet inside off the unity and the second variable We need these private again. But this time we need a rigid body today because we want to connect the rigid body off our bullet with these scripts. So now when we have these toe wearables, we can create, let's say shoot function, but we are not gonna create exactly and a function. But Corentin, you will see what escorting in a second instead of the white, which we usually use to declare our function. We're going all right, I in numerator, then our name. So let's say shoot. And then we can continue writing thesis as big as we would tweet normal function. But instead we we need to add a just one line of code. Again. It's called Yield return. You wait for seconds and I want to wait for three seconds. You will see why. Because first I want my bullet to shoot toe travel in the in the specific direction. And if the bullet doesn't collide with anything, I want the bullet to disappear from the scene from the game so it doesn't so it doesn't occupy too much off our memory. So let's begin first. We need to. We need are rigid body. So let's let's do this. I mean, our V is equal to get component. We need rigid body to deal. And now when we have our rigid body connected, we can apply velocity toe our bullet so r b dot velocity he's equal to transform dot All right, multiplied by speak. And after three seconds, if our bullet doesn't call I to it, anything we want toe remove this bullet from the scene so simple, destroy, game, object and that's on for the shooting function. But now we need to call this function or Cortines. So how do we do that? Start 14. Which one should, um, that's how you dio core routine. So now we have added functionality toe our bullet, but we can't shoot just yet because we haven't added ability to the player to shoot. So let's do that. Let's go back to unity, Select Player one. And we need toe at another point this time fire point in the same way we did with our ground struck so we can simply duplicate our girls check. But I want my shooting point to be somewhere like here in the middle off my player. And it was, you know, great. And of course, I would like to change the name, door fire buying great. And let's do the same for the player to and fire point is the point. The position when we will instead initiate when we will spawn are bullets. So we were extension bullet here and it will go in the right direction and if we face to the left, it will also go to the left because we rotate the the entire player so no one thing we forgot, I forgot. We need to do it. Make the pre fap off this the bullet. Let's first change the name, toe bullet. And now we can drag this bullet down to the assets. So we have a brief up and we can deal it. This bullets from the scene, the lit. And now let's go back to the usual studio Select Movement One We need to declare toe new, uh, wearables Fire Point and Bullitt brief up. So let's begin with public transform, and I will call it Fire Point and the same thing Quit Are bullet Prefect, we need public game object bullet Breathe. I will copy this because we're gonna re use this in the movement to script. So let's go here. Copy like that. Now go back to Unity Select Player one, and we can see that. Now We need to add a fire point and the bullet prefab toe the first player. So we tracking in fire 0.1. So our player and a bullet prefab here and the same thing can go sweet. Our second player. Well, his fire point and we need again bullet pre fat. No, we can go back to coat open visual studio and let's start with Player one. We're going to declare a new function called shoot Boy. It should. And we need to instance she ate bullet here. So Stan, she ate in a bullet proof app. Then where? So fire point dot position and we need to add a rotation. So five banks and done station and that's all we need for the shoot function. But now we need place where we will call it. So let's go under the jump if statement and let's at another. If input dark, get the bottle down is equal toe fire one. We want toe food and no, we can try these out or no, let's first copy that and go in the movement to script, and we can also copy this. If statement turned, let's go here, but we shouldn't forget to change the fire toe. And now, if I save it, let's go back to unity. And before we try this out, we need to set up input settings. So let's go under the edit project settings and let's elect input. We need to fire one. I will set fire one off my first player to be s on. Let's go under the 2nd 1 I will delete that because I don't need to. That and under the fire to I'm going up, declare positive button to be joystick. I bought them seven. So let's go back to unity and we can try this out so we have our player shooting. But Bullet doesn't move. So I again forgot something, and I have no idea what I forgot. Of course, we need to do at speed to our bullets. So let's say 15 and no. Do you think trying shoot my player shoots bullet on? Let's try within the second player. Also, my player shoots the bullets. So that's for the shooting ability. In the next withering the next chapter, we're gonna cover how to at health to our players and how to damage the other players when we shoot them. But for that video, that's all. And thank you fraud. Thank you for watching See you in the next video 8. Health of the Players (Script): hello and welcome back in the chapter, Number seven in the Last Widow. We have added a shooting ability to our players, and now it's time to add some health held to both of them. And some wind loose logic, of course. So last time we created this bullet brief up and a bullet script for these prefab um Then later, I realized it would be better to have two different bullets, one for the player, one turn to the 2nd 1 for the player to. So I have created a second brief up, and you should do the same exactly in the same way as we have created it. Bullet one and also script for bullet toe. I, uh, I said a different color for both bullets on bullet one. Dewey's this pinky color and bullet one is this blue collar. And now if we go back to who is your studio, you can see that bullet one and bullet. Two scripts are exactly the same. I have added this method on trigger enter to the tow boat off them, so let's begin with it. Anything held to our players, we can do this insight off any script that is connected toe player. So let's go toe movement one and down there under the number off bowlers jumps, let's at a public wearable with, well, you with our health. So let's say public ecstatic. We needed this wearable Toby static so we can later change it from other scripts Public static int and let's call it health. Then we need to set a value to this wherever we can do this. Ah, inside off the start function at the beginning, off the game. So let's say health would be 100 on. Let's do the same for our second player so we can copy that on paste it here. And of course, we need to set held value for the players to as well. So health is equal toe 100 and then we need to keep update on the well you off this health . So if it drops below zero, we need to remove the player or we need to at a 0.2 2nd player we see later. But now let's go in the update function and under this statement, let's at another each statement this time for health. So if held is less or equal to zero we want to, Let's say real haute, this window, this scene for now. So course we need to import seen management package. So let's go toe using unity engine dot seen management And then we can down there reloads in the scene with seen manager thought hello to seen And we can, uh, here enter the build index like one or as we did before, we can do it with seeing manager dot get active scene that build index And we have the building index off this active scene. And let's copy that because we need that as well in the movement. One script. So let's go in movement one up its function and we can copy that. But of course, we need also to import unity Engine got seen management here like that. And we, of course, need to save bought off the scripts. So no, we keep update on the health off both players. But then, of course, we also need a mattered to decrease the health. And we can do this by, uh, we can do this in the bullet script. Uh, here in the bullet one, we will try to detect the collision with player to and we will decrease the health off player toe and the same with a bullet to scripts. We will try to detect collision with player one and of course, we will decrease the health off player one. So let's begin with player one. So we want toe destroy our bullet when he when the bullet collides with anything on the scene. But if it collides with the the other player, we also want to decrease the health off other player. So let's begin with we have no bullet one. So yes, collision. That name isn't player while because we don't want to. Coli twit the player that should itself. We want just to detect collision with, let's say, platforms and with the second player. So if collision dot name isn't equal toe player because we have named the prayer one player and player two. So the collision that name isn't equal toe player, then the second condition would be if collision. That name is equal to players, too. Then we can decrease the health off the second player and we have to start the health where you in movement to script for the player toe. So let's write down movement toe that health and now we can degrees for anywhere you we want, Let's say minus 40 and that will decrease the size off the health off player do if we hit him with our bullet. And, of course, we want to destroy on this bullet if it collides with anything but player weren't so. Let's right after this. Second, if statement, I'm just trying game subject just like that. And now we can, uh, of course, we must save this script, and now I can copy all of that copy and let's go toe bullet to script well based there. But we need to go change the names here, so you collision. That name isn't equal to player to because we are in the bullets to script. And if we collide with play it one, we want to decrease in the health off player one by 40. So we have Ah well, you the health off player one saved in the movement script. So let's save that. And now if we go back to unity, we can tried these out, so let's get to play bottom. It works. Let's try for second player as well, so let's go down there. 123 It works. But why? We don't see and, uh, in bullet. Oh, I see. What's the problem? I forgot something else. We need to go in the movement to script and we need to do well, Stan. She ate, We instance, created a bullet prefect, but the wrong one for the player to. So let's go toe player do. And we should have added the bullet prefab. But we need for the player toe. Also the order bullet. And now let's try this again. Okay? Our player shoots and we killed the player one. And that's not trying, Player. One can kill the other player too. So let's go. Yeah, one and he killed the second player. So in the next widow, we're gonna at a visual representation. We're gonna add some user interface, though Showcase to show how much off the health has each player and something like overall score. Who has more points? But for now, that's all. And thank you for watching 9. Displaying Health and Score on Screen: hello and welcome back in the second half off the chapter Number seven. Ah, In this video, we are going to set up a visual presentation off. Well, use off health off what players and the overall score, uh, off the game. So let's begin with setting up user interface. Um, we can go under the higher he and let's right click on this empty space and we should add canvas. You will find canvas under user interface. Let's at canvas and double click on it. So these will be our canvas. And now we should at the scoring system to this canvas. So let's no select the canvas. Double click, right click and again under a user interface search for DNA Panda and the spanner will be our on our pace for presenting the heads off Plan one. The health off player, too. And some were here over our score. The first thing I want to do East to remove from thes background because we don't want to have any background. So let's go under the source image and let's select none like this, and Connor, we want needs to be fully transparent. Langley's and the last thing we need to do usedto at, um, next two thes banner. So let's click on the panel. Right, Right click and again, under user interface, search for text. It will be the first element here. So, uh, we got our for stacks. This will be our health one. So I will also call it help one? No, of course we want toe modify it a little bit. Let's put text in the middle. Let's increase the size to something like 20. And I want foreign stars to be bold. Text should be 100 soon into the corner of the text will be black because we have white background. And now, if I, uh, press the play button, we should see our shelled one in the middle of the screen. But of course, we want the health of player one to be in thes top left corner and the health off player to Indy. Stop right corner and I will put the overall score here in the middle. So stop the game and let's first move from this text. Something like, Yeah, should be okay now. I will duplicate this text and change. First the name this will be held. Let's move these text on the other side and I will again duplicated this text. But this time we needed in the middle of the screen and I will change the text of this one toe the overall score over our score. We have in the beginning off the game like this. Now we have set up our is in device. Let's try it out. It looks good. So now let's go back. We need toe write a script to toe access in thes user intern You I elements and of course, because we want toe change the text during the game. And of course, we need toe changed the name off this element here. These will be over, uh, text. So I will rename this panel to, Let's say, score and I will also add a confident to this to this panel called Score, of course, and hit near script. Create a net and after a few seconds we will get a new and you component here, double click on it toe open 18 visual studio. So now we have created a script toe change on health off both players on the screen and to display the overall score. Of course, we need somehow toe connect this, uh, user interface elements with the script. So let's first do that. We need to import another unity engine package this time using, you know, multi engine dot You I Because we will be working with user interface. Then we're gonna, ah, set up three variables. Uh, three public text where members the 1st 1 will be public next H one B's will be helped one . Then again, public. Thanks. Aged. Or? And the last one public text over there are like this. No, let's save this. Go back to unity and, ah, we should see here empty windows, um, to which we have to connect these objects. So let's connect health one toe. Each one has toe health too, and our overall tax toe the overall window. So now we have connected user interface elements with the script itself. And let's go back to toe visual studio. We can, of course, and to lead to the start matter, we don't need each For now. We will use update function, toe display, health. So we want to I've date, uh, during the game, the value the health off each player. So let's begin with player. Well, so H one well not text is equal to. And now we need to tow display here The text, the health. We have the health of player one safety in movement, one script. So let, uh, let's and get it movement dot held. And we need to cast that to strengthen because we will displaying text. And that's all we need. Toe display toe oblate the the head off. While let's do the same with players toe, we can copy based, of course, age do. And we need to make sure that we enter movements to here. And now we need some object, some script to store our, uh, to store our over our well, that's a score on. We need some kind off agent to keep track off this court off our game. So we're going to create a new object inside of the unity. Or actually, we can at this script toe that's a canvas because we won't be deleting our cannabis inside off the game any time. So let's at component to our cannolis. I will call it agent rule script Great than that, and we're gonna create a to public static integers in our agent script. So let's go under day into the script. And, uh, for now, all we gotta do is declare scripts. 1st 1 would be public static in Teacher. Let's a score One and again. Public static integer score two. So now we have a place to store the the health on. Um, we also, uh, have a place toe store the overall score off our game. Now, of course, we need to also, um, at points to the score. We need toe at 0.2, Player one and player toe depends on which on which player wins the game. So let's begin with player one. So if player one, uh, loses the game, we want toe at, uh, point toe the second player. So let's go. Uh, here and under, uh, I mean above the scene. Manager. Let's enter Agent. Not score too. Plus less one. And we need to do the same with the second player. So let's copy. What is that? And of course, we need the first to save this. Now, let's go back to movement door and here under the, uh, if statement enter, agent dot score is equal toe. Bless what? Now? We have added a point. Uh, I mean, score one. Now we have added the point toe the player one when the plant one wins. So no, um I want also to add a point to each player when other prior falls off the map. So let's go toe detector script. And we have entered this method on trigger enter to D and we can repeat Ah, the same process process we did in the movement scripts. But of course, we need to tow detect which player, uh, collided with our box collider. So let's write an if statement. So if collision don't name is equal to player So if player one, uh, fall off the map if player one collide the tweet our detector, we want toe at a point toe player, too. So we want to access agent dot scored. Two is equal. He's equals toe plus one. And in the other case and he's collusion. That name is equal toe. I plan to. We want to add a point toe the first Blair so a gentle thought score one. He's he called toe plus one. So the last thing we need to do is inside off our score script Now we are updating our health, our values. And it's time also to, uh, have date over our thanks. So let's do that over, uh dot text is equal toe, and now we can hear display the, uh, discourse off both players. So let's get it. The 1st 1 agent of score one plus, won't I really right? Like something thes plus agent, not score. And that's, I think all we got to do to display the score on the screen. And now we can, of course, uh, there's this out. Let's check this ality and M and everything's works as it should. Let's hit play button. So we have hundreds 100. Let's fall off the map. And, yes, player one. A player toe gets the point. Let's do the same. Which player? Toe? Great. Now we have want one and two. Let's try to kill the player. And yes, we are displaying the text on the health off both players. So this is how you displaying. This is how you connect user interface with the script and how you track the head off the players and how you, um, changed the values, changed the health and decrease the health and at all points. And that's also all for this widow. In the next one, we're gonna add some kind of timer before the beginning off each round, and we're also gonna at game over screen and boss screen. But for now, that's all. And thank you for watching. 10. Adding Timer in Unity: Hello and welcome back DC's video. Remember seven in this chapter, we're gonna set up a timer at the beginning off the game toe countdown. Uh, like, 321 and then start the game. Uh, first, we're gonna set up a simple user interface wheat, white background, and, ah, a taxed to display the time. And then we're gonna write Ah, a little bit off. Coat the script for timer for time, though for timer element. So let's begin. Uh, we already ah, Aditya cameras in the last chapter with our score object. And now we are gonna select this score object and let's set active to force. So we don't see any scoring on the screen. And now under the canvas, Let's great a new, uh, you I element again banner. And we're gonna use this panel to set up some kind off timer. So let's first remove this background picture. Ah, let's select background picture source lawn. Then we we can leave this white color as ah as, ah background off this panel. But I will set off a channel a little bit higher to, let's say, 2 to 5 like this so we can clearly see later. Ah, the text here and not the ah game it's of Ah, the next thing we can rename this panel because we will be using three or four different panels. So it's ah, wise idea toe name them. Uh, this one will be called Diamond and let's at another component this time two timer. And of course we need Next you will find text under user interface. That text, Let's ah, set alignment Toe media. Of course, we need to increase the size off this text and let's go under this scene on and focus on our timer. And of course, we need to ah, make it bigger, something like this. Let's set it in the middle of the screen. So we have Ah, new text phone style should be bored. Next, let's say tree, because we will be, uh, would be counting down on. And that's actually it for timer now. Ah, Now let's select the timer object, and we should at a script to this object. So at component, and I'm gonna call it timer new script, create the net. And we are gonna write, uh, some coat to this time. Our script right now. Now we should do 1st 1st thing we should do is to import using nt engine that you I so using unity engine dot You I Then I would like to connect my text to display time with this script. So I will declare a new public. Ah, public text. Wearable public text. Ah, let's ah uh Next. Then we need two more wearables. But this time static, you will see later why we need them for now. Let's just declare them The 1st 1 is public static float Probably ecstatic float. I will call it time remaining remaining and the 2nd 1 the 2nd 1 will be public static bull and I will call it time running. You will see later in this in this widow why we need both off them. But for now, let's go in the start function and ah, let's set time remaining to tree So time remaining is equal to three and we should set time running to be true And then in the update function Uh, first we need to check one condition. So if statement if time running and then the second condition if course if time remaining is greater than zero. So we have. Ah, time left. Then we want to Ah, write two lines of code here the 1st 1 time remaining. Mine's equal time that delta time and these will Ah, these will count down from our tiny time remaining. So if I write here three, it will count for three seconds. Then, of course, we need toe display This change on the screen we need to display this time on the screen. So let's write these down. We I need to use our text element So next that text is equal and we need here to display our time remaining. But of course, we want to displayed as ah ah ah whole number like tree to one. We don't to display the like the float like treat 10.13 point two So we need to use Ahmet function. Uh, met met f dot seal to integer And now we entered the float we want to use so time remaining and we need also to cast it to string because ah, text elements displace uh, they display string string types off wearables and not integers or float. So now we are displaying Ah, time remaining on the screen. But we need to check also if our time is up. So if we don't have any time left so if and then we right? Yes. As time running is no equal toe false Because we need to stop our timer. Ah, and the second time remaining is now equal to zero. We, uh now we have stopped our timer when time is up. And for now, that's all we're gonna right in this script. Let's save it. And we can go back to unity, um, to connect these text window with our text object. Let's drag 18. And now we can test these out if if this is working. So yes, we are correctly displaying the time on the screen. And now we can proceed with Ah, the next step. We want to activate the score, planner. So we I want to, uh, this panel to disappear from the screen and I want the score panel toe appear on screen. I will show you that in the next video when we will work on changing ah panels for each game state. And we're also gonna work more on this agent script. This script will handle all the logic off our user interface, so I'm really looking for it on. I hope I see you in the next video. Thank you. 11. Pause and Game Over Screen: Hello and welcome back in the last two widows, we have set up our score panel and timer panel. And for these widow, I think we could at a game over screen I mean game or panel. So let's begin. Ah, creating our game over panel in the same way as we have created previous two panels. So let's go under the canvas, go under the user interface, and again we select a panel. I will rename this panel toe game over and ah, as with a timer panel, I will now also select source image as non and I will increase this white color Ah, the Alpha channel of this white color to like I did with timer 2 to 5. And I will also add some text to display who won and bottom to restart the game or exit the game. So let's begin with text selected game over and under user interface select text again. We need to ah, correct the alignment. Ah, selects media. We need to increase phone size. Let's say 20 And of course I would like to change form, style toe world on. Uh, we should a little bit extent this text so we have enough space, I will, and I will put it there and text. Let's say, Ah, rat Player one. But of course, we will modify this text with our game over script or agent script. Um, but for now I will leave it like that. And I would also like to have one button to restart the game. So again, selected game over user interface. And this time we need bottom. I will modify this button in the way so we have a like button with black background and white text. So how we do that under the source image, we don't need any so non. Then, ah, under the collar, I will select black color and I will ah set normal color to also be black. The highlighted color again black. But this time with decreased Alpha Channel, let's say 2 to 5 and then the pressed color will again be black with alpha channel toe the maximum. Ah, and of course, I need to rename these bottom. Let's say these will be our ah restarted bottom restart really start like this and I need to also modify the text element off this button to say something like play again and off course. We need toe change the Connor off these texts to be white. I will also increase the size and form style toe bullet and to size. Let's say 20 uh, let's increase the size off the bottom. No, no, this is the text. Of course. We need to increase the size of the bottom. And I will also no duplicated his button. So we have. Ah, so we will have two buttons looking exactly the same. But of course, with different function so duplicate and I will change the text of the second bottom to No , I mean they restart button. Um, I will change the text off the second button too. Ah, man, you So these in button will transfer us toe the main menu off the game. And, of course, let's renamed Ah, the button to Manu Barton. And that's how we ah, that's how we get a new panna. This is This will be our, um, game over panel. So now let's go to our canvas and let's select agent. Now, I would like to connect our panels with this script and then we can modify this panel we can set with descript. Which panel is currently active, depending on a game state. So let's declare, Ah, a few public game objects. The first will be public game object and we have our timer first, then public again. Game object. We have our score panel, Yes, score panel. And we have also created our game object called Game Over, Uh, game over. And now let's go back to unity and Connect. Ah, these, um elements and these objects with our script. So we, uh, under agent script. Let's wait a few seconds to get these windows. So now let's connect our timer, which is here. Then we need our score, which is here and lastly, our game over like this and, uh, as we are in the state off creating Ah, Panelists Windows. Let's let's create the last one we need for the game. We will be using £4 the last one ah shows when we paused the game when we, um when we stopped the game for a few seconds or to restart. So let's create the fort. Ah panna, go under the canvas again user interface and to let select banner. We're gonna name this panel force so force then, as we did before, let's remove this picture. Select lawn and again, white collar wheat Alpha, Channel 2 to 25 like this. And no, I would like to add again some some kind of tax to this panel. So let's go under the posts, user interface and at text on modify it in the way you like. I will sat phone style against Boult, and I will write down a text post like this. Then let's move these text here. And I would like to have, um, three buttons here, one to continue playing the second to restart the game and the last one to, ah, to move in the main menu section to transfer us in the Manu. So let's create three buttons are select again pose Ah, kitty eight, um, user interface element button. Now we know how to do that, and now I want to have three buttons. So let's duplicate them two times, and I will move both of them. No. Now let's modify the text off each bottom. The 1st 1 will be our Corentin, your bottom. Of course. I forgot toe change the color to white, and I would like also to increase the size. So let's say 20 and phone style toe both. The 2nd 1 will be our our restart buttons. So these will be our Manu bottom phone style will be again Bold 20. And the last thing we need to changes color again. White. So now we have treat bottles. Uh, we can, of course, change the name to stay organized Kenya and, of course, our menu Bata. So now we have all for, ah, game panels. We have our score displaying on the screen. We have a timer at the beginning off the game. We have a game over panel and we have both panel. And now it's time to put them in. Use toe add functionality, toe all four of them. And that's what we're gonna do in the next. We though for now. Thank you. And see you in the next chapter. 12. Making User Interface Work: Hi and welcome back. This is chapter number then, and this chapter will be all about coding because we're gonna add functionality to our user interface. Um, first, think, let's set this pose panel to inactive and let's go over the game over Banner because we have added here Ah, a text saying which player? One is it a blue player or right player? But I forgot to connect thesis these text with our agent. So let's do this. Now. Go back to visual studio and, uh, down there below the our game objects, we're gonna of course, declared the fourth game object, which is post so public game object boss on. Um, we are also now gonna connect the text to display which player? One. So this will be public text, and I will name it. Some think like full one. This will do the job. Uh, we get ah, there are here because we need to import. Ah, unity engine dot You I So let's do this using unity engine dot you I and let's now also import unity engine dot seen management because we will need this later. So the error is gone, and now I will declare the last the last wearable we need. It will be static because we're gonna change it from other scripts also. So let's declare it public static off type bull and I will call it can play. You will see later why we need this Boolean. Um, But now let's start with our first function, which is also called Start and I want to set Ah can play variable toe force at the beginning. And what will this wearable Dewey's? Um, it will determine if the player can play or not. Let's say when we have our game over, man you or when we have our post panel, we don't want to. We don't want the players to be able to press any buttons like shoot, jump and move left right, just the user interface buttons on the screen. So let's that can play variable toe force at the beginning because at the beginning we will have our timer banner on the screen, and at that time we want we don't want our players to be able to press, to play so can place no force, and we're gonna call a start game function inside of the start, but of course. First we need to declare a new function. So let's go down there. Avoid Let's a start game. And we need to then call dysfunction inside off the start. So start game. And now what I want to do in the start in the start game function, I want to set my timers to be active, so set active is equal to true. And I want the order Panelists to be inactive. So I'm gonna set my scoring score, uh, to to be inactive. So set active physical force and the same with the post panna force. Not second set Active force and the last one East, of course, game over. Not sick. Set active is force. So that's all we're gonna doing the start function. No, Uh, let's declare let's go in the oblate function and we need to check if a player one or player to has reached ah specific amount off points. Let's say the player who reaches five points wins the game overall, so we need somewhere to check. Check this, and the update function is just the right for us. So let's go in the update function and let's right if statement if and Let's check first the score. One. If score one is equal to five, then what we want to do. We want to call some think like game over or the last screen game over screen. So we're gonna call here game over screen and, um, in the other case, if the second player reaches five points, we also wanna call a game over screen, but with a different era. Mentors. Because we will be, um, we will declare a function which takes in a para matter, which player? One. So if a player 11 then we want to call this function game over and we will say Player 11 or Blue Player one and prior to wins. Then we want to say Game over for Red Player one. Um, so let's go and declare this game or function. Let's go under the start game and to declare the new void, I will call it game over, and you know we need to set it to take Paramedic er's. So this function will require a string parameter, uh, which, which player? One. And then when we call this function, we need to pass in that data eso game over which player? One. And when our player one wins, we called this game over function quit. Ah, para matter, off blue. And, uh, when right player wins, we call game over function again. But this time we need toe passing rat course. Now we need to do at functionality to this function. So let's go in the game over function, and we're gonna right What? This function thus So the first thing we need to set our timer to be inactive So force then , uh, we also the same with our score banner set, active force. And we also want to enactor to set our post panel to be inactive falls. But we want our game over panel to be, of course, uh, active. So game over said Active is equal toe. Sure, but Aziz U S o before I have added a text which will display, uh, if blue or player or Red Player one. So we need ah, here. A simple if statement to check which player one So his which player one is equal to and will to check. If it's if it's a blue player, then we want to do this. And in the other case uh, we wants to. Ah, and in the other case, we want toe do the other thing. And what is this? Think first I want to set the color off this text. I want this text to be blue when blue players wins and the red when I read player wins. So let's do this first. Um, who won? That collar is equal to collar and let's see blue. And in the other case, I want my color to be all right. So let's set it toe. All right. Great. And, um, no. Before we display of the game over panel, we need to do one or think we want to set our who won text. So let's do that. Who want that? Next? He's equal to which player? One bless and then some text. Let's say Play it a lot. So it will say Blue Player one or read Player one, and it will be in the colors off the wiener. Great. So the last thing I want to do in the game or function is to set can play, um, can play worry able to be force again. And now we have done, uh, everything we need to beat our game over Bana. Uh, of course, we need also to add functionality, toe the bottles off user interface. So let's begin with our play again. Baton. Let's go down there and declare a new function. But this time we need to set it to be a public public quiet. Let's say play again because we will call this. We will connect dysfunction with Barton in unity. And that's why it needs to be a public one. So what will this ah function do? It will set the score off both players toe zero because we will be starting all over again and ah zero, Joe. Then I want toe activate the timer again. So, uh ah, timer from our time or script. Let's elect timer. That time running is equal to true. Then timer again from timer Skip. But this time we need a time remaining and let's set it to three on. Of course, we need toe activate at the time of panel. So let's select timer Panel. That said active is equal to true. Then we need toe set all the other panels to be inactive like we did before, So let's begin with the score banner that said, Active Here, Good force. Uh, then we have poor spanner That said Active is equal to force and the last one game over, Panna said. Active is equal toe force. And now, because we are starting ah, game again over again we can set can play to be true. So we will connect dysfunction with the bottom in the game later. Let's now continue and age and script. Uh, now we're gonna at, um ah, function to be called when we want toe pose the game. So let's create a function white dot called boss game. And what will dysfunction do? First, we need to check the can play wherever if it's false or true, so if can play. So if we, um half hour player, our game running, we want to do the next things. We want to set our timer to be again force. Then again, with our scoring. We also want to be invisible. So scored that sect exact, active, false. But this time we need our post panel off course to be showing so posed. That said, active is equal to true and the game over panel needs to be inactive. So set active force then because our can play is now true. We want toe set at the opposite. Well, you so can play is no falls. And of course, we want to freeze the game. So time that timescale is equal to zero. These will freeze our game on now, in the second condition. If our can play bullion is false, then we want to do exactly the opposite that as we did in the case above. So we can actually ah, copy a lot of things, but we need toe change the values. So timescale is now, uh, back to one. Um, timer, we need no, uh, again timer to be fools. Scoring is now visible. So scored that said activities. True. And, uh, two other banners we have Pause is now invisible. So sad, active force and game over. He's also invisible. So sad, active tour force. And the last one can play is now equal to true. Uh, and that's all we need to do with our post game. We're gonna also call it later. For now, let's continue with writing functions we need. So let's go. Uh, don't And, uh, the next one I want to add this to restart the game. So this time we need the public a public point public avoid Where do you start? Game and you need to Ah, cause we need the right here. Three lines of growth. 1st 1 would be to call seen manager and load on. You seen it will actually be the same scene, but we will reloaded. So seen manager that get I need toe select the right one Scene manager not get active scene that beaded index. And of course, we need to set both off the scores do zero and the same. It's scored toe and no, uh, disease are restart function. We need one toe continued to game. So public void continue game. And let's just call post game here because these will ah do the job just fine. Because when our game is supposed, we can call the postgame function and with this will set the game to continue. And now the last function off this off this long script would be a function toe. Uh, transfer us back toe menu. So again, we need the public function public right low to Manu. And again we need toe use the scene manager that load scene and we can copy all of that. But we need to decrease the index by one. And again, we need to said both off the scores back toe zero on under the scene manager. And that's all we need to do in the agent function. Now. Off course, we need toe. We need to connect this function with the Barton's in the user interface. Um, one thing I realized I forgot is off course. Um, how to call the postman You? Because ah, you need toe press the escape bottom toe call the post manual. But I forgot toe at that functionality in the update function. But we can do it right here right now. So let's go under this. If statement, let's make some space and we can write a second if statement if input dot get button down and we're looking for Barton called cancer. And if we get these bottom, let's call post game function as if can play. Then we can, uh, right here. I made a mistake here, huh? Of course I forget. Well, Rocket. So in the I'm sorry for death here, we can write which panel we want to activate and, uh, I'm getting really a little bit of tired. It shows I'm really solid Sorry for that. In the in this condition, if, ah, we don't get a cancel button, but we can play. We need toe, of course, set the scoring, the score panel to be active and all of the rest to be false. So let's do that. And then we are done with this script. So Taimur dot said active is equal to force score. That said, active is equal to true. Then, uh, the boss banner is, Uh huh is connective now, and the game over panel is also inactive. And that's all we have to do in the agent script. It's, ah, long script, I know, but we handle all of the user interface here, So let's not forget to save this script. And the last thing I would like to do used to go in the movement script. And now ah, down there in the fixed update function under the is grounded were, Let's copy all of that and the elect and way we're gonna write it this in the if statement . So if, um, agent that can play, then we want to do all of this. So let's no based it. And we need to do the same with movement toe. So go in the fixed update off the movement toe. Copy all of that, right? If statement if agent that can play easy called the truth, then we can copy based off that and that will prevent our players to move when the post or game over panel our actives on and ah, the one think I think we also need to do is in the diamond script. Yes. Ah, here. We need to write one. Ah, line of coat. Ah, down there, Agent that can play is now equal to true. So let's save this. We have all scripts saved and go back to unity. First thing we need to do is in the on the canvas object. We need toe assign game over posts and who want objects. So let's begin with game over. Let's drag in the game over panel. The next one is supposed panel, and the last one is who want text, which is under the game or panel. So let's drag in the text and then we need to assign ah functions to these bottles So let's begin with our continue button, uh, at new on Click you went and dragging the object with our agent script, which is canvas and select under the agent script. Select. Continue game function and repeat the process for the for the all the others but or the other battles. And now select the function, which is load. Manu and I just realized that we can actually optimize to off our functions. So let's go back to the agent and in the play again function, Let's and delete all of that and ah, writing time. That time scale is equal to one. Then reset. Score one and scored two and the last thing. Reload the existing scene and repeat that, Ah process Wheat Restart game, which will do exactly the same us play again function and also, at a time scale to load menu ah, function. And now, if I save this agent and go back to unity, we can test this out If everything works fine. So our timer timer panel is working fine. Let's try out post menu, which also works. Let's load menu and replay and everything works fine. Let's try out. Restarting Game also works and now we need to see the ah, game, or PANNA, which also shows up again. And yes, our user interface is now fully functional and way Cano at background music and sound effects to the game, which we will do in the next chapter, and for now, that's all. 13. Music and Sound Effects in Unity: Hello and welcome back in this chapter, we are gonna at a background music to the game. And we were also at one sound The fact on Let's begin with a Dinka sound. The fact toe the bullet eso when we shoot, we also play the sound effect off off our bullet. Uh, we can add a sound to the object itself. But first, of course, we need a music and sounds So, uh, let's drag in music off our choice. I will dragging this icon in unity and drag it down under the assets. So I have added one sound effect and one background music for the game. Uh, first, let's begin with our bullet. Oh, actually, we can choose both of the bullets, and we can at the component out there sorts under the audio clip dragging your, uh, sound fact, I have this sound effect prepared, and now we can actually modify a lot off a lot of settings. Here we can loop the sound. We can set the volume beach on so on. I will leave it as it is. I will leave volume, and I don't want to look this out. And now for the background music. I will go under the, um, in the menu Seen, uh, let's safe all of this and I will add a new empty object here. Let's create empty. I will rename it Toe something like Team and Let's at a component. We will get a script, uh, also called Team Create the Net, and this script will actually be really simple. We just want to write in it that we don't want these objects to be destroyed when we, uh, load another window. Another scene. So let's, um let's open up our team script and we can delete all of the functions starting update functions. Let's the lead boat off them and I will use another function called awake, and the only line in this function will be don't destroyed, unloved and we don't want to destroy these game object and that's all. These will prevent unity toe destroy this object when we load game. So let's save this on. Go back to unity. And now if we select our object, which is team, we can at again competent out your source. So let's at our their source and now we can add our background music, which is this empathy song. So let's a drag in. And now, because this is our background music. I want toe loop this sound and I will lower the volume toe something like 0.5, because I want these music to be in the background. And now if we try this out, we should, uh, we should hear in the background music playing from the start from the menu from the manual screen and then also later in the game. And we should her a sound effect off shooting when we should are to deal on their player. But for now, that's all. Uh, we have just one more chapter to go, and we will covering the next chapter. How toe it'll icon to the game and how toe modify how toe add it in the splash screen off our final game. For now, that's on and thank you 14. Icon and Splash Screen: So we are left with the last chapter off this course, which is how toe additon icon and splash screen off the final built. So when you finish your game, you can, of course it. And I can't do it. And you want some kind off the splash screen to display I I don't know your company name or your personal name or your logos. Or let's find out how toe add it that, um, we can go under the edit under Dad, hit bottom and let's elect project settings. And then now we can hear select the player element, and we can see here If I, um I will maximize that and you can see all of the things we can modify here. It's a lot of things. The 1st 1 would be your personal or company name on the product on the game of the name off your game. Of course. Uh, the version of the game and you can also add, um, I come here, so I will. At Icon, I was selected these I can, which I prepared earlier. Um, then you can, of course, select the default cars are off your game. Ah, and you have a lot off other things you can modify. Um, of course, one of the more important is splash screen. You want to have some kind off splash screen to display your company name to a display? Maybe the artwork off the game and so on. So on which you can dio Here you have defaults. Paresh splash, screen off the unity. Ah, Then you have the ability to change the style by default. It's light on dark, um, animation. And then you can add your own logos. And of course you can at again the background, color and capacity and so on and the background image. Ah, you have, um, ability toe at, um, different icons for different resolutions. Um then, of course, you can select if your game is full screen if its windows and so on. And, um, what, this you can change? Uh, you have. We're turning a reality supported on. Then you have ability to change supports for graphics and memory and so on. So on. But the most important for important for, of course, for beginners, developer is toe set up on icon and splash screen to display your name. Your company name your product name. And with that example, off unity Splash screen, we have came to an end of the scores. We have covered all of the basics on how to develop a simple multiplayer prototype with working user interface. Now you should be able to expand this game. You should be able to add new levels and game modes all you can start building your wrong game with your unique graphics and ideas. Just don't be afraid to try new things and nor from mistakes you make along the way. That's all from me. I'm very thankful for opportunity to teach you, and I hope you will find a good use for the new knowledge. But for now, that's all. And thank you idea.