Unity 2D and C# for beginners | Ekaterina Usova | Skillshare

Unity 2D and C# for beginners

Ekaterina Usova, Artist

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
20 Lessons (1h 60m)
    • 1. Introduction

      1:18
    • 2. Download and install Unity

      3:32
    • 3. Unity Interface

      9:26
    • 4. Components

      10:20
    • 5. Assets for your game

      13:24
    • 6. 2D Animation in Unity: basics

      6:11
    • 7. Coding in Unity: Basics

      4:35
    • 8. Function

      7:38
    • 9. Vairiables

      7:07
    • 10. Create your own function

      5:52
    • 11. Class

      0:59
    • 12. Coding your game

      0:34
    • 13. Character Movement

      12:45
    • 14. Character Jump

      10:19
    • 15. Animation from idle to run

      9:41
    • 16. Jump Animation

      3:18
    • 17. Collectable Objects

      3:21
    • 18. Counting Collectables and Displaying Score

      6:53
    • 19. Export your game

      1:54
    • 20. Thank you!

      0:25
38 students are watching this class

About This Class

Are you ready to create your first game in Unity? Then you need this course!

*please don't forget to review this class if you want to see more Unity classes!*

Join new class by Andrew Usov Skeletal Animation and IK in Unity (I translated this course) - https://www.skillshare.com/classes/Skeletal-Animation-and-Inverse-Kinematic-IK-in-Unity-2020/770641727

We will start from the very beginning: download and install Unity. We will talk about Unity interface and will create a real game scene!

You will learn C# scripting, and no prior programming experience is necessary! We will focus more on creating short and basic scripts that you can use in your projects. By the end of this course, you will be able to create a game and share it with friends and the whole world!

  • only useful information

  • all lessons are downloadable

  • no coding experience is required

  • get to know basics and get inspired!

Transcripts

1. Introduction: Hi. My name is Kate. Welcome to my Unity course. If you're on you immunity and want to create your first game, this course is for you. By the end of this course, you will be able to create a simple game and share it with friends. Learn how to get started creating your own games and unity. Ah, Powerful and professional. Close platform. Game engine. You will learn the fundamental techniques in unity. Development touches physics, animation, script in you, I and much more. We will start from the very beginning. Download and install. Unity will talk about unity. Interface on will create a reald game scene. You will learn C sharps grouped in and no prior programming experience is necessary. We will focus more on creating short and basic scripts that you can use in your projects. Are you ready to create your first game in unity? I hope so. Because we're starting right now. 2. Download and install Unity: All right, let's go ahead and install unity To do that. Go to unity does come and click on get started. Unity offers different plants for business on individual If you are beginning developer, this personal free plan is for unless you revenue from your products made with unity is higher than $100,000 in the last 12 months, you can use unity completely free. Amazing right. Get started. Here we have first time users and return in users. You can choose any option. It doesn't matter. I'll leave you through unity anyway. I prefer to you download this one next. We need to create an account without it. You can't complete the installation and can't import assets from Unity Store. I already have the account. It's pretty simple. Here. You have your email, user name, full name and password agreed to unity terms on Grady Unity. I D. And that's it. All right, let's run our application. All right, I agree. And installing protests started. We need to allow excess. Now we have the unity help, and we need Teoh. Add a unity version in click on ads, and here we have all the unity versions and We need to choose the last one off course, and you might have the new Aversa. That's good. Next. Here we have models that means platforms on you can check all these platforms or uncheck Samet them. But even if you don't do that now, you can always in style this platforms later. So a condom the installation protest can take a while. All right. Finally, the install protests is completed. Let's go to the projects, and they have these projects that I have done before. But let's click on new here. We have several templates on you can click on each and find out. What is this exactly this. For a simple game, you select either two D or three D, depending on your needs. In this totoro, we will talk about two D game, although the overall logic is quite similar. So let's rename a project, and you can also change the location here and we're ready to start, click on, create on lads, get into unity 3. Unity Interface: in this lesson, we will talk about unity, interface panels, tools, how to work with them, how to rearrange them and go back to default. Moreover, we will create an object and added on our C, we will talk about blame mode. What is this and why we need it? All right, let's get into unity interface. Here we have a sin view. This is the place where we create our game. We can zoom in and out by using mouse will on change the view. Uh, if we click here, select hands tool and we can move it over here we have a hierarchy where all objects which we have in Allah seen ah, stored that's click here. So right now, the scene has only one game object camera. And when I click on the object, that inspector panel right here chills the settings off the object. Each object has components, for example. Camera has transform and camera components, and we can add a new object by clicking on create. That's create an empty object. So we see game object. Here it is empty. That's why we don't see anything. What you need to understand is that the basic game object is the empty object which has one component transform. You see only one component. And if I add a sprite object, let's do it to the object Sprite. This bright object Here it is the sprite object. Is there empty object with the Sprite renderers component? All right, let's go ahead and choose a sprayed for hours. Pride to do that. Click on the circle right here. Right now we have on the standard ones because we haven't imported any SS yet. Okay, I choose this circle. All right, let's change its color back. This, okay? It is really small. Help you see it? And yes, the circle right now is on our sink. Panel on up here. We have different tools. Move, Rotate scale. And this one is move. Rotate in scale at once. Onda, We also have ah wrecked toe rectangle toe. All right, let's select skill tool and make my circle bigger. Like this, huh? All right. And off course, You can also change its size, position and rotation here in the inspector using the transform components, for example. Now let's move it. I select move tool here And if you want to your object for example, along a horizontal axis, you can click on this arrow and and it will be moving on the, uh right right here, right and left. And so another axis that's happened out. But if you click here, you can move it all around the scene. All around that screen there is, Ah, one good way to rece. Enter your object Just right. Click on transform and select. Reset. Now the position is 000 That means that yes, it is in the center of the scene. But yeah, it's Ah, it became small again. So let me fix it like this. And there are hold keys for all these tools. Q w e R T y so Q s for the hem tool W for move if irritation and so on. ID like to rename your object selected and breast have to. That's right, you name it circle. All right. In addition to our circles, bright I add another one. Let it be something like this. All right? No, let's make it's bigger like this. All right, So this is our ground. Let's again select the object and type ground. All right, over here we have a project panel, which displays all the assets we have. So we can simply drag and drop our assets from here to the hierarchy panel on they become visible on the same panel. So let's see, What do we have here? We have a scene sample seen here bells. How s prides next to the scene, there is the game view and it shows the way I was seeing. Looks in the game right now. It just our circle and this white ground. Well, it's not white, I think. Let's change its color. Teoh. To what color could it be? Purple. Nice. Okay, you can rearrange panels just aware you like, for example, But the game here, put this panel here. Remember that you can always click here upper right corner off a screen on choose default. Okay. I prefer to move the game view down there so I can see the game view and the singing you at once on the project panel next to it. Here. Good. Next thing is a plane mode. If you click here and wait a little bit, yes, you should rate the plane mode starts and you can play your game. That means all objects start to behave like they do in your game like they will do in your Nothing interesting is happening right now. But it will. I promise. Remember if you click somewhere while on playing mode, for example, Try Teoh, move my ground like this. This adjustments will not be saved. Look, you see, eight came back. So don't forget to exit that plane mode by clicking here again. So one click here to turn that plane mode own on board. Next. Click here, Teoh. Turn it up. 4. Components: in this lesson, we will talk about components how to end them. Why we need them. You won't get to know too important. Physics components Collider Andi rigid body. Finally, we will learn physics materials which help us to set bounciness and friction. As you already know, all objects are empty game objects with different components held to add components that's click on our object on and click here at component. You should understand that there are actually two separate physics engines in unity 143 D physics and 14 to D physics, for example. There is ah, collider component to d you say is just, uh, you know, plane playing object and full three d. It's like a cute right now we work. We work on our to do game, so we will use to d colliders. So the basic components physics once, Because if we right now, click on play, nothing is happening. So I accept that plane mode. Onda. We need Teoh add a collider. So at Component and Circle Collider from my Circle collider, components defined the shape often object for their purposes off physical collisions. A collider which is invisible, does not need to be the same shape as the game objects smash. There are simplest colliders box, circle and compound colliders. So we have added the circle one. Do you see this green circle around our object? This is it. Now we can click on Edit Collider here and make it smaller. All bigger. All right, let's go ahead and add a collider for our ground again. At component this time it as, ah box collider on you see, maybe it is too big for our ground. Let's click on Edit Collider Just like this A little. Okay, pretty good. No. The game objects have physical shapes and can participate in physics events, but they can't initiate them. They don't react to physics. Forces on is not influenced by gravity. So we still don't see any differences in plain mode. So we need another component redid body. I select my circle that component Regent rigid body to D. All right. Redid bodies enable game objects to act under the control off physics. So I just add it to that rigid body to d to my circle. And if i m to the plane mood, I will see that Yeah, my circle is that my circle is falling down. Stood again. Do it again. Boom! All right, so it has fallen down because of gravity. And if I uncheck the collider ah, that game object will simply pass through Ah, one ground because it doesn't have ah physical shape. You can also add physics material. T object Speaking about two d object Their physics material helps you to add bouncing this Andi friction. Let's go to the project panel on click on Create basics material to D on Let's rename it t bouncy. All right. And you see, there are two parameters here. Friction and the balance in this. Let's said bounciness to one. All right, and click on my circle. Find my collider. Let's check it. And you see this material here, the material slot. You can simply drag and drop our physical physics material here. All right, that c move. Yea, yeah, this is this is now bounciness. That's right. All right. Now the objects not only react to the physics forces and other colliders, but it also does it in a bouncy manner, which is great. Let's duplicate our ball by clicking control D. All right, let's move it a little bit and change its position for both circles. Thank ISS. Okay, Now select the 2nd 1 and let's take a look at the redid body. So we have mass here. That is the weight off our object. And also we have gravity scale. So if you're game needs a normal gravity, for example, like on other planets may be looking Address gravity here. Let's, for example, type something So you see this is the ball. This is the circle. Now it's look and now it looks more like a ball. Well, anyway, it is the object with a normal gravity and this is with a normal one. More thing about rigid body is body type here. Ah, there are three options or body type. Each defines a common and fixed behavior and dynamic rigid body to D is designed to move under assimilation on and aesthetic rigid body is designed. She not move under simulation at all. A cinematic rigid body to the is designed to move under simulation but Onley under a strong user control. So while a dynamic, rigid body is affected by gravity and forces that Kim thematic rigid body isn't so, if we need for example, reached body for our ground on if we don't change its body type. So let's see what will happen. Yeah, our ground is falling down because of gravity. So all we need to do is just sad static here and right now it doesn't move, doesn't fall, which is great. And let's go back to our bouncy physics material. Onda. Um, let's say you need a slippery object. So, for example, that's make our ground slippery. I will use the same material, said the friction to Zeron, bounce nous to zero and rotated a little bit. Selectman Ground irritated and don't forget to drag and drop Oh, a bouncy here. And let's check that our circles don't have it. Okay, good. So no friction, man. Slippery. So that means that our ground a slippery now like ice, for example, if you're platforms made from ice, it can work for you. Each unity component has this little blue book over here. Andi, if you click here, you open unity manual on can get all the information about this component. So you need to do communication can be very, very useful. And I encourage u t read it from time to time. But to be honest, I don't need to encourage you because you need to read this documentation. So now you know how to work with components, how and why to add them, added them, and even know the most important physics components. 5. Assets for your game: in this lesson, you will get to know where to find game assets and how toe you birth. Um, we will talk about for fabs immunity and learn how to work with them. And we will add and riel character on Allah scene and give him physics components. Let's talk about game assets. They are everything a user of your app will see characters, background platforms and so on. First of all, let's create a new sing while no, soon. Um, that's safe. This one. All right. So I encourage you to click here next to this seeing you we have assessed or and Le Guin into Unity Acid store. They have a bunch off absolutely free assets. Waas characters and backgrounds on these assets are certainly useful When you are learning or creating your first game. Onda, we can even click here three assets and we got a really very large variety off free assets , which is really great. I will use this sportsman room Black hammer. Thanks, buddy. So click on download here. But I have already downloaded so I have inferred here and after you downloaded it Just click on import and it takes a while for it to ah, to be ready. So here are all the files which are included in this pack. Let's have a look what we have. We have sprites. It's just our character divided by parts. I can you see Head legs shield. We also have animation here, and there's great. We got an oration files. So we also have a demon seen on and other files. In case you don't need something, you might uncheck the boxes like this example. But but I'd like to input all these files, Hubert. So now all the assets are being imprinted t our assets folder here. Let's hold on for a second. We're already Yeah. So, no. In our assets folder, we have us lows Wardman on It contains older folders that we have seen previously. Um, let's find our ah, hero. Let's find Hiss Prefab. And I'll told you what? What? It iss later. Whoops. Didn't minute. All right, let's turn on the plane mode. Andi. Yeah, we see the animation off this character, so this position means idle position. So the character is Tane still on and do nothing, but he has Teoh do something just in order to look interested All right, let's take a look at the hierarchy here. So you see that next to the sword Man, we have this blue box, so the blue box means that it is a prefab. Prefab is ah, template unit is perfect. System allows you to create, configure and store a game object, complete with all its components, property values and child game objects. As a reusable asset. When you want to really use a game object configured in a particular way in multiple places in your scene or across multiple scenes in your project, you should convert it to a prefab. They're just better than simply copying and pasting the game object, because the prefab system allows you to automatically keep all the culpas in sync. So any EDIs that you make to a prefab assets automatically reflected in the instances off that prefab, allowing you to easily make broad changes across your whole project without heaven to you repeatedly make the same added to every copy off the asset. So let's take a look at this brief up. It consists off. What? Let's see Sprite fender, right? This brief app consists off sprites. The simple price like the ball we created before they are PNG files. Let's take a look. It's too small, but you can try to make it bigger. But is it It's his leg. Yeah, maybe. Yeah, definitely. It So, yeah. In our assets folder, we have all these prides, you see, And to remember, in the very beginning, we had Onley sundered sprites like circle and, uh, Square. But right now, we have all these brides because they're wore in the assets pact that we have downloaded. And if we click on the sportsman, we see that it has there any mentor component. We will talk about it in the next lesson and off course. You can create a character or a background or wherever by yourself. Just don't forget to put each body part to a separate layer. If we are talking about characters and if you're going to any Maitham later and if you work in photo shop, save you drawings like PNG files and simply Dragon, drop it to your assets folder here and then added to your scene. That's it. How a character does not have the important components you already know Rigid body on collider. Which means we need to add it. But in most cases, rigid body and collider are included to the character on the gay sin leads. Why did here Tomo prefab here? Yes. You see the hero from the gym? A scene He has rigid body on capsule Collider. But we're game developers so less. Is it it? Andi ad These components by Alice helps. Let's click here. That component, buddy Dynamic type. All right. And collider. Your capsule collider is what we need Can either use box collider in this case or capsule collider. All right, click on Edit Collider. Let's make it bigger. The one more thing about pre fabs we have created rigid body and capsule collider while this Wortmann was highlighted. And we have these small glasses. Do you see it? That means that component is not added in the prefab. You see, the animator component doesn't have the plus find overrides here. Next choose your components and ah, play apply to prefab again. I fly apply to proof up. All right, so now there are no pluses. That's good. But, uh, it's ah kind of bad way to do it. The better way is to click here and open our prefab Andi in this view and components, and if you add components here, they will be inside the prefab. So I have created rigid body and collider for my player. And now I need the ground. It's create right in the sprite. Rename it to round. Choose one off this rights something like like this. All right, let's make it bigger. Well, it looks awful, but that's because it it wasn't a designed for this manipulations, All right, to have my ground. And now we need to add of the same components for all the ground box collider first added collider to make it just the way our shape iss good. And let's head region body, the body type is static, all right? And I want to do one more saying we have other any matter here, but I'd like to related because eso to Dili the component was simply need Teoh, right? Click on it and remove component. All right, the this animator component was created by someone who created this, uh this character and this this scene but it doesn't work just the way I wanted, So I want to start from the very beginning. So no animator just rigid Body Collider on this hole. All right, so now we have rigid body and collider for a character and war up ground. Let's play the plane mode and I'm expecting my character to fall down. Yeah, off course. And one more thing. Go t our character. Click on rigid body. Find constraints here. Andi Check. Freeze rotation, is it? If we don't do that, the character will be retaining while fallen. Although you may need him to rotate, it's up to you. But in most cases it's Barrack chief presentation alone. Z access. Hey, we have our character placing on the ground. Isn't it amazing? Let's go to the next lesson. 6. 2D Animation in Unity: basics: and this. Listen, we will talk about animation and unity, how to any made your character using any mater component and Sprite animation. Animation is a big and important part of game development. Animation gives character is live, they become more interesting. And as a result, a user wants to play your game more. So let's go to the animation folder and find this file. So this is any waiter and this elements are nuts, which are connected somehow. And this elements are animations. So you see this, Ah, window animation, Go to window animation animation. All right. So, for example, we have idle animation. Here we have our body parts on the timeline. Do you remember that our character consists off parts? This is because the designer who created him was a clever guy and did All right, So now we can change the position off characters, body parts create an animation. That way this is all want any major component? I go Teoh, our sportsmen on here we have our removed component. So right, click on ads. Room of component. Revert on. Do we have this component again? After that, I go back to the scene of you move my character a little bit. Good. Let's go back to Animator eso right now. Our sportsmen has the any major components. Controller Schwarzmann, This is our source, man. Animator. Okay, so it all starts with idle animation off course. So if we click here, we see the properties. Oh, in the animation panel here. And we can click on play and see this animation so And we can manage it, for example. Make it faster Like this. All right. Okay. After that we see that we have a body had and weapon. We can, for example, click on head here. And you see that that had selected Now, for example. Ah, put this line right here and click on the red circle. It means wreck. And now, for example, do like this with our head. That's kind of creepy. All right, let it right now, you see? Yeah, It works like like it has to work. So to create anything with your animation, you need to first select when you want it to happen. For example, Here, here, here, here, Or even here after that select ab body part or just a part off your object, for example. Let's take our weapon and click on this circle and do something with it. For example, let it like this and rotate like this. All right, click on the red circle again and let's see, what do we have? Boom. That's kind of funny and creepy, but it works. Let's get. And of course, if you don't like something, you can simply, uh, select this point and, for example, adjusted here. Example. It's, uh, said, It's like 10. Andi, let's see. Boom! All right, all right. I'd like to tell you about another type of two D animation Sprite animation. I have downloaded this coin. Drag all these files to the folders, right And one of these coins on the scene panel. All right, Next. That's creating animator components for it and create any major in the folder, rename its to coin and create a new animation. So after that, let's select all this prides and drop them to the animation. Let's make it longer and OK, that's just it good. Our currents rotates. All right, so this pretty it's about to the animation in unity, What you need to know to start 7. Coding in Unity: Basics: in this and next lessons, we will talk about coding immunity. You will create your first script and get to know c sharp basics necessary for effective coding. So do you need to be a programmer to develop your game? No, but you need to know a few things about coding and understand how it works. Because, yes, we have imported the assets. But how to make the move interact with each other? Shoot, jump, run. All these things are different from game to game, and you need to understand how to set your own parameters. Script in tells our game objects how to behave, held to interact with each other on etcetera. On script in is nothing more than a component for our game object scripting in unity as different from pure programming. If you have done some pure programming, for instance, you created Iran and app. You should realize that immunity. You don't need to create the code that runs the application because unity does it for you. Instead, you focus on the game. Play in your scripts. The language that is used in unity is called C Shop. Let's create a script to do that. I go to the project panel. Find the folder scripts, or you can create your own folder. Uncle can create and find C sharp script here. Let's rename it to test. All right, so now this script is not, uh, connected with any game objects, but we will connect it later. Double click on it on the visual studio's. Open it. The visual studio was downloaded with unity. So you have it. But off course you can use any other program to code. All right, so up here we have all libraries which are used in the script. Libraries make the game developer lives easier because they contain classes on functions Insight on. We don't help to invent them right here, public class. And we have the class that has the same name with our script. Do you remember that I renamed my script to test? So we have test name here. Andi, this is very important. If you're in name your script, don't forget to rename it here. Inside the script, let's study the theory. There are variables, functions and classes, variables hold values and references to objects. They're like a box that holds something for us to use Variables start with a lower case. Letter functions ah, collections of code that compare and manipulate these variables. We organize code in functions so that they can be easily reused multiple times in different parts of the program functions. Start with an opera case Letter Classes are a way to structure coat to wrap collections, off variables and functions together to create a template that defines the properties often object right now in our code, we see the class here on two functions here, start and update. We don't see any variables yet, So in the next lessons will be talking about all this and you will get to know how to use it in your game. 8. Function: Let's start with functions and take a look at this function. Start when writing the function. Remember that functions start with the returned type off the function at the beginning. Avoid in this case, followed by the name off the function. Start on, then the parameters in parenthesis. We also have curly brackets here which, surrounding the block of code for this function functions can do calculations and then return a value. You can ask a function to do something, process the information and then return an answer. If you use the type void, let's just like we have here then then not returning anything. This is the function. Let's go inside it and type print. That means we use the function print inside the function. Start. All right. And you see that the program? It's not unity. It's the visual studio. It helps us to you. Right? Allah code. So I I was typing print and you see it. Show me prints. All right, Now this open parenthesis and tie. Hello, guys, guys. All right. And don't forget about Sammy Colon. They're necessary. All right. So safe. And now I expect to see low guys when I start my game, right? No. Right now, Alice grouped is not connected with any objects and it will not work. So it's just a script in our folder. You should connect script with particular objects. In my case, I can simply driving drop its for example That's connected with our camera like this. All right, Now we see the script component here, and the name is test. Now, do you see the this? Hello, guys. We need to open console here and start over game. Go back to console muc. Hello, guys. All right, on. I think I better delete the animation you've composed. Okay, so the function start works when the object. In my case, it is the camera because I have edited us grouped to the camera when? So when the object is created in the very beginning, the object was created on DWI. So hello, guys here. But there is one function which works before the start function. Just cold. Awake. That's type it. First of all, returning type than the name of the function. No wake. All right. And to do the same thing. Print runt. Uh, my game is awesome. All right, save it. Go back to unity Go to the plane mode console. All right. And we see that the first message we help is my game is awesome which was which is inside the awake function and up to that we have Hello guys, which is inside the start function. But the starts, function and awake function they work only once. For example, start Ah, works on Lee when the games start. So we see our text only once. In most cases we need the update function because this function gets called every frame. And thanks for that We, for example, can move an object every frame, for example Let's create a variable inside our class. Don't forget you see this Brekke is here inside it. That's creative Arab ally, which is a number on you we need to type into it would like to declare a variable, which is an integer a whole number like 251 10 and so on. All right, so I It's the name of our variable on. Let it be one. All right now let's go inside our update function. Let's sprinted print our I've arable and let our I increase every frame safe. Go back to a project. All right, so what do we see? We have the next number. Each frame our variable becomes bigger. Every friend. So the movement off non physics objects timers on the detention of input. These are just a few things that I usually don an update function, but pay attention. This function is not called on the regular timeline. If one frame takes longer to protest that the next one, then the time between update calls will be different. That's why I want to tell you about fixed update function. This function is called on the regular timeline Update function runs once per frame, while fixed update function can run once 00 several times per frame, depending on how many physics frames per second, a set in the time settings and how fast or slow the frame rate. ISS. This function is used for regular updates such as a Justin physics objects 9. Vairiables: Let's go ahead and talk about variables to declare variables. First, check the visibility keyword, then the type and the name. For example, public light the type flight onto the name my light. So again the public is the visibility. Keyword light is the type, and the and my light is the name. There are two main visibility types, private and public. What's the difference, While private can only be accessed within this particular script within this particular class, if you make this public, then it's accessible toe all the scripts and other classes, so that means other people can access it and change its value. Moreover, public variables can be changed in the Inspector from the Unity editor, for example. Let's create wearable a on and public be. And so here we have our public variables, my light and B, and we can change it. For example, my 10. And remember, we can't do it in the plane mode because it will not be safe. So type ton. If you change variable here, the unity who used this number. So let's go back to five. But what if we want our variable to be private so that no others groups and classes can modify it. And in the same time, I wanted to be visible. Well, here is an attribute serialized field in the square brackets. Let's go to a private variable. All right, safe. And now we're going to see the A. Yeah, here we go. Hey, it is still private, but we can see it and modify it in the inspector panel. Okay, Now, let's go ahead and talk about variables types. You already know the type and hole number. There are many types, like florid. Hello, it is. Ah, float point number like 10.6. And don't forget Tiu type. If after that, if you use float type After that, we have stream type. So string is a stream, for example, is type. I love my game. All right. So a stream, Uh oh, yeah, we have way already have a So let's use all the letter C. So that's why I love this visuals to you. Because it helps a lot. All right. After that, we have bull type. Boom. The bull type is true locals. So these are standard C sharp types. Okay, let's save it and take a look. How it works. in our game. So yeah, we see a B de c e itself. The e is a bull Variable checked minutes. True, unchecked, Miss False. As I told you, this types Ah, standard C sharp types. But besides them, we have many types which works on Lee immunity. Such a slight. Here also, we have ah, camera type camera. Um, we also have even rigid body. I think you remember If you need a venerable rigid body, you can use this type and the reason we need to know our type. ISS, for example, if you're trying to add two things together and their types are end like we have here A and B and and so you notice says, Yeah, I can do that. And if you try to add, for example, be indeed so end plus floats. Yeah, no problem. For example, let's go inside. I'll start function, um, create a new variable em and let it be people's plus d. The work type means Hey, compiler, find the type by yourself. So and after that, we print our m All right, safe. Go back to unity. So right. And when I was start function was cold in the very beginning, we have ar 15 or in six. Andi, I think that's correct. That's five lost, 10.6, All right. But if you're trying to add two variables, one of which is int and the second ISS up, for example light. So unity can't do that because it doesn't know how to manipulate them. So that's why the type is important and you should never forget about it. 10. Create your own function: Unity has a number of functions which are useful, but we can create and call our own function. Yes, you remember, a function starts with the return type, followed by the name off the function. Let's call it test function and then the parameters. And let's do the same thing which my start functioned it. Koppett basted here and one more time. Pay attention to these currently briquettes. We use them if the following code is more than one line. Because the function doesn't understand that the second line is its line also, and as a result, works wrong. Also, you should understand that unity calls its functions for us, for example, the start is called In the very beginning. The update function is called every frame and so on. But who calls my function, which I have just created? Well, we have to find a way to call it. We have to call it from another function that unity calls or from another script. All right, so I'm going to call this function from start function, meaning my test function is called in the start of my game. Just function. All right. All right. Okay. So let's see whether it works on his here. We helped the same number because we did the same thing. But now we received it from our test function, not from the start function. All right, let's, for example, add something like people's D plus plus. Mm, plus a. Okay, we have our favorable here. So it so that we have another number console? Yeah, 19.6. All right. And we use void type all this time, meaning that the function does not return anything. But let's create a function which returns into variables. I changed my return in type from avoid toe end because the function will return whole numbers and add two parameters divided by coma. So brushes who are one IHS or to of course, you should understand that the end is the type of variable Andi, Bar Juan and war to is their names. All right, now as ill, it it's here. Okay. And let's declare in bar three were one plus or two and ask our function to return it. Return to our three now. Good. Had to the start function. I'm gonna call test function from here. Andi, Since it results in bar three and returns it I'd like to add values for Barbara Juan and bar to and bring to the result deserted to do that, I declaring you variable my bar. All right, so it's equal to my chest. Function on and let it be. You see, we have, like, in for one in toward to just the way we have type it here. So, for example, 503 but coma, All right? It should be just the way we wanted to be here. We have two parameters here. Bubbles are int. So I use in type of variables here. Five country. All right, and now that's great. Print this variable. All right, save it. Let's go back toe a project on and check it. All right, go to console. So here we have eight. I hope you remember that we still have that date function. The hour I variable increases every frame. So dont pay attention. Toe that. So we have eight on this best true five plus three is eight 11. Class: finally, a few words about classes. That's the beginning. Developer. You need to understand that a class is a group off interrelated methods and variables. A clause defines the kinds of data and functionality their objects will have. A clause enables you to create your own custom types of grouping together variables off other types, methods and events, for example, transform component, which represents position on the rotation and scale. Almost every game object has it, and transform is a clause which was created and built and unity so we can manage it in a very easy way. We will work with glasses in the next model. I'm going to introduce the most useful classes there, so let's go. 12. Coding your game: welcome to the most useful model in this model. We will talk about things that you are very likely to use in your first unity game. I can't overestimate the usefulness off the next lessons You will get to know how to make your character move and how to program his interaction with other game objects. For instance, when a character touches a Cohen, he takes it. All right, let's get into it. 13. Character Movement: I create a new script for our character. To do that, click on at component script. No script, and you can create any name you like my choose movement. Let's create and add. All right. The component was created, and now we can open it. All right. Click and its script in this last and Will will talk about movement and get to know input. Input is a class which help us to read a user's inputs. For example, I want my character to deactivate when I press the space bar. To do that, I need to catch the moment when a user presses this particular button and then deactivate the game object. So let's go inside the update function. If you right and no, we need to declare our object public should be public. The type is game object. The name is lunch. All right, so let's take a look. Input is a class and geeky up is a public function inside this class, since it just public, we can see it on. We can use it besides, get keep up. We have a bunch off all the functions here, like we'll show you input, get key down or get key so that's generated and get Keep up is working. When a user really is is a bottom while get key down is working when he presses it okay s get Chiappe is a function we opened parenthesis on Declared what bottom to use by type in key coat key code consists off all the buttons we got on the keyboard or joystick. I choose space we've done with that condition. It was that condition If a user presses and really says space now we decide what is happening. In that case, I want my object to deactivate And, as you might figured, said active deactivates or activates the object where true activates the game Object and falls Deactivate it. All right, let's save I was grouped and go back to unity And now we have this object slot because in our script we have the public bearable object that has type came object. So I just drag and drop my sward man to this lot. Let's click and play. And so nothing this happening. And now I press the space bar And then I released this pays bar. My character dicta rates He will not come back in the plane mode because we haven't killed it yet. Let's change our game. Object to the head, right? Let's see space. So no head and a creepy again. All right, now I want my character to move right When a user presses the right arrow old letter D and we're left when he presses the left arrow or letter ache lead. Still it this First of all, I need to declare their variables, which defines the characters speed. Most of the parameters in unity are flowed numbers. So I declare the flowed variable public type, float name, no speed. Of course, you can create any name you want on and let it be 10. And remember, if you are declaring load bearable, don't forget to type F after the number. Let's go inside the update function again. All right, I'm using the If again. So I use get key in this case because let's move the course or over it. So right now it returns true while the user holds down the key identified by the key key code in, um parameter. So it means that our character is moving while we're holding the button. He will not just make Ah, once top and stop. No, he will continue his movement. All right, so we have a condition. Now let's take the transform component and translated in a particular direction by creating and you vector rector three and I multiply it by move speed and time. Delta time. So what does it mean? Vector three is a structure in unity engine, and for you to understand, structure is a quite similar with a class. This structure is used throughout unity to pass three D positions and directions around. It also contains functions for doing common vector operations. So I used new to create a new object from it New vector with three components x y and said , Since we're making a two D game, we can managed only first to X and y. If you're making an three d game, you have the third Access Zet. Next we have a move speed which controls our movement and time. Delta time, that competition time in seconds since the last frame, it provides the time between the current and previous frame. And we really needed inside the update function because if our game slows down, our object will twitch. Aunt time, Delta time helps to smooth out a movement. All right, let's copy it on. Create a function for the right arrow. This time I don't use the game object bearable. Here we have our script as a sworn mons components, so it will work for these particular game. Object on if I want, for example, to move other game objects I can create and you screw up for them and I can better control my code. All right, so we have our move speed here, and, uh, we can control it. But right now, let's just enter the plane mode. All right? I press the left arrow, press the right arrow, and yeah, my character is moving. Let's change them of spit to three, for example. And his stops when I when I released the button. Okay, that's awesome. But I'd like to show you that all the way to move your character. We're going to use access this time. That's still it. It I greet afloat. Variable a equal Teoh input. Get access, get access, uses our access and instead of horizontal the stream here, maybe vertical and not hunger. This if you go, if you go back to our project. Then go to edit project settings and find out input. Here we have excess and to see all the access we can use, you can also see their reserve batons for each accident and even change them. For example, you don't ones a on D one chooses that and X Okay, let's go back to our script. My next step is to declare a variable inside Rector three. It is a vector with you Coordinates X is a horizontal position. Onda we type h This is our age bearable. And after that I take the position element from an object transform component. So previous position plus movement wearable. Multiply by move speed and time Dale to time. Okay. Okay, guys, my arrows and my object is moving all right. And I can also use a nd. And it is really useful because some users prefer to use a nd buttons, others like arrows. And our game is perfect for waas off them. I have shown you two options how to code a movement, but there are many of them. And I just want you to understand that in coding there are always many solutions for one problem 14. Character Jump: can you do again without a jump off? Course you can. But I think you should know how to make your character jump. Jump is not a simple movement. Up and down, right? It is a push off the ground which has force and acceleration. And then the object goes down because of gravity. Not because we told him to do so. Therefore we work with physics here. Let's take a look at this collider. We have created colliders for hours Wardman and the ground. But we have a problem when we are in a plane mode. You see that I was Wardman doesn't stay on the ground. The colliders cannot cross each other, so I decide. Teoh, deal it this collider and create box one. Okay, let's open our sward Hman, go to Capitol Collider and remove component. All right, Now let's and another component walks collider to D and it's collider. It should be just the way our character is so that his legs can stay on the ground. All right, maybe too big. We have another collider for hours Wardman. And right now, if we are, if we turn on the plane mode, we see that our player a stain on the ground. But we still have this, uh, little little line because here's our ground collider. He's over characters Collider, and they cannot cross each other how he can push off to jump. I'll tell you, let's go in our prefab and create a second collider like this. But it should be. But it should have a part which is under our characters Collider, and the next step is to select the second collider. With that we have done on find is trigger and check it trigger colliders are used as triggers so they can and will cross other colliders. All right, let's check it in the plane mode. So you see that our Characters Collider does not cross that grounds collider, but the second collider is located inside the ground collider. So yes, it does cross it. The next step is to add a tag to the ground so that we can defied it by its tag. Let's select our ground, find tag here and add tag. And now we can simply select the tag ground from the list. All right, Time to coat. I used the same script goes for me. Jump is the part of movement. First of all, let's create a variable which are going to help us with ground check. I remind you that serialize filled makes a private variable visible from the inspector. But it remains private. Okay, let's create private terrible type. Bull bull type means it can be true. All false. The name is is grounded on a It is false. Next level, use another function that unity has. It is void and just called on trigger. Enter toady. Ah, this function is cold. When the collider others enters the trigger, we have a trigger on the second collider on our character. Remember? All right, so inside this function we check if other rooms we check if other collider has a tag ground by chance and if so, is grounded true out. And we need to edit it. We need to tie other here. All right. So again we take the other collider and check if this collider is tagged a by ground and then the object is grounded and now vice versa. We add a function a private Boyd, The function on trigger exit to the again. Although here home on, I can simply copy it. Okay, Andi, this time false on trigger exit to tea is cold when the collider other has stopped touching the trigger. All right, we have our check in. Let's go ahead inside the update function. We already have our right left movement and let's add something for jump. I will use that currently briquettes because you know it's ah good. It's a good practice to always use curly brackets because it doesn't understand that we have more than one line inside it. We cannot do it if we have only one line after that. But it is a best practice. All right, so get component. You can use this symbols if you'd like to add several conditions. So in this case, it means if this and this at once first part here means if a user press the space button, the jump means space buttons off again. You can check all this, thinks inside the properties here again. Edit project saddens input. So if a user presses space button on and the variable is grounded, which we have declared is true and this second condition saves us from endless jumps, our character jumps on Lee. If he is grounded the next part adds a force where this is a direction off. Acceleration on this is that instant imp ALS. You can change the number here and change acceleration that way. Let's save it. Go back to unity on and check it. Okay? Speak space bar. He is jumping on. If I wanted Teoh, if I press, that's pays while the character is in the air. Nothing is happening because no enters jumps on the one jump from the ground. But off course. Maybe you need endless jobs. Maybe so right now I was Portman moves and jams, which is great, but he looks too boring with the algae animation and it is waiting for you in the next lessons. 15. Animation from idle to run: Let's go back to animation. First of all, I select my character and go to the animation folder, right click create and let's create an any major controller. I rename it Teoh my animation. All right, let's open it right now. We don't have any animations inside, but we have a bunch off animations inside the pack like Attack Die and so on. Animation always begins with idle animation, so let's drag and drop it to our animator on. I do the same with the Iran animation. All right, now let's go to our house Wardman and add a new component. Animator, find that controller slot and dragon dropped about controller here. All right, so our controller right now have has only one connection. And if I turn that plane mode on, we see the idol animation, but it doesn't change when the character is moving on jumping. It is still the idol animation. I know that we was playing with idle animations, so you need to return your idol animation it as it was in the pack, for example, you can import to the idol animation again from the pack diluted from here in import. But I hope you just I didn't save it, Okay, so let's go back to our animator component. We need to you connect Idol and run animation. To do that right, click on the idle animation and make transition to that run. Let's click on the arrow on the right side, off the screen. We have conditions, and we need to create one. First of all, we need to think what should happen for animation to change. In this case, speed changes off course when my character is standing still, the Idol animation should play, but when it starts hiss movement to the right or to the left side, the run animation should start here. In any major, we have parameters. Let's create one click on Plus I select float type. Rename it to speed and let's add the condition. Click Um, plus select a speed Andi if their speed is greater than 0.1 So if the condition is true than the transition happens, and of course, we need to do reverse right click on the run, make transition from run toe idol, click on the arrow, and this time speed is less then 001 I also prefer to go to settings here on and uncheck the exit time and changed the transition time 20 in both cases so that the character goes from idle to run animation very fast. All right, now let's go to the plane mode and see that nothing is happening. We have our idol animation plane again and again, and this blue line shows us that, yes, we have this kind of animation. All right, so off course nothing is happening because it shouldn't. But we can go to the animator. Let's go back to the plane mode, go back to Animator and change the speed to two. And then you see that the animation has changed. So that means that our logic works. So the anti monitor works just fine. Now we need to come back to Abbas script and do something. First of all, let's declare and you variable Stuart here, let it be private. The type is any major, and let's call it any major. All right, now, let's go inside the start function and take the animator a any major from my object. Get component animator get component is the primary way off access in other components. So when the game starts my variable animator takes the animator component. Next let's go to the update function and off course there a so many different ways to code it. I just show you the easy and obvious one. All right, so my logic here is simple. If you use her holds right or left bottoms, Idol animation should change to the run animation and vice versa. If he doesn't press the buttons, that means my character stops and Ron animation switches to idle. And here I have aged variable, which tracks such actions. All right, let's go ahead and write the first pot. If h does not equal to zero so exclamation and equal together means is not equal. So age is not equal to zero. That, in my case, means user presses bottom, which controls horizontal axis. And if it is so let's send a float value to the animator. We have called ahead spit as you remember, and I need to give it any value bigger than ah 0.1 because it is my condition, remember? Okay, so any major set float speed one. The speed is the name off our parameter here the speed and I should give it any number higher than our condition here. I decided to give it one. And if age equals 20 I send another. Well, you to my any Reacher, you major set Float speed zero. Yeah. And this is the red line here. Means we did a mistake inside the If we can't use just equals, we need to type two equals We used to equals because we want to compare not a sign and the equals Just You know, this equal sign is the assignment sign. In this case, we need to equals. All right, let's save it. Go back to my project. That's run it. Oh, right. Good idol. And then the run animation. And I want to show you what if I haven't unchecked this box here we have on Then we have this moment when our player still has the idol animation Wild. He needs the movement of the the run animation. So that's why I told you t uncheck this box so it works good. My hero walks from left, right and stays. And moreover, his animation changes just acid shoud 16. Jump Animation: All right, let's add a jump animation. I opened my any major again on If you want Teoh, move it. If you don't see some elements, you can hold ELT and then simply move it. So I take the jump animation and drugged. Drop it to the animator here. All right, let's make a transition from any state. She jump right quick my transition jump and from jump she idol. Oh, right, Let's click on this arrow and create a new parameter. Okay, so this time it is bull parameter. Let's call it grounded. Next, let's add a condition for the first transition ground it. And of course, the first value is fulls. So if not grounded, then that means that my character is jumping. So it is in the air on and the second arrow that at a new condition grounded True. All right, let's check that we don't have any exit time now. Exit time. Let's open our script. We already have. The variable is grounded. Do you remember? We have created it while code in jumping. Go back to the lesson jump if you'd like to refresh it. All right, let's go back. The update function All right. And let's do the same thing for the false balls rounded wells. So we have used set flawed there because we have upload perimeter for idle to Ron Animation . And and now we use set Bull because we have bull parameter here, remember, for amateur grounded, it is a bull. And again, the grounded. It's the name off Abba parameter. All right, let's save it and go t our game jump. Okay, let me make it bigger. No, right, Move and jump. Move and jump. Oh, that's that's pretty good jump, Joe. Hey. All right, we have finished. 17. Collectable Objects: Now, when you know how to any mate and move your character, your next question must be Hey, how to collect coins. Well, maybe I'm grown, but collecting coin's is one of the most common part of the game. And I gave you 99% that you first gave. Need someone collect in something? All right, so let's look at our coin. And I want to you make it a little bit smaller, because right now it's kind of IQ, so I use wrecked tool. All right. Good. Now one team of it right here. Okay. So let's add a collider to our Cohen. It should be Circle Collider. Where is it? Okay. Almost perfect. Okay, good. Now we need to create and you tag. Scoot tag at tag Doug coin. All right, Go back to our kind tag coin. So now our coin has a collider and is tagged as coin. Let's duplicate it. Right. Click duplicate. Right click duplicate, creating a few more coins that way. And now, as I duplicated the 1st 1 all these coins have the colliders and they are tagged as coin. All right, let's go back to our script on Go inside our function Own trigger. Where is it? Oh, yeah, on trigger entered too deep. All right, so here we have checked. If the object is tagged as ground Onda, let's make another checking. If so, we have almost the same thing here. If our trigger collider touches the collider with the tag coin, then other collider is destroyed, so it will be destroyed and disappeared from our scene. All right, that's save. Um check it. Yea, our coins disappeared. Good. 18. Counting Collectables and Displaying Score: in this lesson will add away for our player to counter collectibles he has picked up. All right, let's, um, move this coin a little bit so that he needs to jump to get it. Let's go ahead and add a text which will display how many coins a user has picked up. Two dough that go to hierarchy. Click on, create you. I text you. I means user interface. All right, so we see that we have Canada's text and events is from here. So the text is a child of can. Ever. But what is the text? You have the text. New text. We don't see it. All right, let's click on it and press F bottom. Oh, here it iss. All right, let's change the view a little bit. All right. Where is that? Was Portman. It is here. Okay. The taxes here, and that's OK. We don't need to move. It ain al asi. It will be appear. Don't worry. Let's click on the taxed and change it to, for example, count. Let's change its collar to read. And we can also change the font size, but it beat 20. All right now let's change its position on canvas to do that, find that wrecked transform. Click here, press shift, plus out and choose any position you want. Now let's go back. Now let's save it and go back. G our script. First of all, to use user interface, we need to add a new library. And I hope you remember that all libraries that we have we have appear. So let's add a new library using unity and Jeanne ducked you I Next let's declare two variables. One counts coins another is the text private and the type of send to the name is Count This variable will be counting our Coens on another variable. Let's make it private also. But you serialized filled. All right, so I would generalize. Field type is text and the name is count text pay attention that text type isse from you I library. So if you don't use this library, this type doesn't exist. Okay, Now inside the start function will start with no coins, so count is equal to zero and the text appears. Alba text has, uh, count text name dot text I use count text variable, which I have created before count. And how many coins and this number how many coins should be displayed as a string? Next? Let's collect the coins. Inside this function where we have our checking, we add up the logic four coins and for the text which displays of their number. I told you that you need to use this. Currently, brackets, if you have a more than one line here and it's even better to use them all the time. So we do it inside our If on if the tag is coin, the object should be destroyed. And all right, let's save it. All right, But before we test it, don't forget to you find our script Or is it movement? Script Onda. We have our count text here, so that's drag and drop our text right here. All right, let's test it one to pre K and that's Freddie it. But I'd like to show you one. That thing we have done in our script here we are using the same code twice. Take a look here and here, so that's not good. The better way to fix it is to create a new function and call it just twice instead or right in the same code again and again. The next thing that you can do is to take your camera on and put it on your character. So now the camera is following our character, for example. Let's make it bigger. You see the cameras following him. Good. This is that the simplest Wait to follow your character by the camera. All right. It works. Just await, Hester. 19. Export your game: all right. So using the produce lessons, you can create your own game. And right now I'm gonna show you how Teoh expert it and share with your friends or play by yourself. To do that, you need to open Unity hub and go to instance. Here we have all the platforms that we can use. Click here, add models. And right here we have a list of platforms and, um, I have already installed most of them, but you probably have some of them unchecked. So a just check the platform you need and then click undone after that into you will download and in style will the platform. And of course, this staff should be done only once on, and these platforms will be available for all your projects. Your next step is to go back to your project, go to file build settings, and right here we have all the platforms. Right now I have BC Mac and Lennox. But if you need another platform, you can simply select it and click on switch platform. After that, you can either build or build and run where build men's. That unity will create a file with your game and the building. Ron means that unity not only create a file, but we'll run it after the building is finished. And that's all. Ah, that's the way you can share your game and play it. 20. Thank you!: Thank you so much for watching this course. Now you know that making video games and unity is fun and not so difficult as it might seem . I hope this course gave you and good start in unity and you are inspired to move forward again. Thanks for supporting and good luck in your projects.