The Ultimate Guide To C# Unity 2D Programming (2024) | Michael Murr | Skillshare
Search

Playback Speed


1.0x


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

The Ultimate Guide To C# Unity 2D Programming (2024)

teacher avatar Michael Murr, Software Engineer :: 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

    • 1.

      Introduction & Course Structure

      4:17

    • 2.

      Section 1: How To Download Unity & Visual Studio

      5:28

    • 3.

      How To Use This Course

      12:12

    • 4.

      How To Work In Unity Interface

      9:23

    • 5.

      Writing Your First Code In C#

      12:17

    • 6.

      Section 2: Magic Game Cube 2D -Introduction To Version Control

      7:22

    • 7.

      Setting Up The .gitignore File

      8:53

    • 8.

      Print Using Debug.Log()

      8:02

    • 9.

      Variables 101

      9:19

    • 10.

      Responding To Player Input

      9:33

    • 11.

      Adding Rigid Bodies & Colliders

      10:25

    • 12.

      Adding Magic To Our Cube

      7:18

    • 13.

      Using If, Else If, Else Statements

      11:04

    • 14.

      Public Methods & Return Types

      15:32

    • 15.

      Prefabs And Parent Child Relationships

      13:52

    • 16.

      Section 3: Setting Up Our World - Game Design

      11:06

    • 17.

      How To Slice Up Sprites In Unity

      7:25

    • 18.

      Tile Maps In Unity

      14:29

    • 19.

      Rule Tiles 101 (2D Extras)

      13:06

    • 20.

      Adding Our First Animations

      13:56

    • 21.

      Animation Transitions

      12:28

    • 22.

      Adding 2D Collisions

      8:30

    • 23.

      Section 4: Moving Our Conqueror Horizontally

      14:45

    • 24.

      Flipping Our Players Sprite

      9:17

    • 25.

      How To Trigger Animations From Code

      7:59

    • 26.

      Adding The Ability To JUMP!

      12:25

    • 27.

      Tweaking Jumping Using IsTouchingLayers()

      10:42

    • 28.

      How To Prevent Wall Jumping

      7:39

    • 29.

      How To Add Climbing Mechanics

      16:11

    • 30.

      Tweaking Climbing Mechanics

      5:27

    • 31.

      Cinemachine Follow Camera

      12:19

    • 32.

      Cinemachine Confiner Extension

      13:12

    • 33.

      State Driven Cameras

      11:48

    • 34.

      Section 5: Adding Enemies And Bombs - Making Enemies

      23:28

    • 35.

      Player Hit

      17:23

    • 36.

      Drop The BOMB

      17:17

    • 37.

      Exploding Our Conqueror

      14:22

    • 38.

      Adding The Attack Ability (How To Use Arrays)

      20:32

    • 39.

      Killing Off Our Enemies

      13:48

    • 40.

      Section 6: Controlling Our Game - Adding Levels

      12:25

    • 41.

      Exit Door

      24:12

    • 42.

      Main Menu & Success Level

      18:49

    • 43.

      Game Session

      14:47

    • 44.

      Hearts and Diamonds Pickup

      12:09

    • 45.

      Adding Sound Effects (SFX)

      10:51

    • 46.

      Persistent Lives And Score

      14:31

    • 47.

      Bonus Section: Level Enter

      18:11

    • 48.

      Adding SFX To Everything

      29:55

    • 49.

      Adding Hearts UI

      14:46

  • --
  • 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.

4,504

Students

10

Projects

About This Class

This course is made with the latest content and newest technics used in modern Game Development

The best way to learn anything is by doing it in a really fun way and this is where this course comes from. If you want to learn how all these incredible games you see are made there is no better place to start than this course. We made sure that this course has everything you need to take you from a beginner (even with zero codding experience) and slowly take you to intermediate and finally become a professional.

I chose the main project in this course to be a 2D platformer because it not only has a vast library of game development concepts that we can implement and learn, but also because it's very simple (especially if you are a beginner) to delve in and get started on your game development journey.

Everything in this course has been meticulously crafted, review and recrafted to provide you with the best experience possible and maximize your learning as much as possible. So not only will you have a great time learning you'll also get the MOST BANG FOR YOUR BUCK by going away from this course with a lot of tools in your arsenal to continue you journey in the wild west of game development.

Section 1 - Introduction & Setup:

We'll start off by downloading all the necessary tools that we need to start our game development journey. That means the latest version of Unity and the latest version of Visual Studio. We'll also go over everything you need to make you feel right at home and how to use the course to maximize your learning potential. We'll finish off by creating our first code with a very simple game just to take the pressure off

Section 2 - Magic Game Cube: C# & Unity Basics:

This is where things get heated up. We'll start by leaning what Version Control is which is an incredibly powerful tool for game developers and used by professional programmers around the world. We'll learn the basics of C# so even if you have ZERO CODING EXPERINCE you can still understand everything and learn how to build great games and continue on with the project. We'll also get a grasp on the fundamentals of Unity Engine and how everything works in it

Section 3 - Castle Conquest: Setting Up Our World:

We begin our Main Project. We'll start off by setting up our world, and what better place than the Game Design and player experience of our game. We'll add sprite sheets slice them. You'll learn how all these maps in 2D platformers are so easily created and understand how it's not as hard as it seems. We'll add our character who's a great Conqueror wielding his trusted Hammer and you'll get your first taste of animations

Section 4 - Castle Conquest: Creating Our Conqueror:

Here is where you go deeper into making our character feel alive. We'll give him the ability to move in the levels we created and interact with various things like the walls and so on. Our Conqueror will jump, climb, run, flip and just stand there sometimes Idling. We'll also implement a modern game development technique called CINEMACHINE that makes our game really cool and professional

Section 5 - Castle Conquest: Adding Enemies & Bombs:

It's where things get a bit scary because our Conqueror is no longer safe. There are new threats inside his castle with pigs roaming and bombs ready to explode at any moment. We'll add enemies, animated them and make them hurt our Conqueror if he walks too close to them. We'll also add hazards like bombs that blow our player up if he doesn't keep a safe distance after they start burning

Section 6 - Castle Conquest: Controlling Our Game:

This is where we add lives to our player, we add more levels and add a score to get anyone playing our game a goal that they should achieve. Make everything in our world much more interesting and fun to experience. This is also where we add Sound Effects to our world and really make everything come alive

Bonus Section:

This is where we do a little bit extra. We delve deeper into the UI canvas of our game and make it much better to look at. We add all the SFX we have available, so that everything we interact with has a sound attached to it, and finally we tweak the progression of the levels by adding a couple of new animations to our player

What You Will Learn In This Course:

  1. Download and install Unity and Visual Studio

  2. Why we need Visual Studio with Unity

  3. Use Visual Studio with Unity in a simple way

  4. How to set a good Game Development environment

  5. Unity Engine are in a simple and comprehensive way

  6. The Basics of C# in the most fun ways possible by creating a game

  7. Use player input to control the behavior of our game

  8. Add different component to game objects

  9. Add gravity and other forces to game objects

  10. Make game objects interact with each other in our game

  11. Add sprite sheets and slice them up

  12. Create Tile assets

  13. How to create levels from our tile assets

  14. Become a ninja problem solver and learn how to go step by step to solve any problem in Game Development and coding

  15. Create animations

  16. Make transition between animations

  17. Add climbing mechanics

  18. Add bombs that explode and kill player

  19. Add enemies that attack you

  20. Create levels automatically with 2Dextras

  21. Learn what player experience is

  22. Add sound effects to your game

  23. Add a scoring system to our game

  24. Add lives to our player with dying conditions

Meet Your Teacher

Teacher Profile Image

Michael Murr

Software Engineer :: Game Developer

Teacher

Hi there, my name is Michael Murr. I'm a software engineer from one of the most highly esteemed universities in the Middle East and the founder of 2M Dev. 

I started coding when I was about 11 years old, when my dad taught me my first lines of HTML, and I have never looked back.

I am a software engineer with more than 10 years of experience. I am the founder of 2M GameDev, a leading game development software company in the Middle East.

Over the years, I've helped hundreds of students create real-world games, learn how to code, and set their lives up for opportunities in many fields that require a software programming skillset. And I will help you do the same.See full profile

Level: Beginner

Class Ratings

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

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 & Course Structure: My name is Michael Moore, founder of double m game dev. And my goal is to make you the best game developer in the most fun way possible. I've helped hundreds of aspiring game developers achieved their goals of creating fair game. And I want to do the same for you. What I've learned is that it can be very difficult to know where to start when it comes to game development and what steps to take to go from beginner to intermediate to professional, not only in game development, but in programming and learning how to go. And I can say with absolute confidence, this course makes it easy for any beginner with 0 coding experience to jump in and learn how to make great things. What's even more amazing is that this course is made using the latest version of Unity 20-20 was the newest possible content and techniques used and modern game development, I've held hundreds of people create real-world games, and I want you to be one of those people. So how are we going to do this, the course structure? So the first section, which we are currently on will be the production and the syrup, where I will introduce you to a unity if you're new to it, and introduce you to the Visual Studio and why will use it, will actually also create our first code and our first script, which is very exciting. The second section will be the magic Game Cube, basically will cover the C-sharp and unity basics. We'll talk about the basics of C-sharp and the tools that we'll need for our Golding later on. And the basics of unity and everything that we need to understand from collisions to rigid bodies, to physics, immunity and so on and so forth. Now the third section is where things will get very interesting. And it's our project which is Castile conquest to the, and in the section three, we're going to be setting up our world. We are going to be creating our tile sets. We are going to be creating our world, adding collisions to let world and adding our player, but not so fast cousin in section four, we are going to be adding our conqueror and we may have, we may introduce our conquer and d, Section Three Button section four. We're actually going to give him the abilities to Shawn, to run, to have different animation and so on and so forth. Now, section five is where things get a bit scary because we're adding enemies and bombs. So now our player as no longer safe, he will have to fight off enemies and he will have to avoid bumps along the way as he tries to conquer the Gaza. And in section six, we'll start controlling our games. All be adding, a score, will be adding the lives, will be adding multiple level store game and everything that goes on with it will actually also be adding a lot of sound effects and make our theme much cooler. And finally, in section seven, we'll have the bone section will be where we tweak things a bit and just for the fun of it, make our game a bit more exciting and more fun. You'll also have the chance to flex your game developer muscles, because in every video there will be a mini challenge for you to complete. And even if you can't figure out how to do it, don't worry about it. I will be there to help you up to retry and complete the challenge with everything. And our gain will be configurable. So you can tweak, play around and give the game and individual S special feel about you'll be putting your own creativity into it and really making it your own. I'm so excited to get started and hope you are too. This is the perfect time to start learning how to code, especially in times like these. So diving with me and I will help you along every step of your game development jury. And I'll see you in the next video. 2. Section 1: How To Download Unity & Visual Studio: Welcome back everyone. So in this video we are simply going to be downloaded in the unity, how installing our version of Unity and setting up everything in order to start creating games. So let's get started. First thing you need to do is you need to go and to whatever browser you're using. I'm currently using Google Chrome. It doesn't matter. Simply go ahead to Google and type in download unity hub, and you should get this search result. So simply go and click on the download unity hub. It should be the first link which would be on the Unity 3D.com website. And it will take you to this page right here, and it will ask you to download unity hub. Now, what is unity hub? Well, unity hub is a place where we can add different versions of Unity. And we can also have all of, all, all of our project represented very neatly and very carefully, which is very helpful and much better than the way we used Unity before. So simply click on Download unity hub and you should get the installation which is right here, which is unity hub setup. So double-click on that. It will start an installation. It's fairly easy. You simply click on agree and install it. And wherever destination folder that you have, I already have unity hub, so I won't bore you with the download process. It will ask you to agree to something which is fairly easy. So go ahead and install Unity hub. Oh, okay, so now that you have unity hub and stall, you should get this window right here. And first thing you'll need to do because I'm already signed in, so you need to create an account. I'm currently using my Google email, which is very helpful and much easier. And here you can see that we have all of our projects, not currently, we don't have any projects yet, but we will very soon. Here you have different tabs for learning and for the community, which you can go and check out and see what there is. But what we're going to focus on right now is going into installed. Now as you can see, I already have a version of Unity, which is 2020.1.21. So maybe you're from the future and you have a better version or a more, or a newer version. And in order to add a new version, you simply click right here on the app. So when you click on Add, it gives you different options to download unity. Now as you can see, you have recommended releases, you have official releases and you have pre release. Now, what should you choose? Well, personally me, I like to choose the official releases because they are usually the least buggy. There is the recommended release which is also not bad. And there are the pre-release press releases. And now press releases are not always bad buggy, but sometimes you may encounter not very good performances during play or during the game creation. They are not that common, but I personally prefer the official releases. So go ahead and choose one of them. Let's choose the official release of 2020.1.10. And let's click on Next. Now, this should take you to another modules to your installation window. And what we have here is a bunch of add-ons and uses for the unity. So for example, you have Android belt, which will help you build games for Android, you have line next built support and Mac and so on and so forth. You also have the documentation which I recommend you download. And you have the language back, which if you have some kind of different language, Chinese or Korean, I'm not sure what those are. You can also check one of them and download that. But most importantly is you have to check this developer tool, which is Microsoft Visual Studio Community 1019. Maybe you have a newer version. So this is absolutely a must. We will be using the Visual Studio to code all of our games. So go ahead, click on those and click on Next. And the download should start right here while you're having a box similar to this one and with a little blue bar up here waiting to finish the download. So now I'm going to introduce you to your challenge, and this is your challenge for today. So you need to download unity and Visual Studio. So first of all, go ahead and download unity hub. Then download unit is latest release. And make sure you also download Visual Studio with unity. So go ahead and do the challenge, and I'll see you in the next video. 3. How To Use This Course: Welcome back, My favorite game developers. And this video, actually, and not in this video. I've created this video in order for us to maximize the potential of learning from this course. So I want you, I want to guide you through a couple of steps that we can use in order to fully squeeze out all the learning energy from the course you're currently taking because you've already, you are already spending your time here. So why not maximize it? So the first thing that we are going to understand is how the Q&A works. So as you are watching the videos, you're looking through them, maybe something comes up that should not fully understand. So what you can do is you can go ahead and slide into the discussions right here. And you can see that you have multiple options. You can either start a conversation, ask a question, or you can simply just share a project. So in here, you can ask me any question that you want. No question is of limit. But there is a small step that you need to do before you ask me a question. And that is, go ahead and do your own research. Why do I ask you to do that? Well, because sometimes when you stumble upon a problem and you go ahead and look for a solution yourself, and then you either find it or you don't. And when you come back and ask me the question, it's much easier to understand. Why is that? Because you've already went through a couple of suggestions, maybe none of them were suitable. But as you go along finding the solution to your problem, you have gained a lot of knowledge. And when you come to me, when you ask Michael and we go through together finding of the solution, you will understand how everything clicks and later on, when you maybe come upon the same problem or maybe you see this problem for another student. You can help them out and it's much easier. And finally, whenever you do find a solution to your question at your question and add a salt prefix to it because other students might have the same problem and they will find a solution for their problem if they see the solved prefix behind it. And finally, before I leave, you just want to say one thing that there is no question of limit. There is no stupid questions, there is no dumb questions. There are only non professional game developers. Nobody was born a professional. We all have to learn through trial and error. You wouldn't believe how quote unquote, my questions were dumb. Because i, o, I'm, I wasn't born a professional in unity took me years of practice, trial and error or asking questions, Googling things. So this is a process. Don't worry, don't be afraid, don't be insecure about some of the questions that you might want to ask. Be brave enough to go look for a solution if you don't find one, not worry about, just leave a question. I always, always answer all of my students and we always delve as deep as needed in order to find a solution to any problem. And now let's talk about the Discord server. And this is where you can go deeper into the community that we've created here on WMD game dev. So you can go either to the link in the description of this video or you can visit my profile and find the link somewhere in there. And I do recommend that you join the discord. Why? Because most of the time it might take me a couple of hours in order to reply based on where are you from. So maybe our we live in different time zones. Maybe when you do ask me the question, it's midnight and you need a solution past I might be sleeping, I might be not able to get to my computer. So it's very beneficial for you to join the discord channel that we've created. And let me just show you the discord channel right here. This is the beginning of our discord channel. You can see that we have the general community. We have the C-sharp chat, we have the game design chat, we have the show off your game. We have the general game development questions. And you can see that we still don't have anything in here because it's fairly new as I'm recording this. But later on, when you go in here, you'll notice that there is a huge community of people waiting to help you and maybe people waiting to get help from you. And it's very beneficial to try to solve other people's question. You wouldn't believe how much I've learned from just helping other people. And you can see here that we have multiple courses. These are all the courses that double m gamma game dev has or I've created. And we can see also we can share memes and here we have general game discussions, AAA games, I don't know whatever you like to play. We can discuss them in here and the social channel or category, and so on and so forth. So I do recommend that you join our discord server. It's very fun. We are going to have a lot of fun there. And that's it. That's all that I wanted to say about Discord server. Next thing, let's talk about the challenge slides, and this is your challenges slide. So whenever you see the slide, you need to pause the video and do the challenge on it. It's a much better way to learn. And doing is always better than watching and my book. So whenever you see the challenge screen, know that it's a great opportunity to go out and try to tackle the task at hand. And the reason I created this challenges is for you to get as much benefit from the scores as you possibly can. I've personally tried over 10 cores where the instructor simply goes through the motions. And at the end of the course, I have created a game, was the instructor, but I haven't learned anything and I felt I would never be able to replicate any of the challenges. Give you the opportunity to try, make a mistake, and get stuck trying to solve the problem. And even if you can't figure it out, if you have no idea how to do the challenge, try even, even if you cannot complete the challenge. When I complete the challenge, after you've tried, it will be ingrained in your brain. And next time you see the problem, you'll remember the mistakes you made and how not to do them. Again, trust me, this is the best to learn and we'll keep you active as we worked through the game together. So next thing I want to talk about is the core structure. So section 1, we'll start by introducing everything and setting up. So I will, We are currently on the Section 1. We are introducing unity and Visual Studio if you have never done them before. So I'll take you through the process of downloading everything. We'll talk about how to use the scores, of course, as we are doing right now. And we are going to explain what version control is. Version control is a very powerful tool in the hands of professional game developers and any kind of programmers out there. And will also be creating our first code in Unity 3D. In section two, we are starting our first small project and it's going to be the magic cube 3D. Here is where we'll introduce the C-sharp and Unity 3D basics. We'll create a couple of game objects. We'll create shapes, will add rigid bodies. We'll talk about what rigid bodies are. We'll talk about what collisions are and what colliders on each game object does. We'll talk about the basics of C Sharp. So this, in this section, if you're already familiar how Unity3D kind of works and how C-sharp works, then you can want to the next section immediately. If you need to build a foundation in C-Sharp, and this is the best place we will talk about if conditions, we will talk about arrays, we will delve into loops. We will talk about everything that you would need in order to continue the course and move to the third section, which is the space bound rocket ship 3D. And we're actually starting to create our big project. And we're starting off by creating our rocket. So we'll build our rocket from different materials and our game, we'll start with the shapes, will add rigid body and will start moving. Our rocket, first of all, will be thrusting it and then we will work on the rotation of our rocket. We will then move on to Section 4, because of course, our rocket ship needs a space to fly, an entity needs obstacles. So we'll talk about level design. We'll start creating our first levels and we will add to them a collisions and we will start detecting which kind of obstacles are we hitting? And are they good obstacles? Or are they may be fuel. Maybe there are things that we need to land on, so we'll talk about all of that. And in the fifth section, we are starting to talk about level flow. And what do I mean by level of flow? Well, of course in level design we're not just going to have one single level, we are going to create multiple levels and we need a way to move through those levels. So this is where level flow comes in. We will add, we will use our knowledge in C-Sharp in order to integrate into our levels and start progressing through them. Then we will start our work on advanced rocket design. So now we have basic understanding of levels. We are moving through them. We have our rocket, but we need more, we need to add more flair. We need to add more power to our rocket. And this is where the advanced rocket design will come. And we will talk about particle effects. We will talk about adding more audio. We will delve deeper into rocket design and make it much more interesting. In the seventh section, we will start using advanced level design. We will talk more about how levels work. We will add moving obstacles. We will start to actually make our level breathe. We will add different kinds of seniors. We will change the lighting. And finally in the bone section, and I've not included this as a main section. That's a bonus section because we already have every core elements set up and our first seven sections. So, but the polishing part is actually adding more art into our gain. So we will, first of all be turning off our oil. So Section 6, we'll be creating a health bar for our rocket, but it's stuck on there and it's not moving in. Bonus section will be polishing that up by removing the Health Bot and only making it appear when ever we needed, then we will be creating a main menu because it's not a crucial part of our game, but it's also very fun. And we'll add, and we'll make our game look much more professional. So I just want to leave you with this message. If you put in the work into the scores and if you try your best by doing the challenges, by following very carefully the steps, you will get out of the scores much more learning. So let's not waste any more time. And let's get started. 4. How To Work In Unity Interface: Okay, so welcome back to another video. Let's see what is unity? So unity is a cross-platform game engine development developed by Unity Technologies. We'll use Unity to develop our game. So what does cross-platform means? It means that we can use it on different platforms. And it's a game engine. And what game engine is, it's a environment for us to develop games and add physics and add different things to create our game. So let's check out what Unity actually looks like and I'll explain a couple of things on it. So this is Unity. First of all, we have this toolbar right here up above everything. And this provides access to the most essential working features. On the left, we, it contains the basic tools for manipulating the scene view and the game objects within it. In the center we have the play, the pause and the stub Control button. And the buttons on the right gives you access to the Unity collaborate, unity cloud service and Unity account, and will not get much into that. On the right side of those, we have the layer visibility unit menu. And we have the editor, which provide some alternative layouts for the editor window and allows you to save your own custom layouts. So if you don't have the same layout as I do, you can simply click right here on layout and you can choose the default layout. And this is the default player that we have. It's the projects right here and inspector and everything. Next thing we'll talk about the hierarchy window right here. It's a hierarchical text representation of every game object and our scene. So each item in the scene has an entry in the hierarchy. So the two windows are inherently linked. The next hierarchy reveals the structure of how game objects attached to each other. So right here we have the sample scene. And if we click on that, we have the main camera under it. And if we add another game object, it will also show up right here. And here is the inspector, as you can see on the right. This is the window inspector and it gives, it allows you to view and edit all the properties of the currently selected game object. So don't select a game object, we don't see anything. When we click on main camera, we have these different windows right here, and the layouts and counter contents of the inspector window changed each time you select a different game objects or now we don't have a different game object. So we'll just settle for the camera. Next. Then we have is this scene view right here. And the scene view allows you to visualize and navigate and edit your seen the scene view. I can show you either a 3D perspective or a 2D perspective depending on the type of project that you are using. So in scores will be using the 2D project view, but you can also write here collect on the to the button and it will go 3D. As you can see, we have this 3D view but we won't be needing, it will simply go into the 2D mode. And finally, I want to talk about the project window right here, which displays your library and assets that are available to use in your project. So when you import assets into your project, they will appear right here. So for example, for now we don't have any assets, would only have the scenes folder. And inside the scenes folder, we have this sample folder. So this is a quick overview of unity and what all those panels and gadgets are. We will, of course, delve deeper into them as we go through the course. But now I want to talk about the, something very important and that is the Visual Studio. So what is Visual Studio? Visual Studio is a Microsoft Visual Studio. It's used well, it's developed by Microsoft and it's an IDE. And IDE is an integrated development environment. And what it does, actually, if you ask me in Visual Studio, will help us write the code used to manipulate game objects in the Unity using something called scripts. So how to use Unity with Visual Studio? So we need a way for unity and Visual Studio to communicate. But they do not simply do that. We need to add something to it called the dot cs file, and that is our scripts. And those scripts, we actually take those scripts, we attach them to game objects. And using those scripts will be able to add behavior to different kinds of game objects. And we'll see that very, very soon. So let's go into Visual Studio and see what it's all about. This is Visual Studio. And maybe the first time you open it up, you'll have different panels right here on the right, and different windows right here on the left. Feel free to close all of them. And don't worry about what happens next. Of course, you won't have this the first time you start up Visual Studio, but you'll see it soon enough. And I will just introduce you to a couple of lines of codes right here. So let's zoom in just a bit. And right here on the top you can see that we are using system collections. We are using stamp collection collections generic. And most importantly, we are using the Unity engine. What are all of those? While those are called namespaces. And basically, these are libraries that give us the opportunity to use different kinds of coat. So for example, Unity engine, which we added tried here, allows us to use fist start method and the update method and different engines to create games and make it much easier. And we simply write here using Unity engine. And it saves us a lot of gold and gives us the entire library to use. Next thing we have the public class class name. And this is the, actually the className, which should be right here. It will be the script that we've talked about and it will be attached to a game object. And it will encompass all of the code that will change the behavior of our game object and sidewall game and mono behavior is a base class and it's actually these two mean that it inherits from the mono behavior, which allows it to use different kinds of manipulations and engine and physics and so on and so forth. And next thing we have is the start and above it is something called the comments. Or whenever you write code and add these two lines right here, it will comment things out and comments actually don't get executed. And the GOP, the coat, coat, the code and they are perfectly safe. So it's start. Start is called before the first frame update. So as soon as our game starts, the start method and the scope of a method we'll start to execute. Next thing we have the update, and the update is called once per frame. So every frame that we have in our game, the update is called. So start is typically used to give the initial properties or configurations to certain objects. And the update is used for objects that maybe are moving or change every frame. So if we have a car, for example, and start, we can give it the color, the name, the speed at which it can go. An update will be moving the car, will be making the carbon jump will be making the car go faster, maybe increase its speed. So you get the basic idea of Visual Studio, and now it's time for your challenge. And your challenge is to go make aim mass. So open unity, create a project. And if you don't know how to create a project, we'll do that in the next video. And when you're finished, after you go make hay mass, go to the next video and we'll make our first coat and gets started. So I'll see you in the next video. 5. Writing Your First Code In C#: Welcome back, my fellow game developers. In this video, we are going to be creating our first code and our first game objects. So as you can see right here, we have a game object called Hello World in our heart and our hierarchy. It's present right here in our scene, although we don't see it very well. And we have the script right here attached to it. We've also created the script criteria in our project. And in console. If we click on play, we actually get a message that displays Hello Michele, which is me. But in your case it will, it's going to be displaying your name. So I'm very excited for this video because it's our first delve into Unity world. So I hope you enjoyed the video and I'll see you in just a bit. K. So first thing we're going to do is we're going to open up Unity hub. And currently you have no projects here, which will change in just the first thing we'll do is click on new right here. And we'll need to choose a template for our game. So we'll be creating a 2D game, not a 3d. And these are different options also for different project types. Next thing we'll need to add a project name. Feel free to name it. What ever you want will be calling it for now the Hello World project. And make sure that you choose a location for your Unity projects. So we'll click on this one and let's go back and save it inside of the Unity projects. So select the folder and now we have a location for our game. You need to do. All you need to do right now is click on concrete. So click on Create and Unity will start to create your project. And I will not bore you with the waiting here. I'll use the magic of editing and we'll simply jump into the project. So see you in a bit. Welcome back. So I hope your project also finished setting up. So this is our scene. If you don't have this kind of seen, as I've told you, you can always go to layout and choose the default layout. And we'll have the same layout, both of us. So before we start, let's first of all at something called the Console. And as you can see, even before we start anything, we have this console window right here. And what this does is it shows us the messages. And we're going to use this console window to see the things that will print from our code. And if you don't have it, you can simply go up here and window, click on it. And just above here, you can see on the general will have the console, so click on it, a window should appear and you can dock it wherever you want. I'm going to dock it right here next to projects. In other thing I want to talk about is in the, wherever you saved your project, I've saved it in D, Unity projects and HelloWorld. So as you can see, we have different folders right here. We have the assets. Hold our scenes and everything that we create and projects. You can see the assets and project assets right here. We also have the library which automatically created every time we enter a project, we have logs, we have packages, we have project settings, all although all of those are details that will not get into too much. And the temporary folder, which we'll discuss later on in the magic cube to the game. So let's go back into Unity. And in here we are going to be creating our skirt. So let's right-click in here. And let's go into create and create. We can actually create multiple things, as you can see, we'll do a couple of them in our project, but for now let's simply create a C-sharp script. So click on that. And before you do anything, so now don't do anything, leave everything. You'll need to make sure that whenever you name a script that you do it with precision because it will cause error later on if you want to try to rename your script. So make sure you name it correctly from the get-go. So we'll name this hello world without any spaces and click on Enter when you're sure that you have decided on the name of the script. So click on Enter and I'll tell you why in just a bit. So as you can see, we have something right here in the inspector. And that took a bit of time and it's because Unity needs to compile the code right here. And you can actually see the code in the inspector. And why I told you it's so crucial to make sure that the name of the script right here is defined before we click on enter as because it is going to be the name of our class. So if you change the name of our script right here, tick last name won't change. And there will be an error where unit or the Visual Studio will not be able to find the correct script in the project and this will cause errors. So to avoid that, simply makes sure that you name your script correctly and precisely from the get-go. Now, what should we do next? It's very simple. You simply double-click on Hello World and the Visual Studio should open up. And as you can see right here, this is what we've described a couple of maybe in the previous video. So what are we going to do in here? We are simply going to print something to our console and we'll do that inside of stock. So let's go ahead and print. So as you can see immediately, Visual Studio, our great friend starts to help us and it gives a suggestion for what we want to use, or we write the print and it gives us the suggestion. And now you can simply click on Tab and it will finish it for you. And now we open up our brackets and we can see that Visual Studio again helps us. And it tells us that we need to add a object message inside of here. And that object message is going to be a string. We'll talk about strings later. But for now, string is a string of characters that we put inside of these two quotes right here. So let's go ahead and add these two quotes a again. And now we write inside of these two quotes, hello world. So is that enough? Well actually, no, because if you see right here, we have the squiggly red line. And if we hover over it, it tells us that it expects a symbol, which is this one. And every line of code in C sharp, you have to add this semicolon right here. So save that. And now, because we've put it inside of start, as soon as we start our game, this message should be printed on the console. So let's try that. We go back into Unity and we go into console. But if we click on play, as you can see, nothing is being displayed on our screen. Why is that? Because it's not enough just to create a script, you actually need to attach it to an object. So let's create an object. And the way we do that, we simply go into our hierarchy. We right-click on here. We can create a empty game object. Click on that. And now we have a game object that go ahead, we can change the name of that game object. We'll call it. Let's call it Hello World object. Click on Enter, and below it you can see that we have the transform. And this transform tells us the position of our game object in the world. And up here we have the tools to manipulate. So if you click on the stool, we can actually put the object up or drag the object down, take it to the left or to the right and put it anywhere we want. And currently we cannot see we don't have anything to represent or game object. We simply have its ordinates and it's transformed. So let's attach the script of this game object. To do that, you simply click on the script and drag it into the hierarchy and to the Hello world object. So if you click on Hello work object right here, you can see that it has a script just below the transform attached to it. And now if we click on play in the console, we can see that we have hello world. Congratulations, you've just written your first code and you've just used your first game object to display something to the console. Go rake. And now it's time for your challenge. And your challenge is going to print your own. Thank. So instead of hello world, you'll need to print your own name. So change helloworld to hello. And instead of those three dots, of course it's going to be your own name. I'll give you a couple of hints. So add your name and size of the dots. Save Visual Studio. Always remember to save Visual Studio we using control as go to unity and click on play and check your console. So make sure it works. Pause the video right now and go do the challenge. Ow, kay, welcome back. How did you get wrong with that? I hope you tried your best and that challenge. Let's go into Visual Studio. And instead of world, I'm going to delete that and I'll put my own name, which is Michel. So hello Michelle. And we'll just add an exclamation or three exclamation points for the dramatic effect. And to make sure that you've saved your project, I'm endure a script. When you look up right here, you can see that it has a small asterix, as strict as strings attached to it. And to save that you click on, and that means it hasn't been saved. So a few hold Control, S, click on control. As you can see that the asterisked as Trixie disappears, and that means that script has been saved, GO back into Unity. And you can see that there is an asterisk right here, also next to the sample scene. So save that. And now if we go to console, you can see right here that we have this button clear. Or do you click down? You can see that we can click on Play. You can remove that. Feel free. It doesn't matter. We'll just remove it to see the changes that happened at now if we click on play, we will have hello Michelle, or hello, whatever your name as my fellow students. And that is all so clear that, that strive again, click on play. And Hello Michele. Hello, my favorite game developers. I hope you enjoyed the video and I'll see you in the next one. 6. Section 2: Magic Game Cube 2D -Introduction To Version Control: Hello everyone. In this video we're going to talk about version control. So what it is, how it works and why we need it, will also download source tree, which is this, a graphical user interface that will help us and make life much easier? Our goal is to reach a point where we have everything set up and ready to go. So let's not waste any more time and let's jump in. Version control. It's hard to learn, it's even harder to teach. But I cannot tell you how important is that you learn the skill. And especially if you are looking to become a professional game developer. So what is it? What is version control? Well, basically it's a system that is responsible for managing changes to your computer programs. So anyway, version control is a way for us to record the history of our project. We needed to control the version of our project and have a backup to every single one. Which means it helps us to take risky steps in our project and avoid breaking the entire project. Why use it? Well, we'll use it to remember previous versions of our game and have more flexibility to experiment. It's especially helpful when it comes to creating games, because game development requires a lot of experimentation. What we will be using is a version control system called Get. There are other ways, but this one will work perfectly for us. And finally, we'll be using a graphical interface that makes our life way easier, which is called source tree. We can also have an online horse, but we won't be hosting just for now. Now, first thing you need to do, you need to go ahead and download source tree. Simply write source three or go to source three, ABC.com, or write source tree download on Google. And you should come up to this page right here. You can either download for Windows and it's also available for your Mac OS. When you finish downloading, you, you should have this installation file right here. Simply double-click on it and start the installation. And when you arrive, you should arrive at this point right here, where you have source three installed. So simply click on Agree right here. And then it should take you to the next slide or window, which is either to create an account. So you either use an existing account or you can go to my adolescent and create an account. Now if you already have a Google account, you want to connect to it. Simply click on Use Existing can count and created using Google, or you can go and create a new my adolescent account personally, I've made one using Google Gmail. It's way easier and they don't spam you with emails. Next thing you need to. Go into connect to an account which as we've said, we're going to skip for now. And finally, when installing, it may come up to this question right here where it cannot find or locate the get. So if you don't have the get already installed, simply click on download an embedded version of Git and it would download it for you. And finally, as a final step, it may ask you for for Mercurial, which we won't be using. There is no harm in downloading. It, will just not be using it in this course. So simply click, I don't want any Mercurial. Oh, okay, so when you finish installation, a window like this should appear to you the most. If you don't have this window, you should click on Create right here, and this window will pop up for you. So here is where we create our repository, which is the most important part of the whole version control systems repository is the backup of our project. So if you click here on browse, you can actually find the destination path. So if we go into browse, click on D, and look into our Unity projects, you can see that we have only one project right here, which is hello world that we've done in the previous section. So what we're going to do now is we'll need to go into Unity hub and will need to create a new project. And this new project, you are simply click here on new choose 2-D. And this will be the project of our current section, which is magic q, k, or magic Game Cube. Okay, you can name it whatever you want. But the most important thing is that you remember the location. So make sure you remember the location of your project to access it through the source tree. Go ahead and click on Create. And now we shall wait for the Unity project. Gaye, welcome back of just skip the entire installation process using the magic of editing. And now we're back into Unity and we have our project setup, which is magic Game Cube. And now what we need to do is we need to create a repository for it. So go back into source tree, click on browse, and look for the project. You should remember when, where you've put it and if you go into your Unity projects or wherever you saved it, you should have. Now, magic Game Cube, simply click on it and click on select folder. Now as you see the repository name as the Magic game cube. And you have the option here to either choose Git or Mercurial. We are going to choose get. And here is where you can create a repository on account. As we've said, we will not be hosting anything. So simply uncheck it, get and click on Create. Okay, it will ask you problem with destination directory. Don't worry about it. Simply click on Yes. We wish to continue. Excellent. So now as you can see, we have this weird things around here and we're not sure what's happening. We have these assets, these libraries and so on, and a long list of things that are called onstage files. You don't need to worry about this right now. Simply go ahead download source three and install it. And this is actually your challenge, which is download and setups or S3. So go ahead and download source tree. Go ahead and install and set up everything. And I will see you in the next video. 7. Setting Up The .gitignore File: Welcome back everyone. In this video we are going to be ignoring some files. And we'll learn how to get all the files that we need to ignore it and put it in a folder that's called Git ignore. We'll also add a cube. Yes, No, actually it's a magic square, but we'll call this magic cube, will add it to our scene, and we will be creating our first commit. So let's get started. Now, if we click on our project, it opens up pretty fast, relatively fast. And while we, okay, so now it's open. And if we go to our source file, we can see that we have this temporary file right here and we have this library file right here. So let's go ahead and close out project. For closer, we can see that the temporary folder disappears. And if you delete the library folder, you can still open the project and unity actually rebuilds the library. You can try this at home. Don't worry, it's completely safe. Library contains cached information that helps Unity open up project faster. But the problem is we do not need to save this library in our repository. As you can see here, we have a lot of staged files are arming on-state files that are currently flow from library and they are useless. So what we want to do is we want to ignore them whenever we stage our files. So to do that, we simply right-click on any one of them. And you can see we have this ignore option right here. If you click on it, we have to ignore exact filename. Ignore all files with this extension. Or we can ignore everything beneath a library, and this is what we need. So simply click on this button and click on OK. And now all of our library, everything under Library is ignored. And if you scroll to the top, you can see that we have a folder here, a new folder that this dot git ignore what's called gitignore. And you can actually double-click on that and it will open in a notepad, you can actually access the information. And here you can see that we have library. And this gitignore file contains everything that will be ignored whenever we create our repository. Now another thing that we need to take into account is that we will be ignoring a lot of other files which are useless and will only take up more space and our repository. And how did we find all of these files? Well, thankfully, we have something that is called a dot git ignore file that somebody has created already knows what we should be ignoring. And you can find that. If you simply go into Google and right here, 5p and Git ignore unity and this search results should come up. Simply click on the one which is on GitHub and it should be the most recent one. It should take you to a window that is just like this. So scroll down and here you can see everything that we need in order to ignore and added to our dot ignore file. So simply highlight everything in this. Select All of it, click on Copy or simply Control-C. Go back to our taught ignore notepad, select everything and paste. And now we have r dot ignore file set up. Simply save that, were using control S. And now everything in the dot ignore file has been saved. Let's exit that. And now if we click on Git ignore, we can see that all of our files have been saved. Let's quickly go over the steps again. So first thing you need to do is to find a file here under Library and right-click on it, go to ignore, and click on, Ignore everything beneath. But here it should be Library. When you're done with that, go into Google, search for Git, ignore unity. Click on the first search result which is from GitHub. Way better. Go into GitHub and you should find this file. Simply copy all of that. Go back into source tree, select the gitignore file up here and paste everything inside of it and you should be done. Next thing we're going to do is we're going to create our first complet. So how do we do that? Go into our onstage files, which should be right here, and click on stage. All it will wait just a bit. And now all of our files us out are staged. To continue, we need to name this commit. And as a courtesy to our project, we always start with our initial commit by naming it. Initial comment a bit anticlimactic. But whenever you want to name a commit, it should reflect what you should reflect the changes that you've done to your project. So click on Commit. And now we have this branches right here, and we have the master branch, and this is our initial commit. Excellent. Now we have a backup to our project. So whatever changes we make to our project, we can always go back to our initial commit. And if we broken the project, we can simply fix it with the click of a mouse button. So next thing is your challenge. Your challenge is to setup the dot git ignore file. So you need to create your first 2D project in Unity hub. You need to create a repository and source tree for the project. You need to ignore all library folders and to create your first comment. So go ahead and do that. And I'll see you in just a bit. Okay, so welcome back. Here we will enter our magic cube, a project. Let's go ahead and go into that. Wait for it to open. It should open pretty fast. Okay, so Let's go ahead and do something right here, will simply go into our assets up here and we'll maybe create something. Let's see what we should create CO2 sprites. And let's simply create a square. We'll call this square of magic cue. And Now we'll simply drag it into our scene. And now we have a magic cube in the middle of our scene. If we click on w, which change, changes the one of the keys right here, we can simply lift that up and settled in the 0 position or go ahead and reset the transform and set it right here. Control S to save everything. And now if you go back and source tree, you can see that we have uncommitted changes. So click on uncommitted changes. You can see an on-stage files that we have something we've added an asset manager cube PNG here.me is something that unit uses and it was added and we've done some changes to the asset scene, sample scene. So stage all. And now we can click here on commit on the top left corner. We'll call this added the magic cue. Click on Commit. And now everything saved GO back into master. And you can see that we have an initial commit and we've added the magic cube. Excellent job. I know this may not be very cool, but trust me, this is a fundamental skill for when you become a professional game developer. And I'll be seeing you in the next video. 8. Print Using Debug.Log(): Welcome back everyone to another amazing video. In this video we are going to be printing things to our console, but not using print, but using debug dot clock, which will enable us to add warnings and errors. And we'll do that using a script that we've created in our project. We'll be adding it to our magic cubed. So as you can see an inspector, we have this script attached to it right now and will be creating some code who very scary, but not too much. And finally will be committing our project. So let's get started. Okay, so first thing you need is this console window. If you don't see it just yet, you can simply go into window and go into our whereas it, so it's in general, console. Simply click on it and you should get this console window. It will be up here somewhere. You can simply docket next to our project. Okay, great. If you look closely, you can see that we have clear, clear collapse. So clear what it does is it clears all of our console. I've checked it on clear upon play. We have colored, which means that when we have suffered all messages that are the same, it's simply collect, collapses them into a single message. And here on the right, we can see that we have three buttons that we can check and uncheck. One of them is messages, the middle one is the warnings. And on the right we have the errors. That's the scariest messages we can get. Okay, great. So next we're going to create our C-sharp script. You are already familiar with it. So go to our project, right-click. Go to Create and click on C sharp script. Whenever you want to name something like this, make sure that you name it correctly the first time we've talked about this. So what are we going to name it? Let's simply name this Q. Click on enter. Now we have our cube script. Excellent. So we can open the sub by double-clicking on it. And Visual Studio will compile, waiting for it. Anytime now, loading solutions. And we should have everything in. Oh, okay, great. So as you can see, we already have some code and here we don't want to be worrying about that. What we will be doing is we'll go into our start method. And inside we're going to be printing to our console. Now, if you went through the first section, you may realize that we used print, but now we're going to use debug. And as always, Visual Studio is extremely helpful. So DBA Debug, click on Tab, it will finish it for you. Dot log and open up the brackets. And as, as I've said. Previously we've used print, but now we're using t Bach. Why is that? Well, debug gives us more flexibility and control. And it's technically butter, and it gives us better habits for future coding. So what is the message we're going to write in here? The message will be hello, everyone. Every one. I'm printing from Debug. Ok. Put this semicolon there, and now we save it, puts a Control-S, go back into unity. But now if we click on play, we should not see anything. And why is that? We only see r square and the scene, but nothing is printing to the console. That's because we haven't attached our script to anything. So let's go ahead and attach it to our magic cube. Save that. And now when we click on play and go into console, we should have Hello everyone. I'm printing to debug. Excellent. Okay. Now it's time for your challenge. And you will need to add a couple of lines. So first thing, you need to add two messages that display on the console battling too, the player to press a certain arrow key. Next, you'll need to add one warning message. And finally, you will need to add one error log message. And hour. I'm going to be a bit helpful with you here. If we go into Visual Studio, I will give you a hand. So if we click on debug dot log, we can see that we have log error and log warning. So go ahead and ground that challenge. Welcome back. How did you do that? It's not a very hard challenge, but it might be tricky if you're just starting off. So let's create our debug dot log. And we'll change this here, will tell the player. If you press the up arrow, you'll jump. And below we're right. If you press the right arrow, you'll move O, k. And now we'll need to create a warning. So let's go ahead and do that talk clock warning. And simply when you open the brackets, you can click anything. If you press the space, nothing happens. And finally, our error, which will be debug dot log error. And inside of it, what should we write? If you smash the keyboard, nothing happens. You just cry. Case. Save that key, keyboard, keyboard, okay, nothing happens. You just cry, save that, go back into Unity. Everything should be compiled and if we click on play, hello, okay, great. So if you press the up arrow, you'll jump. If you press the right arrow you are move. And we have a warning that if you press the space, nothing will happen and an error. If you smash the keyboard, nothing happens. You just cry. Great, I hope you enjoyed this. Oh, and one last step. Click on play, save everything, go into source three because we have uncommitted changes. I don't think I'll be doing this every single video, but you should know that whenever we make changes to our game, we should always commit DM stage all. Click on Commit here on the far left corner. And what should we call this? We'll call this adding a script with the bulk, the bulk dot Log Insight. Okay, great. Commit that. And we have it in our master branch. And I'll see you in the next video. 9. Variables 101 : Welcome back everyone to another video. Today we are going to learn about variables. So we'll learn what variables are. We'll learn how we declare those variables. And we are going to learn how these variables make our code more flexible. So as you can see here, we have some different kinds of messages because we've integrated those variables into all the backlog. And here in our code we see that we have three new variables. One is integer and the second one is a string. And we have also a lope. And we've added those variables into our debug dot log. So let's not waste any time and let's get started. So variables, what are variables? Well, we can think of variables like boxes. You have a box that we call lives, and we want to put some information or something inside that box to hold it. So we put a three inside of it. And what is that three while it's an integer number. How do we write that in code? Well, we have this way of writing it. It's an N2, which means an integer lives equals three. But what do these even mean? Well, first of all, we have the type of the variable. We have the type here is integer. We have the name of our variable, which is Lives. And by, while it's a common tradition encoding, if you like, of naming the variable where the first letter will never be b capital, and all other words inside of the variable name will be capitalised. And finally, we have the data and the data should reflect the type that we give it. So what other types do we have? We have float variables, for example, if we want to talk about velocity and velocity has can be 4.8. And the way we write it as we write float velocity and 4.8 F, whenever we want to make a float variable, we add to the end of it. And then we have Boolean. And as you can see here, we've named it is that we're the first word of is not capitalized, while the second one is capitalized. And the bool or a Boolean can be either true or it can be false. And we also have a String variable. And string valuable means that it has, it's a string of characters. Or for example, here we have the box called my name, as you can see also, the second word is capitalized. We write string name equals Michelle, which is me. And we put it inside of a box, and now we have a variable of strewing. Okay, great. So how are we going to translate that into our personal code? We're gonna make this, well, what actually happens is valuables make our code more flexible. They help us. Manipulate the code in a better way. Let's demonstrate that. Let's go back. Let's go back and to our Visual Studio, and let's go ahead and create a valuable. So first thing first, if we create a variable inside of start right here, we can only use it inside of start, but if we write it outside of our start method, we can use it anywhere we wish in our code. So let's do that first. So what variable should we use? Well, let's create an integer variable. So let's say that we have an integer, will name this integer number of times, and we'll assign it a value of, let's say five. Okay, save that. And as you can see, it's black and white or it's a bit transparent. That means that we still haven't used and now let's use it. So if we go ahead and debug dot log, it says if you press the right arrow, you will move. So let's go ahead and add something to it. To add a variable, we simply do the following. Click on space, close the bracket or the little column in here. And then we write plus, we write number and Visual Studio. As always, this is our best and helps us simply click on tab at finishes, and we save that. And now we have a variable inside of our debug. Let's see what happens and visuals. I mean, in Unity. Let's go ahead and clear all of this and click on play. And as you can see here in our message, if you press the right arrow five, you'll move. We should have added five times, but you get the picture. So now let's add a string variable. So let's go ahead and click right here. String will name this name of the KI. And our string will be, let's say space, space, space. And now we want to add it to the warning for example. So instead of writing space here, will simply open this and close it on the other side, right? Plus and name of the key. And then another plus. And now we have a string variable inside of our log warning. We save that, go back into Unity. And when we click on play, we should see here that it's space. Well, that wasn't very helpful because we don't know if it works. So let's change this from space two. And let's make this also or capitalised, save that, go back into Unity. Click on play and this should change to enter. And it did. So you can begin to see how flexible using variable makes our code. So instead of going and looking for every single name, we can simply add a variable and change it from the top and all subsequent uses of it and our code will change. So what now? Well, I think you know, because it's time for your challenge and your challenge is to create your own variable. So you need to create a variable of type string and use it inside the, inside of the debug.org, which we already did. So go ahead and make your own variable. We are going to create a variable of type integer and use it in one of the warnings. And finally, we're going to create a float and use it inside of the error logs. So pause the video right now and go, try and do your best. Don't worry about messing things up. That's why we have version control. I'll see you in a second. Ow, kay, welcome back. So how did you can on was that shouldn't be too hard. So let us go ahead. We've created our string, we've created our integer. Now it's time for our float variables. So let's go ahead and create a float. What should we call this? We'll call this at a speed, will simply call this speed. Speed of breaking. And we'll make this value 4 or weight will make this 6.94. Oh, okay, great. And I've made a mistake here. It should be 6.94. Okay, so let's go ahead and add it here and our debug dot log error. So if you smash the keyboard, that's gonna look here at a speed of, let's simply add this. And what should we write here? Speed of breaking. Click on another plus. And now if we go back into Unity, collect on Play, it should tell us that if you smash the keyboard at a speed of 6.94, nothing happens. You just cry. Okay, I hope you enjoyed the video. I know that the variables and the messages in the debug log don't make a lot of sense right now, but you will see that later on. It will be very important. So I'll see you in the next video. 10. Responding To Player Input : Welcome back, my fellow game developers. In this video, we are going to be responding to our player's input. And that will happen. How well click on play right now we don't see enemies messages until we press the up arrow. It give, it gives us a message that tells us up arrow key was pressed. And if we press the left arrow tells us laughter, okay, got pressed, right arrow and the down arrow, and we did that using, using some magic code rule. Very scary, but don't worry about it. I will take you step-by-step. And in fact, in this video, you are going to do that, not me. So let's get started. Oh, okay, so as the title of this video suggests, we are going to be getting our player's input. And for that we'll use, for example, the up arrow, right arrow or the left arrow. And based on that, we are going to print something on our console. But in this video, we'll be doing something different. Because my goal in this course is not to just show you how to create a game. I want you to be come an expert problem solver. So in this video, I'm going to tell you the problem that we have. And I will take, take you step-by-step on how I usually solve my problems. So first thing we're going to do is we're going to think about problem. So the main problem is we need to get our player's input from a certain key that he pressed. He or she of course presses. So the keywords to look for our input and key. And whenever we face something that we don't know, unity has a great documentation site. So we can actually Googled. So we go in to Google and we simply write input. Unity will get all these search results. But what we are looking for is the documentation which is scripting API input unity. Click on that. It takes us to this documentation. So we see that we have input, we have the scription. You can always read all the documentation, but of course lead it, read it later. You don't have to get specific in every detail, just a glance over to see what it has. So as we scroll down and we know that we need a key that will tell us what key the player pressed. We can see that we have multiple static methods in here. And one of them is called get C0, which returns a true while the user holds down the key identified. Now, as we said, our problem is, doesn't consist of a player holding down achy. We only want to return something or get a response from the play, from us, from the game. Whenever a player clicks or presses a button doesn't hold down. So if we read below it, we can see that. Return true during the frame for user starts pressing down the key identified by name. This looks like something we could use. So we click on get keydown and it takes us yet to i another Unity documentation. And here is where we begin to read our description, which says that it returns a true during the frame, the user starts pressing the down identified by name, caret. This is what you need. And even if you're if you don't know how to actually code it, if you scroll down just a little bit, you can see that we have multiple examples of this. And here we have this amazing example which tells us that they are actually putting this get Qi Dao inside of Update and using something weird, which is an if with some parentheses and I don't know what that is. It's so weird, it's so difficult. Let's not trouble our heads with, let's simply copy this. So we'll copy this. And of course we'll be explaining if conditions later. And we go back into our Visual Studio. And as they told us in the example, we will paste it inside of update. Oh, okay, great. So a small x, I do a small explanation of what we're actually doing here. So if condition works, as it says, if anything inside of this place here, inside of these two brackets is true, we will execute any code inside of these two curly brackets. Don't worry about if conditions, if you're new to them, will be explaining them in more in-depth in later videos. But for now, paste this inside of update, save it, and let's go back into Unity. Click on play. Now we press the space bar. Space key was pressed, pressed, pressed and pressed. Oh, okay, girl rate. But as we've said, we are not looking for the space. We are actually looking for the key arrow. So how are we going to do that? Well, we hope that our good friend Visual Studio will help and it will. So if we double-click here on space and delete it, and delete the little point. And if we click it again, as we see, it gives us a lot, a lot of options. So what are we looking for? We're looking for the up arrow. So let's write Arrow. And voila. It gives us all the options that we can use. And one of them is the up arrow. So simply click on tab and now it should work when we press the up arrow. So let's remove this and actually instead of space, we write up arrow. Oh, nope, not. Excuse me. So save that. Let's go back into Unity. Oh, go back into Unity, clear all of that and click on play. Wait for it to compile. And now if we press the up arrow, we should get up. Arrow key was pressed. Oh, okay, great. One more thing I want to do. Let's comment all of these out. And the way we do that is with two backslashes just as we have comments in here. Just so they don't get in the way. And now it's time for your challenge. And your challenge is to finish the rest. What do I mean by finished the rest? Well now you have to finish. If the player pushes the down arrow. If the player pushes the left arrow. And a small extra challenge for those of you out there that are very motivated if the player pushes the spacebar, even though we've already done it, I want to see how you do it. So pause the video right now and get on with the challenge of gaye. Welcome back. How did you get on with that? So let's simply go ahead and copy this. There is no shame in copy-pasting code, even though it's better to find a better way to do that. So what will we be using? And here we'll be using the head down arrow. And we'll copy this also and save ourselves as much time as possible up, down arrow. And in here we're going to use the left arrow. Also copy that. And just for the sake of being even extra, nerdy will make one for the right arrow. Right arrow. Copy that. And here we are simply right arrow. Let's make this capital letter save that. And now if we go back to Unity and click on play, all of this should clear. And now if we press the up arrow, we get up arrow key was pressed. Left arrow, left arrow key was pressed right and down. Everything is working fine. And before we go, don't forget to commit our changes. Don't worry about if I have some extra changes here. These are just experiments. So stage all. Click on Commit and we'll write here, added a couple of layer inputs. Okay, so comment that everything is working fine. It's an hour masters, and I'll see you in the next video. 11. Adding Rigid Bodies & Colliders : Welcome back my friends to a another video. And this one will be using rigid bodies and we'll be using box colliders. What, how are we going to use them? We'll use them adding components. And why are we going to use them? Well, because now our cubes are not just images, they actually fall. And not only do they fall, but they get caught using platforms that we've created. So Let's not waste any more time, and let's get started. So now, if we click on play, our Cube doesn't do anything interesting. And what we wanted is we want to at least make it for. So how do we make this cube fall? And hence, how do we add gravity to it and make it a physical real object? We do that using a rigid body. And what is a rigid body? Well, rigid body control allows us to control an object's position through physics simulation. No, it's a handful. It's big words. But if you go to a unit is documentations which I've left you and the resources you can actually read all about rigid bodies. And rigid body object will be pulled downwards by gravity without adding any code, which is amazing and exactly what we need. So, so if we go back into Unity, we can actually go into our magic cube. And if we look here on the right to our inspector, we can see that we have a transform, we have a sprite renderer, and we have the cube. So transform tells us the position that r cube is at. The sprite renderer actually renders our cube. So if we turn it off, put, it goes away, turn it back on, it turns back, and the cube is our script. So let's make all of these smaller. And we have here this button which allows us to add components. So if you click on add components, we can actually search for rigid body. And we have two rigid bodies. One is rigid body, which is used for the 3D world. And the rigid body that we will need, which is Rigid Body 2D. Click on rigid body to d. And now we can see that we have a lot of options and information and constraints and body type and Mass. Don't worry about all of these. We won't be using all of them. But if you are interested and you want to go deep into the rigid bodies object, you can read all about them in the Unity documentation. One thing I will be glancing over is the dying body type, which we have dynamic, kinematic, and static. Now, later on we will delve even deeper into these three. But for now what you need to understand is that dynamic is when our body is subjected entirely to the physics world around him. Kinematic as when our body is not affected by gravity, but could be affected by other forces and static as an object that does not move at all, whatever happens to him. So we need r cube to be four now, dynamic. So we've added a ridged body. Let's save that. And let's click on play and see what happens. If we click on play, what are her belt D or our magic cube goes down and leaves are seen and we have no idea where it went. It goes away into Arno, what's called down there, maybe help or anything. But it disappears. So how are we going to hold it? Because for now it's not that magic. We'll do that using colliders. And what our colliders, What is a collider? A collider makes it possible for objects to interact and hence collide with each other. So whenever our Collider or, or whenever our body has a collide and it touches a another body that has a collider. They will collide and stop each other. We'll use it to catch objects that are falling, are falling because of gravity. So we're going to use this collider in order to catch the object that we have. So let's go back into Unity and close down this rigid body and adding another component. And we can actually search for collider. And as you can see, we immediately have tons of options. We have box colliders, we have box colliders to the capsule, capsule to the circum, circle to the So, because we're using R cube or square, will be using a Box Collider 2D, which is ultra simple. And as you can see, we also have tons and tons of options. You can read all about them. I of course, lifted and the resources. But one thing we need to focus on is this is trigger, and this will be useful later on in the course. But for now, let's just zoom in and see what we have. We can actually see our box collider. It's green. It's a green line all around our box, but we cannot see it right now. The way to see it is if we click here on the edit collider. And we can actually make this collider bigger, make it this way, and this way, and actually make it outside. So this is the collider is, this is actually where our object will be colliding with objects. So let's reset all of that. And let's see what happens if we click on play. So exciting. And then o, nothing happens. Why is that? It's because you have a challenge and your challenge is to catch the falling a cube. Don't worry, I won't leave you alone. Because first of all, you need to create another cube and size it to platform size. What do I mean by that? Well, you need to make our platform from this end right here all the way to the other end in order to catch our queue. So that's continuous with the, Hence create a another cube and make it a platform and a rigid body. And don't forget to change the rigid body type two, static. And finally add a collider to our platform and catch our cube. So pause the video right now, give it your full attention, give it your full concentration. And don't worry about making mistakes, because mistakes are the best part of learning. You. Either you do something well. Or you do it wrong and learn from it. So take your time and do the challenge. Okay, welcome back. How did you get on with that? I hope you didn't just stare at the screen for like five seconds until the video continued. Okay, so now we take our magic cube and what we'll do is we'll duplicate it. And we can duplicate it in two ways. We can either right-click on here and do CO2 duplicate, which will create a another game cube. Or we can simply click on Control D. And now we have another cube. If we take it here below, Let's make this cube a little bit bigger. And the way we're going to do that is by scaling it. So here we have the scale in the x direction and we have scaling in the y direction and in the zed. But because it's Tuesday at one scale anyways. So let's bring back Y 21. And let's increase the x scale until it fits between the two sides of our game. Now we have a platform, and let's differentiate a bit between them. So let's make this platform a bit darker. We can change the color in our sprite renderer. Here we have the color. And if we click on it, we can make it a bit grey or black ish. So let's make it black and will make the square here. Let's make it the, keep it white or make it a bit grey. Let's see, maybe let's just keep it white and let's change the background. Ooh, very fun. So we can go into camera and actually change the background color, which will make Gray o case seems great enough. And let's lower this magic cube actually, let's change its name to the platform. Oops, right? Platform. And now we have our platform that's lower this down. And these are the edges of our camera. So now if we save that and oh, I forgot something and good thing I remembered. We click on platform and don't forget to make this static or else it will just fall away, fall down into whatever down is. Click on play. And hopefully, yes, it holds. Amazing. I hoped you liked the video. I hope you did everything and commit everything we've done. So committed. Add it. Well, actually made my magic cube fall and held it with a platform using rigid body and colliders. That girl rate. So stage all comment, and I'll see you in the next video. 12. Adding Magic To Our Cube: Welcome back guys to a brand new video. And as advertised in this video, when we click play, our q becomes magic. How's that? Well, if we press up, he jumps. If we press left, he goes left. If we press righty goes right. And if we go up, up, up, up, we can actually press down, down, down, down, down, and make him come back faster to Earth. So let's get started. Okay, so first thing we'll do is we need a reference to our rigid body. What do I mean by a reference to our rigid body and why do we need it? So reference to a rigid body means that we'll write up here public and don't worry about public will explain that later. But for now, public means anybody can use it. So public, rigid body, it's a variable of type, rigid body. And we'll call this my Rigid Body 2D. Okay, save that. Now, how are we going to tell us that it is the rigid body on current object? Well, if we go back into Unity, clear those messages, pesky warnings. And if we click on q right here in the inspector, we can see that now we have an empty slot for a rigid body. So if we click on the little circle to the right, we can see that we have the magic cue or the rigid body of the platform. So let's go ahead and click on the rigid body on our queue. Double-click on that and say that. One thing I noticed is that if we click on our platform, oh, it's actually, we made them steak. We shouldn't add the rigid body. In fact, we should remove the cube. So let's remove the cube component from the platform because we don't need to move that. Something we should have done in the previous video. But that's no problem. Go back to cube and now we add a rigid body which is magic QP. Excellent. So save that. Now we have a reference to our cube. Next thing we're going to do is we're going to add velocity to our rigid body. So if you went through the documentation of the rigid body in unity, in Unity documentation, I think you have noticed or maybe you didn't, but there is a component or how do we call it a property and my rigid body that we can use in order to manipulate the velocity. So now our arrow keys no longer print things to the console. Our arrow keys now actually manipulate the velocity of our rigid body. So let's do that. So in order to access the velocity, we will write my Rigid Body 2D, which we now have a reference for dot velocity. Velocity. Now, if we glance over velocity, we see and actually Visual Studio tells us that it's a vector to what is a vector too? Well, a vector is a vector in to the space. So that means it has the x-coordinate and the y-coordinate. Now you should be pretty familiar with X and Y coordinates from school. It's not too hard of a math, but it should be. Now, I will of course, leave some resources in the video attached to this video where you can check out everything about vector tools. Don't worry about it. It's pretty simple to create a vector two, we only need to do is write new vector two and open the brackets. Nothing too fancy. And inside those brackets we can actually go through multiple parameters that this vector two can take. And it takes a float x, float y. So how do we want to move it? In our case, we are pressing the up arrow. That means we want the box to move upwards and not move to any site to site. So how do we do that? We simply write 0 f in the x-direction and ten F in the y direction. So can add means it's a flow because our parameters told us that the rigid body takes floats. So let's go ahead and continue the down arrow. Now, even though Down Arrow, I don't think we'll be needing it, but for practices, practice, practice reasons, we are going to add it and being this is down, instead of ten, f will make this minus ten. So save that. Let's go into Unity and see if something actually worked. So click on play. R cube falls to the ground and if we press the up arrow, he actually jumps and then falls down. So up, up and then down, down he falls faster. Excellent job. And now you know what time it is. It's time for your challenge. Complete the magic. So you have to finish adding velocity using the left arrow, and then you need to finish adding velocity using the right arrow. So pause the video right now. Go ahead and do that. Challenge. Welcome back. How did you get on with that? I hope everything went well. It's very easy that simply copy that. And now when we add it to left, we will have 0 in the y direction and we will add minus, let's say ten. Let's keep it them. And in the case of the right arrow, will add ten AF in the x directions direction and 0 in the y direction. Go back into Unity can lack on play. And now a free press on the left arrow. We should move left or right arrow and move right, up, up, up, down, down. Everything works perfectly fine. Final step, as always, I don't think I will keep doing this, but for now just to get you in the habit of doing it. So assets, what should we call this? Well, made my cube move left, up, down, and right based on the arrows, put an exclamation mark. So comment that I'll see you in the next video. 13. Using If, Else If, Else Statements: Welcome back everyone to another video. As the title suggests, we are going to be learning about if conditions and we are going to learn how we can manipulate them. So if we click on play right here FOR box moves to the left, our console prints that are cubes out of bounds to the left. And if we move to the right, it tells us that our cubes out of bounds to the right side. And the best part is if we jump, it tells us that our cubes out of mine bound to the upper side. So how are we going to do this using if statements? So put your concentration caps on and let's get started. So before we start, let's talk about what if conditions are, why we use them and their structure. So conditionals, if statements, they are, as the name suggests, they are called that we execute only under certain conditions. So this is the structure of an if condition. We've used it before and our arrows in player inputs. So if some condition that needs to be true is true, we execute whatever code is inside these curly brackets. So if we put in a Boolean, as we've said, a boolean can either be false or it can be true. So if that Boolean is true, we execute the code that is inside the curly brackets. Now if this statement happens to not be true, we will simply just avoid or not even considered the worthy, if, not even consider the code inside of the if statement. But if we add another else, if and as its name suggests, is if the upper condition does not, is not true, we check for a second condition, which is some other condition that is true. And if that statement or condition is true, we execute the code inside of these curly brackets. And if both statements are false, then we finally use something called Else. And this does not have to be, nothing has to be true in order for the scope to be executed only all over. If conditions above it should be false. And we've used this else if condition before. We've used it in our code when we tried to get the key down from the player. So how does this exactly work? Let's zoom in a bit. So input, this input, which is a class and unity, uses the function or method, get key down. So if you hover over the guessed key down, you can see that it's a boolean and it returns a true during the frame, the user start pressing down. So whenever our player presses the up arrow, as we've used, as we've said, told it here. And we did it using key code, which is a another function in Unity, dot up arrow. If he presses these, the up arrow. It tells the get keydown that this, during this frame, the up arrow key was pressed and it returns true. That makes our cue, that makes this code right here Execute and moves our cube. And the same is true whenever we use the other if statements. So now what we're going to do is we're going to be creating our own if condition. And we are going to do that in our case for the game. So for now, if we click on play and remove our cube from side-to-side, whenever he gets out of boundaries, he falls down from our platform. And what we want to do, first thing, we'll make our platform just a little bit bigger. So will increase its scale. Make it just a little bit bigger to give our cube a place instead of just falling into whatever down is. And now we are going to check for the coordinates on this cube. So this white frame right here is what our game actually sees. And if we lock our game view next to our scene view, oh, and as you can see, it gets smaller. To fix that, we can simply go into gain and click on this right here and simply make it into 16 by nine. And this should always keep or frame at the same dimensions. So now if we go into our scene, let's make this a little bit wider and click on our game queue or magic e cube and move it. You can see at the top right and the inspector that the position changes. And this value can actually be accessed. So whenever our cubes goes outside the boundary. So let's say it should be right about here, which is 9.42. So whenever it goes outside the boundary, we want to print something to our console. And the same holds true whenever we go to the other side, which is what should be 9.40, we'll settle for 9.5. Okay? So how are we going to do that? Well, using the structure of if conditions that we just learned. So let's go ahead and save this and go back into our Visual Studio. And we'll do this inside of object. So what are we going to do? We want to check if the cube has moved outside the right boundary. So if should we write here, first thing we'll need to do is access the transform of our cube or game objects. So its transform, simply write transport dot position. And we're not looking for any position. We are looking specifically for the x-position, so it's X. So if Transport dot position, dot x is greater than 9.5 f, because remember it's a float. Then inside of the if statement, we want to execute some code. And for now we're simply going to print out to our console. So we're like debug. But log, let's make this a warning just for fun. So debug dot log warning. So we should write something inside of it. Our cube is out of bounds. To the right side, was two exclamation points to make it a bit more dramatic. So save that. Go back into Unity. Wait for it to compile and understand what is happening. And now clear all of that. Click on play. And now if we move to the right side, as you can see, our cube is out of bounds to the right side. And the more we move, but if we move to the left and nothing happens, so pause that. And now we'll make a, an else if statement. So else if. And then side of it. For our else if statement, we're going to check if our cube goes to the other side of our screen. So it's transform. Again, we access the position and we need only the X. And now we are going to check if it's smaller than minus 9.5 f. And in this case, we're going to also print a warning, which will be our cube is out of bounds to the left side with two exclamation points. So let's make this a little bit neater. Control S to save all of that, go back into Unity. Wait for it to compile, clear everything. Click on play. And now if we go to the left side with r cube, it tells us that our cubes out of bounds to the left. And on the right side, it tells us that our cube was out of bounds to the right. But now if we jump without cube, nothing happens because it's time for your challenge and your challenge is to finish the last if statement. So finish if statement when our player goes out from the top of our screen, and I'll give you a couple of hints, will need to move the cube around in our scene and understand the top boundary. And we'll also need to use the if statement to print to our console. So pause the video right now. Take your time with this challenge. I'll see you in a bit. Okay, welcome back. So let's clear this up and let's see our upper bound. So if we move our queue and we can see on the right here that we have the y position changing. And if we take the y-coordinates and check for them at about 5.5 r RQ leaves the camera view. Okay, great. So let's go back into our Visual Studio and write another else if statement and else if our transform dot position. And now instead of the x, we're going to be using our y. So if our transport dot position dot y is greater than 5.5 f, we will print another warning in here. And this warning, our cube is out of bounds to the upper side, also the exclamation points, save that, go back into Unity. Let's wait for it to understand what we've done. Click on play. And now if we jump, jump, jump and we get out of bounds, it tells us that our cube is out of bounds to the upper side. Okay, so final step, let's move out of play, go back into our source tree, and now we can commit everything. So stay Joel, click on Commit and we'll call this adding if statements to my game. Click on Commit. And I'll see you in next video. 14. Public Methods & Return Types: Welcome back everyone to another video. In this video, we are not be doing a lot of coding, but we will be restructuring our code. How are we going to do that? Well, as you see, our update method is a bit different because we extracted all of the things that are related. So for example, now we have a method that is moving our cube and it's right here. And we have a another method that is out of bounds. And our printer, not only that, we've also created a public method which is printing from outside, which also has a parameter. So exciting. And it returns a string and it's used not inside of cube. It's used in platform, a new script that we've created. I'm so excited for this video. I hope you are too. So let's not waste any more time. Let's get started. Okay, so if we look right now at our start and update methods, we can see that they are kind of cluttered and there are things that are not related to each other. So for example, we have all of these if conditions that relate to our cube movement. And we have them right next to the if conditions we've created to understand the boundaries of our queue. So we need to restructure them in a way and to make it look more appealing to the eye. So we're going to do that using methods. So what our methods, well, method structure are kind of like this, just like we have the start method and the update method. We can also create our own math. And they kind of look like a valuables, but they are also kind of difference. So we have V2, first of all, is the access type, and this is the accessibility. So we have to access types. It can be either private or it can be public. And we're going to use both in our project. So private is when a method is only used inside of its class. So for example, if you create a public method inside of cube, only cube can use that method. But if you create a public method, other scripts can use your method. Also. Then we have the return type, and for now we've only used the void, which means that we return nothing. We can have a return type of integer, for example, where a certain method returns an integer, it can also return a string and it can return other things. We also have a method name. So the method names should always reflect what the method actually does. And as a convenience, just as we name our variables, the first word will all always is not capitalized when we are naming methods, our first word is always capitalized and all subsequent words are also capitalised. And finally we have parameters and we have a one. A parameter has nothing inside of it. That means we pass nothing. And what parameters are? They are like variables that we pass to our method and we can use them inside of our method only. So how are we going to use these methods structure? Well, we're going to use it inside of our code right here. So let's begin by restructuring some things. So as an example, I will show you how much more efficient our code becomes. So let's remove all of these comments right here. And as you can see that every time we would need to comment these debug logs, we need to go and do them one by one. Well, we can actually use all of these if you highlight them. And of course you're using Visual Studio and you right-click on them. You can see that we have something up called quick action and refactoring. So if you click on that, tells you if you want to either extracted to a local function or extracted to a method. So if we extract it to a method, and by the way, the difference between a function and a method, you can actually use them interchangeably and however you want. But functions are usually methods that are inside of a, another method. But a method is a method that is outside the method we're currently doing. So it's a bit confusing. You can use both of them interchangeably. Don't worry about. So what are we going to name this method here? And we are going to call it printing to our printing equal weight to our console. And click on and turn. And now we have this function or method right here. And as you can see, it's a private method that doesn't return anything because it's void. And now if we want to comment that out, we can simply comment this function out and all of it is commented out and at 1P printing to our console. So this is the first benefit of using methods. So let's go ahead and put this under update. So if we click on Control X to cut it, and we'll put it below update. I like to put update right below the start method to have a nice and cohesive structure to our code. Next thing we're going to do is we're going to extract to nother methods. So first of all, we're going to highlight all of the if conditions in our AP for our food, for moving our cube. So highlight all of them, a right-click, create a extract a method. We'll call this mass moving our queue. And we will also extract this method. And we'll right-click go to extract method. And we'll call this method, what should we call this? Out? Of bounds printer. Okay, so now we're sorry for the Get Back to zoom in on it. So now as you can see, our update method is very cohesive and it, uh, we can easily see what our update method does. So it is moving our cube And it out of bounds printer the checks for out of bounds. Whenever r cube is out of bounds, it prints something to our console. So now you can see that we have this method right here and another one right here. And finally we have the printing to our console. Excellent. Now we're going to create a second script and create a public method just to demonstrate how everything is working. So first thing we'll do is we'll create a public method just under update, and we'll call this, well, first of all, let's make a public we'll make this a void because we don't want it returning anything for now, public void. But we'll use it. We'll call this printing from outside. Okay. You don't have to make your method names that long, but just for the sake of giving an example. So what this function will do, it will simply print something or a certain message that will have Hello from the other side. I don't know what froms capitalised. It doesn't have to be. So it's Hello from the other side. Let's go back into Unity. Click on platform because it's the only other object that we have besides the camera. Let's add a component and let's create a platform. Plat form scattered. So New Script platform, excellent. Let's go ahead and create it. And it enough, but it should be added. And now if we, now we have it in our project. So double-click on it and it should open in Visual Studio. And as you can see, we already have the void update method and the void star. Now inside of start, we are going to get a reference to our cube script and use the public method that it has. And how are we going to do that? Well, we're going to do that using something called find object of type. An object of type has these two operators right here that we need inside of it to tell which script we are going to use. So it finds the object of type cube and Visual Studio always helpful. And now if we click on dot, we can see that we can use anything that is inside of the cube. So if we, for example, want to access the Start method, we can't. But if we want to present, as you can see, it gives us the printing from outside method because it is public, so free. Save that and go back into using Unity. And let's also save our scene and click on play. And before we do that, let's clear this up. And as soon as we click on play Hello from the other side, how cool is that? So we've created a function or a method that is inside of the cube, but we are using it inside over the platform. That is so cool. And this actually is the basis. And it's very crucial because we're going to be using it a lot in our game in the next sections. So your challenge is to create your own method. You'll create a simple method with a string return type. So instead of void, you will have it as a string type. You will also give it an integer parameter, and you will use it with the string and return it. So it's a bit of a big challenge, but I think you are ready for it. And a small hint use to string. And it will require a bit of research to understand and do the challenge. Take your time. Don't, don't be afraid of making mistakes as I've told you, trying and failing is not the end of the world. So I'll see you in a o. Ok, welcome back. So now we are going to change our method just a little bit. So instead of void will make this a string, and it currently doesn't take any parameter. So we'll give it a parameter which is an integer. And we'll simply name this integer value to not be over-complicate. As you can see right here, we have a squiggly red line. That means that our function is not working properly, properly. Why is that? Because it has a return type, which is a string, but it's actually not returning anything. So how do we fix that? Well, we need to write here return, and we need to return a certain value. And what that value is, well, needs to be a string. So let's go ahead and create a variable inside of our printing from outside. So this variable will be a string. We'll call this variable printing something. And what? We'll have it print, well, the value we were s_1 is. And now we can use this parameter that we've been sent from the other side. And now in return, we will return, print something and that trip fix our squiggly red line problem. But because we've given it a parameter in here where we call it from, should also give it a certain parameter. So we have to give it an integer. And that integer, let's say, will be a 4x4 or anything. Or you can even create a variable right here. We'll call it an integer. We'll call this value to sand, and it will be equal to say nine. And in here, we'll send the value to send save that this actually returns a string. So let's put it inside of a string reference, which we'll call string from L outside equals. And now we'll simply debug dot log and will be printing this string from outside. So close that, save that, go back into Unity. So clear everything. Click on play. And now the value we were sent is nine. Excellent job. And one thing I want to make clear is that because this is a string and this method returns a string, we can actually directly put it inside of our lock. Excellent job everyone. Hope the challenge wasn't too hard. I thought it was a little bit step up and it needs a little bit of research, but I hope you tried your best. And as always, before we go, we need to stage all comment. Created my first public method with a return type, commit that, and I'll see you in the next video. 15. Prefabs And Parent Child Relationships: Welcome back everyone to a new and very exciting video. In this one, we are going to learn about prefabs. And not only that, we'll, we'll learn about prefabs, how we can use them from scene to scene. Here you can see that we have a diamond was something called a polygon collider. We also have this magic cube and a small circle, but actually the circle moves with our cube because it is a child of that cube. We can also, we've also created a second level, level one and level two. Here we have three cubes, as you can see, and for some reason they are blue, and we'll see why they are blue. We also have in diamond right here. And if we click on play, all of them fall down, and that's it. So, so exciting. I'll see you in a bit. Okay, so what is a prefab? Well, basically it's a template for a certain game object. So if we created a game object with all its components and its script and its position, we can create a template from it to create other similar game objects. Ap system allows you to store a game object with all its properties. So let's say our periphery has a collider, it has a rigid body and it has a script. Whenever you create a prefab from set game object, you will have the same properties. And so why do we use it for? Well, we can reuse a game object configured in a particular way. We can edit many objects at once, and we can use the same object and different, different scenes, much easier. So let's go ahead and demonstrate these three uses. So creating a prefab is actually very, very, very simple. You, all you need to do is simply click on the thing that you want to prefab. So for example, we want to prefer our magic cube. Click on it and drag it into our project. And now we have a prefab of our cube. And you know, it's a prefab by looking up at the hierarchy and you can distinguish it by, because it's a bit more blue. Excellent. So now, what can we do with our prefab? If we click on it, you can see that it has the same properties as the cube in our scene. And now if we click on the prefab and jacket and to our scene, you can see that we can create three beautiful magic cubes extremely easily. And this is very helpful in many ways. So let's demonstrate how prefabs work. So let's say we click on this magic cube, which we see in the hierarchy is number one. So let's say we want to change its color. So if we go into our sprite renderer and choose color, and let's make it red. So now we have a red Magic cube. We save that. And you see that. Other two magic cubes are still white. And by the way, these cubes are called instant instances of prefer. And if you look closely in our inspector, you can see that we have a another tab open. So we have the open which opens our prefer, which has the magic cue. We can select the prefab and we can overwrite. And what this does. It applies whatever changes that we've made to our current instance, to our brief. So the things that have changed, you can see that they are also highlighted in a blue color right here. And we changed the color. So if we click on overwrite and click on apply, all what should happen is that all of the other instances of that cube changed to red and down here and our project, you can see that our magic cube is red now, that is very cool and you can start to see how helpful that is. So let's say we changed back, change back the instance to white. Let's take another cube and change that to green. So now, if we apply this to our prefab, What do you think should happen? Well, all of them turning green or will only the one that is the red turn to green? Let's try that, apply and ops, as you can see that only the prefab or that was originally, or the instance of prefab that was still the same as the original is changed to green, but the ones that we've also modified don't change back. So privet prefabs are a bit tricky, but they are very helpful. So for example, let's go ahead and delete those three cubes. And let's go into scenes and let's simply duplicate our current seen. By that we create a second scene. Let's rename this to level two. And our original scene will be level one. So now, yes, it asks you for preload. Simply click on yes. So now in level one we have these three cubes and then level two, apparently we also have these three cubes. So let's go ahead and delete them. Save that. So in level one we have the cubes. In level two, we don't have cubes. So what are we going to do about it? Well, instead of going to level one and duplicating or copying the cubes, we can simply go to our project and we have a magic cube. And we can add it easy as pie, right into our scene. And now we have a cube, a magic cube, and our scene. Okay, great, so that's a Prefab. Now, what our children well, let's go ahead and create go to assets. And to create a sprite. And the sprite will be a circle. So now we have this, let's say magic child circuit. Okay, so magic child circuit, we can go ahead and add this magic child circuit to our scene. And by the way, this magic cube is the prefab. This is just the sprite. By the way, we can also organize all of this. Or if we create a folder called this sprites, we can put both of these into sprites. We can also go ahead and create another folder called this scripts. And now we have these scripts inside of the folder scripts. And if we add another prefab, we can also create a folder for the prefabs. So now we have this magic child circle. Why do we call it the child circle? Well, because we are going to child it to our magic cube. And we do that by simply taking our magic child circle and dragging it right under our match cube, and now it's a child. Now what this child mean? If we click on the circle, we can move it as we always do. But if we click on the magic cue and we move it, you can see that the circle moves whether that means it is a child. And if we scale our cube, r, circle also scales. And if we scale in the y direction, it also scales if we wrote it. So let's see if we rotated. The circle also rotates and these are properties of a child grows with its parent. And the parent is magic cube. So it grows with its parent, shrinks with parent, it moves and behaves just as its parent does. And this is very helpful because sometimes we may need to add children. So if we have an object that has several objects inside of it and we want them all to move in unison. Instead of coating all of the children, we can simply coat things to the parent and the children will move with the parents. So we'll be using a lot of parent children relationship will be using prefab Also a lot. And now it is time for your challenge. And your challenge is to create a new prefab. So create a new object in our scene, whichever scene you want. Prefab it, make an instance of it in a different scene, and add a component to that instance. Apply the changes to prefab and see what happens. And if you want as an extra challenge, you can also make a child-parent relationship somewhere in our scenes. So pause the video right now and go do the challenger. Okay, welcome back. How did you get on with that? I hope that wasn't too hot. So let's take this cube, put it over here, or magic cube, which is square, ironically. And now let's go and go ahead and create something. So we'll go into sprites. Let's see, we'll create a diamond because diamonds are for diamond. Click on Enter and let's go ahead and put it in our scene. And we'll put it inside of sprites. Now we have a diamond classmates timeOfDay, but bigger. And let's change its color. So let's make it a blue, because diamonds are kind of blue, I guess. So now we have this diamond in here. And when we want to do is we want to. So what was our challenge? It was make an instance in a different scene and add a component to the instance. Okay, so we take this diamond and let's Prefab it. And now because we have two prefabs, let's create a folder, call this prefabs and everything is organized and meet. So now we have the diamond that is go ahead and save that. Go back into our level one scene and we have three cubes here, but now diamond. But we can easily add one from our hierarchy, super easy. So let's add the components. Component. Let's add a Rigid Body 2D. And let's also add a collider. And what kind of Collider should we add to it? Let's go ahead and add a circle. Sure, why not a circuit? Well, actually it should be a polygon collider. Let's make it a polygon collider and it fits perfectly. And actually just for the fun of it, let's go ahead and rotate it in the y-direction. No, not in the y direction. I meant in the z direction. Okay, great. So save that. But right now we are click, as you can see, we clicked on the diamond in our scene. We've actually added a rigid body and a polygon collider. So it's not added to our prefab. If we click back on our prefab and projects here below, we can see that it doesn't have any rigid body or collider. So back into diamonds. Click on override, Apply. And now in our second level, save that. And our level two, sorry for that. Scenes. Level to the diamond actually has rigid body and a polygon collider, which is great. So click on play just to see it fall. Diamond falls and everything falls. And as you can see, the, even, even the circle falls with r cube. But because it doesn't have a colloidal, nor does it have a rigid body, but it moves without cube. So I hope you did the challenge. I hope you enjoyed this video and I think this will be the last video on our section. In the next section, we're going to actually start creating our gain. So exciting. So review this, make sure you understand everything in this section and don't forget to always commit our work. So let's call this stay Joel. Add a diamond prefab and a child circuit to my magic. Cu O K TG rates or convinced that it saved, we have it in our commits right here. And I'll see you in the next video. 16. Section 3: Setting Up Our World - Game Design : Hello and welcome back, my favorite game developers. In this video, I'm going to talk a bit about game design. And as you can see, I've heard it started and already the Google slides are very excited to tell you about the gang sketch. So the game sketch is the following. Now, it's not very impressive, but it will get the concept of our game around. So you've already watched the introduction video where I showed you the game that we have finished already. But now I will take you through the steps that it took for me to get the game developed. So first thing first, I've created this mini sketch. And as you can see, well, it's not very impressive, but it gets the job done. So first thing first we have the tiles right here which will define our world. And we have the background tiles or the world combiners right here on both sides. Next thing we have are the doors. So we'll have the enter doors through which our conqueror right here, this little guy enter through and start the level. And this is the door right here that he has to go through in order to advance to the next level or room. Next thing we have the bombs right here that I've sketched as burning. And they will explode as soon as we get near them. Well, not as soon as they will start burning when we get near them and they will explode. Eventually, we have the hearts that we can pick up in order to increase the lives we have. We have, of course, the hanging sheets right here that we can climb to get two platforms that are unreachable. We have the diamonds, of course, that we pick up to increase our score. And we have the little monsters right here that will try to attack us and Canvas, but we have the power of source hammer that will crush any enemy and our path. And also we have this little square right here. And if you've noticed in the introduction, of course you've noticed because I've told you like ten times, because I'm so proud of it. This is the camera that will follow our player wherever he goes. So instead of having a huge camera around the entire leveled and having to move our tiny, tiny player around, we make the camera follow our player where ever he goes. That is very cool and I encourage you to create your own games sketch and see how you want to make your own game. So next thing, let's talk about the 2D platformers because our name is going to be a 2D platformers. So I'm sure you're familiar with a couple of these. This is a recent game called Celeste, which many regard as one of the best games of I think two thousand, two thousand seventeen. I'm not sure, but it's a fairly modern game. And as you can see, it's just like our game where it has toils and it has a pixelated character that moves around in the 2D platform that they have created. Next thing we have a hollow night. Not sure if you've played this game, but it's really amazing. It's similar to dark sauce and difficulty, but it's a 2D platformer. And I've used modern examples just to show you how much 2D platformers are still relevant in game development. And you can see right here that it also has a tile maps and platforms and backgrounds, and little pixelated. Although they are, but more polished than our game, and not as pixelated, but the same concept applies. And finally we have Shovel Knight. I'm not sure if you've played Chavan light, but it is an amazing game. I've played it, I finished it. It's very cool. And as you can see, this is very similar to our game. It has the ladders, it has the enemies, while the enemies are bigger, and it's pixelated just like our game. And the final example, I found this on Google. I'm not sure who did it, but as you can see, they have sketched up the game and the pixelated it and it shows the tiles that were used to create the game. We will use similar tiles or similar way of piling our game and making our game a 2D platform, just like this one would ladders platforms and with a background. So castle Conquest, game design, what am I going to talk about right here? So this is a screenshot of our game, and let's talk about the core mechanics. So we'll have our conqueror running, jumping, climbing, and he will also be attacking. What else should we talk about the core gameplay, but it's going to be getting from the start of the level, from the starting door to the end without getting hit more than three times. As you can see, as you saw in the introduction video, I've showed you that our player, or the conqueror is the player and our game has only three lives. And that's not talking about the large that he can actually pick up. Every time he gets it, he loses alive and if you lose three lives, you're done. You need to go back to the main menu. So let's talk about games story also because that is, you might think that, well, you know, I don't think we need a game story and you are completely wrong because the game story is, will the game story will be the, I'm not gonna say the core, but it is the nucleus around which the core is built. So what is our game story? Well, you are a king and you've just inherited the castle from your father. Monsters, pigs have taken it. And you need to defeat them all. And you need to go through every room and tried to crush every single one of them. And also along the way, you'll need to collect d1 times. So this will make the came much more interesting. And as you're playing through it, you can feel that you have the ability to take charge of whatever is happening in the game and you have a reason for killing the little pigs, not just for the sake of killing them. You'll have a reason and you're collecting diamonds for a reason because your castle is infested with them. You need to take back your pride. Okay, that's a bit dramatic, but you get the point. You always need a story for your game. Next thing we're going to talk about all the technical requirements to create this king. So as you can see, we had a lot of stuff. So first thing we need is a tile set for the background and the foreground with some elements. So I've chosen a tile sad that I will show you later on where I got it from. And I will leave it, of course, until resources. Feel free to go and get your own path sets. Make sure that you have a foreground and a background tile set for our game. Next thing, we're going to use inputs from the keyboard to control our gain. We will add a follow CAM that will follow the player or the conqueror wherever he goes and zoom in and out depending on his movement, as you saw in the introduction video, when we're running theorists, a certain zoom in, when we're standing still or idling, there is a certain zoom out and so on and so forth. And will also create an automatic way of adding background to our game. That means that will add a row, we'll add rules to our tiling and make all the background automatically fill everything and save us a lot of time. So let's talk about some more gameplay features that will have. As you can see right here, our little player is punching the air, but even though the pig is a bit far away, but the conquerors movement, we've covered this before, but it's going to be running, jumping and winning the hammer. As you can see right here depicted in our screenshot, there will be hazards. There will be bombs that will, that bombs that burn and explode if we're near and they can actually kill us. We will have a start and end point, will have doors that the conquered walks through to get from one room to the next. And by room, I mean the levels of our King. Next thing we'll have the pickups and the pickups, our lives along the way for the player to pick up as we walk and all the diamonds that you can carry with you. Now, it's time for your challenge, and your challenge is going to be to create your own game design. So figure out a story for our game. Think of a compelling story, a story that make whoever is sitting behind the computer and who's going to play your game, feel excited and give him reason. Giving him reason, give him the motivation to go and kill all the pigs and collect all the diamonds. Next thing you need to find out the game mechanics you want. Maybe you want to add other game mechanics. And I completely encourage you, even if you don't know how to actually implement those mechanics. Just to write them down, keep them with you. And along the way, you will find out how to create them. You will go and download your own sprites and typeset. And as I've told you, make sure that you have the foreground and the background. I will leave the links in the resources for you to go ahead and download all search for whatever tile sets and sprites you want. Or you can simply use the same, that amusing, figure out what features you want to add. So as I've told you, we have picking up things, we have climbing the sheets. You can also add your own features. I'm not sure what those will be, but for example, you can add power ups. That's a good idea. So write that down also and figure that out for yourself. And as I've told you, this is going to be very exciting and some pump to start creating this game. And I hope so are you. So let's start our journey to gather, and I'll see you in the next video. 17. How To Slice Up Sprites In Unity: Welcome back everyone. Now we are starting a new project which is very, very, very exciting. Oh, okay, so first thing, we are going to create our project. So open up your unity hub and go into add new. So it will be a 2D project. And we'll name this castle conquest to D. And remember, we're saving it because we'll need it for the repo to create. And now we wait for the project to be created. I'll see you in a bit. Welcome back. So I've accelerated the process of creating the Unity project using the magic of editing. And now we will, we are going to set up a new report. So this is from magic cube to setup a new ripple, simply click on the plus button up there. You can close this tab and click on the Create button right here. So we browse for our path. So wherever you've saved your path, go into that and click on the castle conquest 2D. Select the folder, keep it longer it keep the Create repository on account unchecked. For now. Click on Create. Click on yes. And now we have a repo. So as always, we know that we should simply click on the Library, ignore everything. Ignored everything beneath Library. Click on OK. Now we go into the gitignore. W click open and our notepad. And you should have everything by copying and pasting if you don't remember how we did it, check out the I'm not sure which video. I think it's the second video in the previous section. And you'll find where you can get the gitignore or simply Google it. And now we have everything set up. So we simply going to stage all commit and call this initial comment. Click on Commit, and we are ready to go. So first thing we're going to do is we're going to be importing the sprites I've provided you in the resources. So go ahead and get them. Simply click on them and drag them into our project right? Now before we get started, I want to take a moment and explain what is a sprite. So as this is a Sprite, This will be our hero or our conqueror. And as you can see, he is a image. So a sprite is a 2D object, and this 2D object has a graphical image on it called texture. So sprites are 2D objects and they have graphical images on them called textures. And they are used by adding a component called Sprite Renderer to an empty game object. So we create a game object, we add a sprite to it and we can have an graphical image on it. Okay, so now that we've explained what a sprite is, it's time for us to create our terrain. So our, before even that, it's time for us to slice up our terrain. So right now, if you click on the small arrow right here, and you can see that it's a single image. So what we need to do is we need to slice up. So if we click on it, you can see here in the inspector that we have many options and one of them as the sprite mode. First thing you need to make sure that your texture type is of sprite 2D and UI. And the sprite mode should be multiple. So click on that and apply everything and go into Sprite editor. So as you can see here, we have all of these. So the top ones will be our foreground and the bottom wounds will be our background. So here on the top, at the left you can see that we have multiple ways of slicing our sprites. One of them is automatic. So let's try that as an experiments or click on slides. We can see that it's slices them up pretty good, but that is not what we need. We don't want this entire block to be a single slice. We want to slice it up into four little sprites. This one also, I think more than that, I think this one is nine sprites. This one is for little sprites. So how can we do that? Well actually and slice, we have something that's called grid by cell size or grid by cell count, will be using the grid by cell size. And I know that it should, the pixel size should be 32 by 32. So we slice that up, click on slice, and now we have our sprite sheet sliced up into little sprites. Okay, great. And you can click on each one of them and check the information about it. So this is the rain, this is terrain also, and each of them has a number. Now if you have time and you want to be very meticulous with this process, you can actually glean, name each one of them and make it your own. But we don't need that honestly. Okay, great. So apply that on this pattern right here. Apply that. And now we have our sheets sliced up, Excellent and correct. And this is everything we'll need to do and it's time for a challenge. And your challenge is going to simply be sliced up your own spreadsheet. So import whatever sprite you choose to use for your game. I've given you the resources, the website where you can find free game arts and simply import them, slice them up into sprite sheets for the background and the foreground piles make sure that you have background and foreground. And as they less step of this process, we are simply going to create a folder. We'll call this sprites and will drag the terrain inside of it. And another thing maybe we'll change this and name this level 0 because we don't have any other levels, simply level 0. Ok, so this project will be great. It will have lots of sprites, two will have lots of scripts. So let's start with some good organization habit for the first video, and I'll see you in the next one. 18. Tile Maps In Unity: Welcome back everyone to another amazing video. And this especially is the best video, I think in the whole course, because we are actually creating our platform. As you can see here. We've made a small platform. We have the style map over here on the right, we have on the left also AOL mapping grid and our hierarchy. We used all the sprites that we've sliced before to create this platform right here. So let's not waste any time. I'm so excited for this video. I hope you are too. So I want you to summon all your creative power to this video and I'll see you in a bit. Okay, so tiled maps, what are we going to do? Well, first thing we did is we got our sprite sheets. We slice them up into little sprite sheets. We are going next to create tile assets. We're going to take those style assets and add them into our file palette. And finally, we'll use our Kyle pilots to create all tiled map. Oh, okay, great. So back to unity, where we are going to, first of all, go to Window and look for our tile palette, which should be under 2D and style pallet. So click on that. And now we have our palate. Feel free to dock it where ever you want. I feel like I want to talk next to the Inspector. Make this a little bit bigger because we are going to need it needed later on. Next step, we go into our hierarchy here on the left where we don't have anything except for main camera. So right-click and go to 2D object and look for tile map. When you click on it, we can see that a grid has been created. It's called the grid and our hierarchy and a tile map. So let's change the name of the style map to go into Inspector. Make sure you go from inspector to tile map. So tile map changes to back ground and create another one. So an ingredient we're going to create another tile map and we'll call the swan foreground. Oh, okay, great. And we'll also rename this from credit to tile, map, grew it. Everything is great. So now what we are going to do is we're going to create a new tile palette. So I'm going to tile palette and here under Create a new tile pilot. Click on it. And it will ask you for a name, will simply named this main main palate can create. And it will ask you where you want to save it. It's, these are your assets folder. So let's go ahead and create a new folder called tiles and save it inside of our tiles select folder. Now we have a new folder which is files and it has a main pipe palette. And this is our tile pallet. So. What are we going to do now? Go back into our sprites in the hierarchy on the left and choose all of these sprites. So go ahead and choose all of them. To do that more Fast. Click on the first one, go to the last one, hold shift and click on it so you choose everything and drag them into our tile palette. And we should have a big, huge master. Ok. Now, go back tiles and inside of tiles, select the folder and save them there. So wait for them to become pile assets. And they should be at now o k. So as you can see, a huge mass has been made. Now of course, we are going to be moving all of these and rearranging them. Now you can rearrange them the way you want to. I will do later on. I will, it will be the same arrangement as the one on the terrain. Feel free to do your own arrangement. So now it's time for the exciting part. So let's choose one of these tiles and start drawing. But as you can see, these are very small. So what's the problem? Problem is that when we are choosing our sprites, they are actually the pixels per unit is 100. So how are we going to make them fit? We're going to change this to 32. So go to our sprite, click on it, go to the inspector and make sure that the pixel per unit is 32. Apply that and they fit perfectly into R-squares. Great, back to our tile palette. And now let's go ahead and draw a simple, very, very simple background. So we can also learn a bit about the stuff up here. So every time you want to draw, you have to make sure on which active tile map you are. So for example, I just drew a abit of tires which were on the ground, which was not correct. You need to make sure you choose the right active tile map. And over that you can see that we have this brush with which allows us to draw a single file every time we have next to it, this box drawing, which we can simply click on here and drag it and make as many boxes as we'd like. We have this, pick where we choose one of these and we can actually change all of them. And now you can also experiment with all of this. And we finally have this. This is a, an eraser which where we can remove whatever we feel like removing. So let's draw this again. And now we are going to change into foreground. And now when we are foreground, we choose the tiles for the foreground. Back to background. Make sure that we, everything is in the background and the things in foreground are always the tiles for Foreground. So now if we click on play. This will be our game view. How cool is that we're beginning to create our game. Excellent. But something I want to point out is that we need to make sure that we are working on the right layers. So what do I mean by that? Well, if we go back into seen and our tile palettes, if you click on the background, we can actually draw over our foreground, but tiles, which is not very good, we need to make sure that when ever we draw, our foreground is well in the foreground. So how do we do that? We do that using sorting layers. Sorting layers are very, very who'll aspect. So if you go into the hierarchy in the background, you can see that we have a tile map. Under that, we have a tile map rendered. Now, if you want to go into the unit documentation and find out everything about everything, feel free to do that. But what we're going to focus on are these additional settings. So if you have it closed, open end up. And you can see that we have sorting layers and we have ordered layers. And now on foreground, you can see that we have these sorting layer and ordered layer. So we need to create a sorting layer for our backgrounds. So click on the sorting layer which is now default and click on Add sorting layer. So to add a sorting layer, simply click on this plus right here, and we'll call this R for ground. Let's add another sorting layer and make this one back ground. Now we have two sorting layers and below it, and above it we can see the tags, which something that's useful for coding, and layers below it, which is good for collisions, will talk about these later on. So go back and to foreground. And now in the sorting layer, instead of default choose foreground and for the background, choose background. But as you can see here, our background still is in front of our foreground. Why is that? Well, if we go back into the layers to sorting layers, the ones below will be rendered first. So if we move up the background and put it above the foreground, the foreground will be rendered in front of the background. And every time you need to make sure that you have your layers in the right ascension or dissension. Okay, excellent, save that. And now we are going to create a simple platform. A very simple platform. But first, note, not challenged, not yet. First, I will use the magic of editing to rearrange all of these styles in here. And it's not going to be something very amazing you can do with the way you wish to do it. I'll simply make it the same as our original arrangement. Okay, I'm back from my magical editing trip. So as you can see, I've rearranged all of my tiles and I forgot to do something. I forgot to teach you how to actually do that. So. Excuse me to do that, simply click here on edit. When you click it, you actually have access to all of these tiles. So if you check on here, you can actually select an area of the grid using S and then you can move it using AMP. So click on us, click on one of the Tiles, click on M, and now you can move it wherever you want. And when you finish editing, simply click on this edit button and it will save four. So let's change this back as an OMB and save and control S to save everything. And now it's time for your challenge. And your challenge is going to be to be to create your own platform. So create the foreground and background tiles. Create a new tile palette and rearrange the toils in that ballot just as I did. Or find your own personal way or rearranging them, create a platform from the foreground with a background. So pause the video right now. Rearrange the tiles the way you want them to be rearranged and then go ahead and create some kind of platform. Don't worry about how much the platform should be. Amazing or great. This is just for simple training. I'll do it later on. But pause the video right now and try your best. O k. How did you get on with that? I am so excited to see what your pallet would look like. So now I am going to create a small tile just inside of our screen. Free dog the game right next to it, and it's 16.9 grade. So we can see it. But for now let's simply keep it there. And I'm going to create a platform just inside this camera and to not bore you with all the details and going to, again, use the magical editing. It's such a good magic. It's better than Harry Potter's magic. And I'm going to create a grid or writing. So I'll see you in. Hello and welcome back. So as you can see, I've created a small platform right here. And what this platform consists of, just I made a small for small I rather big wall in here, an obstacle. Maybe I'll make it smaller Later on I made a little platform here where we may, we might put, I don't know, maybe diamonds or hidden box. Then I made these kinds of steps where our player can jump on. And that's basically it. Nothing too fancy. And I hope you did to create your own platform or you might have waited for me to create the platform and then took inspiration from it. But what I want you to do is create your own platform. Don't just copy mine because this is the best part in the course. It's actually creating levels using the amazing magic of tile maps, a lot of magic in this video and see you in the next one. 19. Rule Tiles 101 (2D Extras): Welcome back everyone to a brand new video. And this video, we are going to be investing time. Yes, we'll be investing time right now to save ourselves a lot of time later. And we'll do that by creating the rules for our tiles. So as you can see, and now we can simply automatically create tiles. So as you can see, they fill up automatically, which is very cool and very helpful. So i'll be teaching you how to create these rules. I'll give you all the resources needed. It will take some time and some understand, some understanding to get it, but don't worry about it. Everything will be explained. So I'll see you in a k. So first thing we're going to do is we're going to be importing our 2D extras tile map role. There are two ways to go about this. You can either go into a google and type to the extras unity, and then go into your, into the first result, which is GitHub and downloaded it, downloaded from here, you will get a zip folder and you simply have to import it. First of all extracted and then you simply drag it into your Unity assets or you can use the one I've provided you the resources. I will use that right now. So simply take this role tile that I've provided, drag it into Unity and put it inside of assets. Wait for it on port. It will give you a long list of things to import. Simply click on import right here on the bottom right corner. Wait for it to finish up. And now you should have this folder right here. When you do get this folder, you can go into tiles. And you can simply, let's go ahead and put all of these in a single folder. Let's go ahead and call this terrain rain files. Go ahead, choose all of these and simply drag them into terrain tiles to have more space. And now, if you right-click on your whatever you want, I recommend you go into tiles, go into create. And you can find at the top right here that you have something new. 11 is a prefab branch and the other is ruled out. So click on router and went for this particular rule set, we are going to make rules for our background. So let's go ahead and call this background rule filing. And now if we click on it and go into the inspector, you can see here that we have some weird structure of Windows. So we have the default sprite and we have the tile rules, a list which is empty. And we can add to this list by clicking this button right here, and we can add rules. First thing you need to do is dock this inspector. So simply go up to the upper right of your screen and click on this little lock here. And now this will not change. This will be very helpful. So now, as you can see, it tells us that there are none. Sprite. So we need to add a default sprite. And because we are working on the background will be only working on the background sprites. So go ahead and add what ever random sprite you want to be the default. And now we're going to start by creating our tiling rules. So the first rule will be for a tile which should be in the middle, just like this one. Which doesn't, doesn't have any sides to it or neither does it have any little natural what those are. Those are called, these are for the corners by the way, and this will become all clear, just enabled. Now we've created our first rule. Congratulations. Let's go ahead and add it to our tile palate. So you can either create a new tile palette simply just for our rules or you can add right here of the, above all the default piles all added into this one. Because it's more practical, I believe. So simply click on this background and drag it into our tile palette and should, it should show right here. So now if we click on this one, we can actually draw these rule tiles. See that? Oh, okay, great. And as you can see, the, all of them are of the same type. But if we choose to create rules for it. So for example, if we click on this one, as you can see, everything changes. Why is that? Well, let me explain these how these rules actually work. So let's see this three-by-three box right here. And if we add, we can actually add these kind of arrows. And as you can see, the more we add the moral changes. And what these mean is the green arrow means that there is a tile above it. So when the restyle above it, to the left, to the right of it and below it, then we can draw this style. So this is a rule. And if we click on this green arrow, again, we can see that it becomes an a red X. And what this red X means that it will only draw when there is nothing to its right. And we can see here o. And if we actually click here, it actually makes, well, it shows us what will happen if we add a title here. And you might be wondering why are all the other tiles this way? Well, because it's our default sprite. So let's go ahead and add a nother rule. And let's keep this like this because actually this is our rule for this particular tile. So let's go ahead and add in another room. And for this rule, let's go back into sprites. Will add a corner on the right side. So let's go ahead. So what do you think the right slide should have as its rules? Well, I think it should have one below it, 12ths, right? And one on its diagonal, and it shouldn't have anything on either side. Now nothing changed pretty much, but that's okay because we'll add another rule. And for this rule, let's see what we have. Let's add this 10. And in this case, if we have something to, on these sides and nothing on that side, we should have this right here. And it's pretty much correct now. So let's go ahead and create a nother rule and add this one to it. So now, if we have, for example, what should this have? If it doesn't have anything to its right and it has something on its left, it should create this One. Another thing about these rules right here is that you can actually change them and they can be either rotated mirror on the x or y axis. What does that mean? Well, if we click on this one, you can see that it rotates all the rules. So if we don't want to create rules for, for example, we want to make a rule that's like this one. Okay? We can simply click on the Mirror, mirror on the x axis, and it will create that rule for us. But we won't be needing that because our assets are rich and they have everything in them. So now I'm going to create a set of rules that's simply believed that one because we needed, I'm going to create a set of rules. And before I do that, I'm going to issue you a challenge and your challenge is going to set up your own rules. Because may I believe even that you can create battled rules than me for the background. So first thing is imported to the extras file I've provided in the resources. Then you have to set up your rules for automatic tiling and use the rules to paint your own platform. So go ahead and try your best. And if you feel that you can't even come up with the simplest rules I have provided in the resources. Also, the rules I've screenshotted everything beforehand, so I'll see you in a bit. Okay. Welcome back. So how did you get on with that? I hope you at least tried to create some rules. So let's show you, let me show you what I've done. So I've created, I think it's about 17 rules. And the way I did them, I actually started looking at different ways that each tile might work and how it should be positioned. Of course, if you don't have any idea how to create the rules, I've provided Jews some pictures and, or screenshots that I've made so you can copy them and use my tiles. But remember, mine are not perfect by any means. And I left out a lot of tiles because it's a very exhaustive list. I want to create an example for you to create your own rules. It will not be easy, it will not be done in ten minutes. I think this actually took me me I think about two maybe 2.5 hours to finish all of them and test them and make sure all of them work. So to demonstrate how the automatic tiling works, let's go ahead and choose to erase a couple of them. So as you can see, when we erase them, new tiles are created to wrap around. And as you can see, we have a mistake right here. And then there might be a lot of other mistakes, but some of them worked like this one, for example, works perfectly fine. So let's go ahead and delete all of these and lead all of these. And let's try them out in our platform and see how they work. So let's go ahead and click on this, choose the automatic tiles. And let's remember to always have it on background. So let's create something right here, and then we'll create something right here. And as you can see, they fill up automatically. And it's perfect, I guess let's see if, oh, there's something right here. I think we need to create another rule for that. I believe it's the one where you have only two on each side. So let's see. Okay, so let's go ahead and create a new rule and let's see which one we should use. So we want to cover, we want to cover this area right here at the top and one over here. So we'll choose which one, which one, okay, this one. So let's drag it in here. As you can see, it fills up automatically, but that's not what we want. We want to actually create a rule for it to always follow, because that will always default to us. So it doesn't have a tile to its upper left. It doesn't have a tied to its bottom right. And it has tiles to both sides and vows to above it and below it and on either side. Excellent. So now you can see that we have our rule setup right here. We can automatically tile all the background. It makes our platform much more static than having all of them the same. You can create gate, also a rule for your foreground tiles. I tried it. It's meticulous, takes time, and I encourage you to try and create that also, it will make your life 20 times easier. I hope you enjoyed the video. I hope you're excited as I am about this in the next video, I think will be finally adding our player or a conqueror us, call us, we'll be calling him our conqueror. So I'll see you in the next video. 20. Adding Our First Animations: Welcome back, my fellow game developers. As you can see, we've created, finally, we've created a player and display or is our conqueror, we'll call him Ginny. So Jimmy right now doesn't do anything. But if we click on play, we can see that our jimmy conqueror actually has an idling animation that's running right here below. I'll teach you everything that we've done. You will have a big challenge. So I want you to give me your entire concentration force and I'll see you in a bit. Okay, so first thing we are going to do is we're going to undock this and we're going to delete all the unnecessary things we have up here. So let's go ahead and delete all of that. Zoom back in and go to Arlen Specter, saved that. Then let's go and create an empty game object and make the smaller within dont needed that big. Click on that to remove a little bit bigger and we'll call this game object our layer. And this layer will be reset to the middle of our screen. And honestly, this is the most exciting part of all game creation when you start making your player. So let's go over some technical words. Animation 101 first, first thing you need to learn as an animator controller. So an animator controller allows you to arrange and maintain a set of animation clips. You'll see what that is enabled. And Animator component used to assign animation to end game objects in your scene. So if you have a game object and you wanted to have animations, you assign it an Animator component, and that animator, animator component gets an animator controller. It's a bit confusing. We'll see everything. Animations at several sprites rendered one after the other. So it say set of sprites one after the other, we put them next. Just like video works where it's a set of images one after the other. And finally a sprite renderer we've talked about previously, renders a sprite for 2D graphics. Okay, grew Rick. So back to Unity. And from unity we are going to be importing the sprite. I've left you and their resources for our human. So let's go ahead and go there. And here you can find that we have fall idle, jump and run. So we'll use for now idle animation. But in order to create the other animations we have the Ron and all jump. So click on the idle and drag it into our unity. So we have it right here. I'll actually, we don't want, we wanted inside of sprites. So let's close that and now let's create a folder. First for our. Conqueror, who call this conqueror. And our conqueror will have this sprite. First thing we're going to do is we're going to be slicing up our conqueror. But before we do that, I want to, to understand the steps that we are coming to take. So we're going to import the concordance spreadsheet and slice them up. We're going to create the player object. We've already done that and add a sprite renderer to it. We'll do that right now. We're create will create an idle animation. We'll add an animator to our player, will create a player animator and ordered to add all the animations to it, will add an idle animation to the Animator, and we'll assign the animator to our player. So let's go ahead and do all of those things. First thing, let's slice up our. So we'll go to multiple will make the pixels per units 32, and we'll apply all of that will go into our sprite editor. So as you can see here, we have 1234567891011 Sprites, and they are spread over 800. Here below you can see it eight hundred and fifty, eight hundred fifty eight. If you do automatic slicing, you can see that it does the job pretty well. But the problem is that when we'll be adding other animations to our conqueror will have a slight problem with that. That's why I'm going to slice it up in a manual way. And it's going to be 58 by 58. We sliced that up. And as you can see, it's not very accurate. Why is that? Because we want to have some kind of offset. Why we need that offset? Well, because 50 by 58 just doesn't cut it. And we're going to pad let's do a padding of I mean an offset of 20. Nope, I meant padding, so padding of 20. And now we can see that they are all in the middle of, the most important thing is to have our conqueror and site in the middle of the sprite. So all of them are in the middle. And Oh, okay, great. So slice that up, apply everything you can. As always, I've told you you can rename them if you want to go down the throat. So we've sliced up our sprites. Now it's time to add our renderer. The way we do that is we'll move this here and we'll add a component. And it's going to be a sprite renderer. And, and our sprite render, we have this default sprite. Choose anyone you'd like and put it inside of it. And we have our layer, a girl rate. So now what we need to do is we'll need to add an animator to that player, or actually an Animator component that we've talked about. So let's do that. Simply type in and he may talk. Now we have an animator controller and this object can now begin to have animations back into assets. Let's create a folder. We'll call this folder. And animations. And inside of animations, we are going to create an animator, so animator controller. And we'll call this the player. Now, let's get back who act should we do right now? Okay, so next step is going to be, we're going to open up our window for an animation. So go into animation and click on the Animator window, animations animator. And we have the animator, but we are going to docket in a different way. Feel free to dock it however you want. This is my personal style, so I'll dock the project and console next to each other. And I will dock the animator weight of what, and I'll dock the animator right here below K. You need to do a couple of restructuring right here. Just like that, and it's perfect. So this is our animator right here below our scene. And we'll add also a window for the animations. So animations and will dock it next to the animator. Just like that. Okay, great. Next thing we're going to do is we're going to create an animation and we'll be adding it to our animator. So as you can see, we already have a couple of states. These are called states. This is the entry state, This is from any state, and this one right here is an exit state. So let's create an animation best part of our game. So go back to sprites conqueror. And the way we create animations is we choose all the sprites that we want. So as I've told you before, click on the first one, go to the last one, hold Shift, Click on them, you've chosen all of them, right-click on it and go to Create, and go down into animation. So this will create an animation. We'll call this idling. Idling. Okay, great. Now we have an animation of idling for our player. Simply drag that into animation. And inside of animation, we have to now add this idling animation, 2D animator. So we do that by simply click on, Click on the widening and drag it into the animator. And now we have an idling animation for our player. One thing we also have to make sure of is we click on animation and add a loop time because of we don't. He'll do this animation once and then stop. I blink is an animation that we want to have over and over and over and over. So click on that. Save all of this, and don't forget to go to player. And in the animator controller, it will ask you for a controller. You can either drag this here or you can click on the little circle and add the player animator. Save that. And now let's click on play and see what we've done or anything works at all. So if we go back to seeing, we can see that our player moves and he is idling woo, woo, Oh, okay, great. Very exciting. It is very exciting, but there is a problem. If we take our player right now and drag them into our platform, we cannot see anything. So where is he? What's the problem? The problem as well? It's actually your problem because see what I did there. I actually changed the everything the steps into I challenge because maybe you're just watching and not doing anything too. So this is your chance to do the challenge. So your challenge is to do all of the things that we've done already. You can re-watch it. Maybe you already doing everything with me and pausing the video. But if you're not, now's the time. And your extra challenge is to use the sorting layers to make our player visible in front of the background. So we've covered sorting layers before. I think you have enough skill to do all of them. And I'll see you in a bit. Welcome back. I hope you did your best and that challenge, I hope you just stare at the screen. So we'll choose player will go into sprite renderer. And we see here that we have the sorting layer just as we had for the foreground and background. So if we click on Default, we don't have a player and we can add a sorting layer. So let's go ahead and do that. So a new layer, we'll call this deep layer, Layer. Layer, Layer. That's fun to say. And we'll put it in front of background and behind foreground, Even though he will not be going over the foreground or behind it. But we'll render it that way. Save all of that back to Player, and choose the sorting layer to be the player. So now our player, our player is on the player layer, say that ten times. And now I, actually, I think that our player is just a little bit sits mall, I think will make him bigger. So let's go into sprites. And the way we do that, we choose the conquerors, playwrights, and we'll make this 30. So if we make this 13, Click on Apply, he becomes just a little bit bigger, just so he can be seen. But and if this camera logo and here is bothering you, it's bothering me. You can actually click up here on the gizmos and you can make all the icons is smaller. You can even make them disappear. Okay, great. So I hope you get on with that challenge. I hope you are excited as I am because our player is actually moving and we have breathe some life into our game. I'll see you in the next one. This is Michelle from the future. Sorry to interrupt. But I want you to do something that we haven't been doing so far. And that is committing our changes. Maybe you've been doing that and I congratulate you. But if you're not, this is a great time to start touring. So as you can see, I've been doing it each video. So slicing up sheets, creating pallets, created a platform and the tools. And now we're going to add the animation. So we'll commit that change and adding an animation or adding idling animations. So if you haven't been doing the repos right here, this is a great time to start because we are going to be doing a lot of things in the upcoming videos. So I'll see you. 21. Animation Transitions: Welcome back my fellow game developers to a brand new video. And this one is very exciting because we're going to be learning about nother, other animations and even more transitions. So as you can see here in our animator, we've added two new states which are climbing and running. And we've added transitions between them with also added parameters that will allow us to make those transitions. And now, if we click on play, we can actually take our player from the ironing animation into the running animation. And we also a climbing animation from what we have. So I'm very excited for this video. I hope so. I hope you are too. So let's get into it. First thing we'll do is we'll go and add the sprites for running and the client. So for the running, we have this runs sprites and 40 climbing. I am going to use the fall and the jump because we don't have the actual climbing animations, but I wanted to include that in our project. So go ahead, click on all of those and drag them into our unity. So we have jump, we have the, either the Iran and default. For now let's just focus on the running. So as you know, this is a step that we've done multiple times. Let's go ahead and click on run. Make it multiple, make the pixel size 30. Because as you remember, we've increased sizable. Save that. And yes, I meant to apply, go back to R1 and for some reason, okay, so going to Sprite Editor, and we have those sprites, it's go to grid by cell size. It should be 58 by 58 with a padding of 20, as I remember, yes, exactly. Okay, so apply that. Now we have our sprites. Let's go ahead and click on all of them as we did before. Check all of them. Right-click. Go to create animation. And we'll call this running chronic, great clothes that take running into animations. And later on, we'll create a folder. So now let's add the running animation state to our, an animator at running right there. So now this is a bit tricky, but let's zoom in, move that exit, exit to overhear. And now we have the idling and the running next to each other. So how are we going to tell our animator that we want to transition from the idling into the running. Well, if you right-click on idling, you can actually make a transition. So make that transition and push the arrow and to the right. And if you click on that transition, as you can see, we have lots of options and lots of settings also. So let me tell you just a bit here. Let's talk about transitions. We have a bit of blending here between the animations, but we don't want that to, as you can see, we have this blending right about here and we can actually. Remove all that blending. So it goes immediately from idling to run. And we'll do that because we already have very good to the animations. So we can simply go into Transition Duration and put it to 0. That way there will be no lag between animations. So now we have the idling going to running. But how is it going to know that we actually want to go down that road? Well, we do that using the parameters here on the left. So go from layers into parameters. As you can see, we have an empty list. So here is where we start adding parameters and we can add and a couple of parameters. We can add a float and an integer, a Boolean or a trigger. For now we'll be using a boolean and that boolean will be called running. So we want to transition into running. We'll need to use the running Boolean. And in order to add it under the, if we click back on transitions, we have the conditions right here. And this condition, this is empty. So click on plus an atom. It automatically adds the running because we don't have anything else to add. And now if we click on play, we can see that we are right now idling. And if we click on this Boolean, we go into the running, but it does, does it only once? Why is that? I will give you a mini challenge right now to figure it out. Okay, enough. So let's see, running should be in a loop. Save that back into play. And now if we click on the boolean, he starts running and he keeps running forever. Why is that? We want to make this butter. So we'll add a transition back from running to eye-opening. And this transition will also have a duration of 0. It's conditioned right here will be running, but when it's turned to false, save that again. Click on play. And now our player as ironing. And now he's running and now he's not running and now he's running. And now he's not running. Okay, so this is very cool. This is a very exciting and this is a great time for your challenge Soviet challenges to create the climbing animation TO important declining sprites from resources. Slice them up, and size them appropriately. Create a transition from idling and to running. And finally create a trigger 40 transition. So pause the video right now, i given, I've given you all the steps that you need. I want you to try your best. So I'll see you in a bit. Welcome back. So how did you get on with that? Let's go ahead and do the challenge. So first thing we'll do is we'll go into our Congress sprite. And as I've told you, will be using the fall and the jump animation in order to create our animation. So this will be a bit tricky. And now we'll go to our fall. So our false should be. Thirty-two, and we'll make it multiple even though we don't need to do that. But because we are going to slice syrup our way. So what's 58 by 58 apply? We only have one sprite, and in here also we have only one sprite. So apply that. Don't forget to make it 30, not 3416 sliced up, apply. Correct. So now we are ready to use these two. So let's click on those, right-click and create an animation, and we'll call this lining. So climbing animation back into our animation folder, and we'll add it into our animator, will create a transition from either link to climbing. And they transitioned from climbing to idling will also turn off of the transition duration on both of them. And we'll create a new parameter, which will be a Boolean. And we'll call this climbing. Climbing. And now we'll add this condition to from idling to climbing. The climbing should be true, and from climbing to idling, the climbing should be false. Save that. Click on play to we put it into loop. I'm not sure. Let's try it. So climbing and it stops because we haven't put it into looping, save that again. And now, if we click on climbing, he starts climbing, but as you can see, it's kind of super-fast. So let's go ahead and play around with our animation. How do we do that? So we have an animation tabloid here that we haven't used them yet. So from animator to animation, and as you can see here, we have this climbing. If we click on player up in the hierarchy, we have the widening, We have the running, and we have the climbing. If you click on any one of those, for example, idling, you can see that it tells us which things change during the animation. For example, here the thing that is changing is the sprite. So we can actually take it frame by frame or play it right here. And we can see that our player moves with the idling. And you can see every single frame. And you can go forward and backwards, make it smaller, make it bigger. So we'll use that for the climbing. Why is the cost? As you saw, the climbing is extremely fast and we want to slow it down just a little bit. So how are we going to do that? Well, goes from here to here, so we'll add another one. So copy that. Click on Control C. Go to the frame where you want to put this sprite and Control V. Ok, so now we have these two. Well actually let's choose both of these. Control-c, Control-V. And then again source three times. Let's make it 1 second. Okay, let's see how that works. Click on play. It's a bit first still. But at least he does it multiple times. And we can actually, let's take them apart if we choose all of these, and that's what let's delete the last two and choose all of these. And we actually can spread them out over a second. And now if we click on play, will be a little bit, something goes wrong, right? Why is that? Because the last frame, well, actually they're not spread out correctly, so let's spread them out correctly. So this is on for 68 on the one. And the last frame should be the same as the first frame. So let's put in that one. And now if we click on Play, it should be very, very small. So a final step before we go, I want to go into player. I want to go into the animator actually, and I want to remove the exit time. As you can see, we have something in here that's called exit time. And this is used when you want to transition back into the previous animation or go into the next animation after a certain time. And we don't want this right now, will be using it in the future. Go into every single transition and remove the exit time. And we are done. So let's save that. Let's click on play and see what we have. So we have our player idling. And if we click on running, he starts running and we amplicon of running, he stops and he also climbs. How cool is that? Seriously, this is the coolest part. And I hope you enjoyed the video. I hope you learned a lot. And don't forget to save and the repo. And I'll see you in the next video. 22. Adding 2D Collisions: Welcome back, everyone. Just wanted to remind you of the amazing job you've been doing so far. In this video, we'll be adding a rigid body and a collider to our player, will also be adding collisions to our environment, as you can see here, that will make or unable our player to land on the surface of our foreground. So now if we click on play, our player actually stands on the surface. So let's get started. Okay, so let's start off by adding a rigid body to our player. But before we do that, I think it's a great time for us too. Prefab out player. So do that, let's go into our assets. Right-click and create a folder, and we'll name this folder prefabs. Let's go ahead and prefab our layer. So now we have a player prefab, which feels good. So back to our player. Let's go ahead and add a Rigid Body to our layer. So Rigid Body 2D. And we'll make sure that we have it as dynamic, save that, and apply it to our preferred. The way we do that as we go to overwrite, click on down and there will be an apply o. Okay, great. Before we continue, I wanted to take a second and talk about rigid bodies to the one more time. So it's a component added to a game object that subjects it. Two should not be TPI, it should be to physics, engine forces. And we have many body types of Rigid Body 2D. So we have dynamic, which has finite mass and is affected by gravity and other forces. We have kinematic that isn't affected by gravity and other forces. And we have static which behaves like an immovable object. Oh, okay, great. Now back into Unity. And because we have a rigid body, now, if we click on play, our player falls through the ground. O k. Not very helpful, but it's a step forward. So now it's time for your challenge. It's important of an early challenge, but I think you have covered. So we've talked about collisions before. So now it's time to add the appropriate collider to your player. You need to add a collision to the environment. And you have to make sure that your player lands on platform without falling through. So pause the video right now if you feel that you have skills to do that, F naught, wait a couple of seconds and I'll be right with you. Oh, okay, so colliders, they are very helpful. So go into player. Let's close down this rigid body. And let's go ahead and add a collider. So I think we'll be adding a Box Collider 2D to our player. And as you can see, our play or our box collider is a bit too big for our player. So we'll go ahead and shrink it down. And You can do this however you want. It depends on your preference to the gain, how much you want to make the Foxconn life big or small. But what you need to keep in mind is that his feet should be touching the bottom of the collider. So let's make it this big. And this is simply based on your preferences. I like to keep it just smaller than his actual size to make the game a little bit fair. So if you make the box collider bigger, that will make the game a little bit more difficult. And if you make it smaller, it will make it easier for your players. So I think this is good enough. So save that and as always, go to override and apply it to the prefab. So now if we click on play, our player still falls through. Why is that? Well, because we don't have any colliders on our foreground. So let's go and add some go into foreground. And if you got to this point and couldn't continue, don't worry about it because this is something you will be adding a tile map called lighter. So let's go into pile map. And as you can see, all of the foreground tiles have been, have now a collider on them. But the problem is that if you zoom in, you can see or you can't. But if you zoom I a lot, you can see that there is a tiny, tiny, tiny gap between the colliders. And believe it or not, this will cause problems for us later on, especially if the player is moving or dropping down active very fast velocity, he can go through these colliders. So how are we going to fix that? Well, there is a small solution that is called a composite collider to the, so let's see what that does. So Composite collider to the, when we add that, it automatically adds a rigid body to our foreground. And what this does, it actually lets close this. And if we click here, if we look into our tile map collider, we can see that we have a checkbox that is called used by composite. And what this does if we click on it, you can see that all of the colliders are now on a single collider, but we can see it. Let's make this bigger. Okay, so now you can see that we have a single line of collision to our foreground. So now if we save that, oh, and there is one more problem. Well, you should have thought of it. Maybe you didn't. That's okay. I've invested a lot of times because we have a rigid body on her foreground. If we keep it on dynamic, all over the world will be falling down. So we need to change this dynamic into static. That way it stays in its place, whatever happens, so save that they can play. And now our player spends on our foreground. Now the game is becoming more and more realistic. So this is great. This is a very big leap forward. But there is one other problem, because if we click on our player and we sat him here on the edge and click on play. We can see that he actually falls on his head. And now the animation is plates. Well, it is kind of cool, you know, but we don't want that. So in order to avoid this type of behavior from our player, we can actually go into our not rigid body, excuse me. We can go into our, into our rigid body. And down here we can see that we have something called constraints. So this constraints the movement of our player on certain rotations, for certain rotations. So what we want is to freeze the rotation on the z axis. If you look here at the top of the transport, if we use the z rotation, R player rotates. So this is the one that will be freezing. Okay, great. Is it's still pleased. We needed to override apply all. And now let's close that. Why is it telling me that I need to change my collider or cake layer can play, and now our player stands using his hammer. It's not very realistic, but it's a 2D platformer and it's OK. We don't need it to be very realistic. So I hope you enjoyed the video. I hope you try to do the challenge and I'll see you in the next one. 23. Section 4: Moving Our Conqueror Horizontally: Welcome back to another video and start of a new chapter in our game development journey. In this video, we are going to start moving. Our player based on keyboard input will be using the same formula as we did for the previous project or for the magic Game Cube, but with a different twist to it that we'll see in a bit. So as you can see, we press the right arrow, he moves right. We pass on the left arrow, he moves left. And I'll see you in a. Okay, so as the title suggests, we want to manipulate our game object's behavior. So what does that need? Well, that needs a is correct and that means coding, which is very exciting and a bit scary. So let's go ahead and add a script to our layer, whereas our player, we already have him. So let's go to Add Component and create a script that we will call simply player. Down here we have news corrupt and will create and add a script. Wait for it to understand what is happening. And okay, so let's start by creating a folder. One of my personal favorite things to do, apparently so scripts, scripts, and we'll add the layer into our scripts. Great, let's double-click on that. And let's wait for Visual Studio to open up and understand everything. Okay, so I wanted to initially do that, initially drew the challenge later on, but I think I'll do it just now. So if you are ready, you can take the initiative and move your layer. First thing you do is import a cross plot for platform input as it package that I've provided you and the resources. Then you create a run method that is called from inside of update. And then inside of Ron use the rigid body to move the player. And finally, add a variable to control our speed. So it's a bit of a daunting task. If you think you have enough skills, do it, go ahead and pause the video and try it. If not, and you think it's too big of a mountain to climb, Wait for me, I will do it in front of you. And one more thing if at any point you feel that you can continue it alone, I recommend that you pause the video and you do it. So I'll see you in, just tape it. Okay, welcome back. So maybe you've tried to add the cross-platform input from the resources I've provided you. But you can also go into Unity's Asset Store and search for standard assets, which has the cross-platform input inside. What is cross platform input? Well, it's something that we'll be using instead of input. And it literally does what it says. What named this? Well, it's cross-platform input. That means it's across multiple platforms. So this game that we are creating right now could be on a Computer on a PC, or maybe it can be on a PlayStation five that's coming out recently. But of course, like this isn't going to be a PlayStation five games, but who knows? Maybe you could create a PlayStation five from this simple graphics. Anyways, let's go ahead and import the cross-platform package. So simply go into the resources and drag the cross-platform package into our assets to, I'll ask you to, do you want to import all of these? Simply click, oh, what is this? Okay, don't worry about that. We've already imported that and what we do need as the standard assets. So go ahead, look for cross-platform. Click on that and now simply click on import. Only need the cross-platform assets. And if you've downloaded the standard assets from the internet, also only choose the cross platform. There's no bad thing to do well if you import everything, but for now we just need the cross-platform. So wait for that to import. And now we should have a folder that's called cross-platform folder. And let's go ahead and add the 2D extras, which is under the File 7.15 whatever, into our standard asset to make everything but more cohesive. As I'd like to say, save that. Let's go back into Visual Studio. And because there is a file modification detected, it will ask you for a reload. Simply reload. Reload again. It shouldn't do it anymore. Everything is fine. Okay, so first thing we are going to do, we'll be adding a using cross-platform. That means at the top here. And I'm not sure I've explained this enough. These are the libraries that we are using. For example, the Unity engine is the library for the start and the update and all other Unity related things that we use an R script. So now we have to import the cross-platform library and we do that by typing using Unity standard assets dot cross platform inputs. So now we have access to the cross platform input. Next thing we're going to do is we're going to create a run method. This would be a private method. It will not return anything. That means it's a void and it will be called run. And what should we do inside of run? Well, we're going to use the get-x method and get the horizontal. So, well, first thing we're going to do is we're going to put it inside of a variable. So it's going to be a float. It's going to be, let's call this. Control throw. And it's going to be u using instead of input will use cross platform input manager, I'd say big word, but it's what we use instead of input. It's going to use dot get axis. Now, inside of get axis will need string name for our inputs. And where will we get that? Well, let's go back and to unity here. And if we go to edit and we look for project settings, we can see that we have our Input Manager that opens up. And if you don't have it opened up, simply click on Input Manager. So this is where we have our project settings. There are a lot of things in here. We don't need to go over all of them. So for example, we have physics 2D, which we'll be using very soon. But for now, let's focus on input manager. We have this axis here. And if we click on that, we can see that we have a lot of options. So, and one of them is the horizontal. Horizontal as when we click on the a or the, and this is exactly what we need. So because and here they get access needs a string reference. Well, go back and to the input manager. And every time we have a string reference, we always go and copy it. We never assumed that we've written it correctly because we never do and we cannot find the error. So we have a control throw. And why did we use a float variable to catch this important? Because I will demonstrate it. So if we click here print and we'll control throw, let's print that out and see what happens. And that's not forgot to call it in the update method. So save that back into Unity. That's dark this here next to our tile palette. And that's, I think is a good place. And now if we click on the play and we click on the left, on the left arrow, you can see that it slows the goes from 0 to minus one and then back to almost 0. And if we click on the right arrow, it goes from 0 slowly to one. And that's why we need to save it inside of a variable to always have control over. So now that we have at, let's delete this print right here. It was only to demonstrate how this works. Next thing we're going to do is we're going to create a player velocity of vector type two. So we'll do that by first getting the rigid body. So let's create a variable right here that is the rigid body. So it's a rigid body 2D, we'll call it my Rigid Body 2D. And previously we've used, we call this a public variable and we've added from the Inspector. But now I'm going to teach you a much better and maybe more efficient way to do that and coat. The way we're going to do that is in start, we are going to call our variable. And we are going to assign to it the rigid body that is currently sitting on our player game object. So we'll use get component, which gets a certain component. And that component is, well, it's a rigid body to d. And that is how it's written. Now we have a reference to our rigid body, to the, let's go ahead and change it and run. So we'll click on here. It's my Rigid Body 2D. But before that, create a variable for our place velocity. And that variable is going to be a vector two. We'll call this player velocity. Velocity. And display or velocity will be equal to a new vector two. And we'll move, we are moving in the horizontal axis. So we will only be changing the velocity in the x or horizontal direction. So this will add the controls throw to the x axis and 240 y will simply keep it as my rigid body dot velocity dot y. So in the y direction, the velocity will not change. And finally, we'll assign the my Rigid Body 2D dot velocity will be equal to the player velocity that we've currently created. So save that. Let's go back into Unity and see if we did anything correctly. So click on here, are player falls. If you move left, he slowly moves to the left. And if we move right, he also slowly, very slowly moves to the right. O k. Excellent. As you've seen, he moves very slowly and we'll need to fix that. And in order to do that, we are going to create here a variable for the Ron speed. So let's go ahead and create something we call a serialized field who very scary. Some fancy words you using Michel. Don't worry, I'll explain what that is. And serialized field is just like public, where we can change the variable from our Inspector. But the only difference is that we can actually manipulate that variable from a different script. Okay, so we use public functions to change, to use functions from different scripts, we can actually use serialized field to change variables. And I don't think we'll be using it too much, but let's say, for example, you want to change your player speed, for example, depending on the platform you're standing on, you can go ahead and do that using the serialized field. Ok, small explanation. Let's continue. We're going to make this run speed a float, and we'll call this simply around speed. And what should the strand speed B. We can actually do something. Let's try ten. And we are going to multiply it with the controls row right here. So R1 speed, not Trump, actually ran Speed. And now, if we go back into Unity and click on inspector and click on player, now we can see that we have a rents run speed of ten. So we go into play mode. We can move now with a speed of ten and we can actually increase this to 100 C. What happens? And our player, what did you see that you see what just happened? Do you see how our player disappeared? But actually you can still see him right here in the bottom left corner. Don't worry about that. We'll see a couple of more instances of this, but we'll be fixing it later on in the other videos, so I hope you enjoy it. This is the part where our player comes to life and we start manipulating him using code and everything is fun. Everything is very cool. I hope you enjoy it and I'll see you in the next video. 24. Flipping Our Players Sprite: Welcome back everyone. Our player now moves in the game. But the problem is that he does a moon walk. So whenever we are moving backwards, he does not flip p simply does a moon walk. And we don't want that. In this video, we are going to be flipping out players or if we click on play, we can see that whenever we move to the right, we move right. But when we start moving to the left, we actually flip our player. And now he moves into direction and actually looks in the direction he's moving, the correct one. So very exciting. Let's not waste any time and let's jump in and get started. Okay, so how are we going to flip out layer in the direction that he is moving? First thing we're going to do is we're going to apply all of our changes to the prefab. So if we look closely at our player, we can see that he moves left and right, but he does not flip. How are we going to go about this? If you go up into our transform, you can see that we have position, rotation and scale. So scale, if we increase the scale of our player in the x-direction, you can see that he gets bigger and bigger and flatter and flatter. But if we reduce it 2.30, He gets smaller. But what happens if we go beyond the 0? If you go to minus territory, we can see that our player flips. So at minus1, our player is facing the other direction. And this is what we are going to be doing. But in our code, depending on the direction our player is heading in. And we'll do that using math, but not very hard math. If you don't like math, it will be simple math. Oh, okay, so now let's go into our Visual Studio and let's go ahead and create a function that we'll call private void. Philip, sprite, script, sprite. So we have flips bright and we are ready to go. So flips right? Before we started, I need to explain two concepts. First of all, math dot apps. So I hope you remember from school what absolute value means. It means it returns the absolute value of something. So for example, if we have math dot abs minus four, it returns four and math dot sine. So what is not signed? It returns the sign of a certain number. That means if we have math sine minus four, we have minus one as a result. And if we have metal signs for, we have plus one as a result. So this is a quick overview of overview of first grade math or something like that. Let's go back and let's go ahead and create a Boolean. So go into Visual Studio. So n this, we are going to create a boolean which will tell us if our player is actually moving. So let's go ahead and create a board which will be running hoary, long, running horizontally. But sure if horizontally takes two hours or just one, or actually hurries on the a is not in the right place or K. So horizontally equals math dot absolute value, my rigid body to the dot velocity dot x. Now you might be wondering why are we even using the absolute value of our rigid bodies velocity? Well, because we are moving in the left direction, our velocity is negative. And we are, when we are moving in the right direction of our velocity is positive. So we need to take the absolute value to make sure that we always know when our player is moving. And to make this Boolean, because right now it's not boolean. We're going to check if it's bigger than, wait for it. Math, f dot epsilon o k. Now, again, Michelle, earlier using very scary words. What is math dot epsilon. So first of all, when we type math.pi f, that means we are accessing the library of math where we have a lot of functions and a lot of methods, tools. And epsilon is not a method nor is it an function. It's a, a small number, a very, very, very small number, like say for 04 or five zeros after it and one. So why are we using math.pi epsilon y not simply compared with velocity equals 0? If you remember in the previous video when we tried to print the control throw, you can remember whenever we went to the left, it's slowly moved from 0 to minus one. And then it went back to minus 0.00009. It never went back to absolute 0. That's why we're using math f dot epsilon instead of simply using 0. Next thing we're going to do is we're going to use an if condition. So if running horizontally and inside this if condition, I'm going to issue you a challenge. Your challenge is to complete the if statement. So we are going to flip our Player sprite based on the direction they are moving. And let's, I'll give you a couple of hands. One will use Transform dot local scale, and that's how you access the scale of a game object. And you will be using, use math F dot sine to determine the direction in which our player is moving. So pause the video right now, give it your full concentration, your full thinking ability, and do the challenge. I'll see you in a bit. Okay, welcome back. So what should we write inside of our if condition? So its transform? Because we need access to AAC transforms local scale. And this local scale in fact, is a vector too, because it's 2D. So we'll be using the scale on the x and y. So send new vector two. And what should be right for the x and the Y scale should stay the same. That means it's going to be one F uppercase. But what should the XP, while the X will be depending the pendant on the direction. So we're going to write meth F dot sine because it depends on the sign of the direction. And what direction is that? It's not my rigid body dot velocity dot x. So now save that. So now if our player is moving to the right, the velocity will be positive, the sign will be positive, our scale will stay one. But if the players velocities to the left, that means the velocity is negative. That means the sign is minus1, and that means that our local scale, x will be minus one. So let's see if that works. Save that and a small mini challenge I'm going to give you right now. Where do we actually use this flip sprite? Where should we put it inside of our code to flip our player? I'll give you a second to think about it. One Mississippi, two, Mississippi, three, Mississippi. Ok, time's up. It's inside of R1 because we're only be using the flip sprite whenever we are. Product. Save that, go back into Unity. Let's move out of the camera. Click on play. And now if we move right, move right. If we click on the left arrow, we actually flip. And how cool is that? Oh, okay, great. So I hope you enjoyed the video. I hope you did the challenge and I'll see you in the next one. 25. How To Trigger Animations From Code: Welcome back everyone to a brand new video. And this video we are going to be changing our players state from our code. So as you can see right now, we have our player in the idling, idling state as soon as we start the game. And if we move him left or right, you can see that his state changes into running. And if we stop, he changes back into the idling state. So let's not waste any more time and let's get started. Okay, so let's start off first of all, by re-explaining what is happening in our animator. First off, we'll make it a bit bigger and zoom. And so first thing we'll need to take notes off is here in entry. From entry we have a transition directly into idling. And what this means is that as soon as our game starts, we go directly into the idling animation. And from there we have two options or two states to go to. We have the running state and we have the climbing state, and both have transition to and from. So for example, to go from idling into climbing, we can see that we have this white arrow line that has a condition on it. And that condition is for a Boolean to be a Boolean called the climbing to be true. And in order to go back from the Comte climbing state or animation, this climbing, a condition needs to be false. And the same holds true for running. So the transition from idling into running needs for a certain boolean to be true and to go back from the running state, we need a certain variable or parameter which is running to be false. So how are we going to do that using our code? Well, first of all, because the parameters are present on our animator, what we need to do is get a reference to our enemies. So let's go into Visual Studio and tried to do just that. So here we are in our Visual Studio. First thing we'll need is a reference to our animator. And we'll do that the same way we've done to get a reference to our rigid body. So let's go ahead and create a variable for our enemies. So we'll create an NA metal. And he may talk please. So an animator will call this my animator. And we'll use the get component to get a reference to our animator. So get component animator and close that up. Save that. Great. So now we have a referenced our enemies. Next thing we'll need to do. First, we'll be focusing on the running. So how will we change from a idling, whereas that, so from idling into running, how are we going to change that? Well, we'll have to set the boolean because we know that it is a boolean. Let's go back and n running. When we. Start to run. Let's go ahead and go into the running state. So we'll do that by using my animator, which is our reference dot. And it has multiple methods attached to it. And one of them is the set Bool, and this allows us to send it a reference. Actually, it has two ways of giving parameters. The second way is our way, which gives it a string and the boolean value that we wanted to have, the String reference name and the bool value which can be either true or false. So let's do that. First thing we'll need the string name. And because it's a string reference will simply go back into Unity, double-click and copy that reference. Because as we know, whenever we have a string reference, we always, always go and copy it. And now we need to set the value for it. And of course it's going to be true. Now this is not the final solution by any means, but this will demonstrate how the set pool in my animator works. So let's go back into Unity and see if that worked. If we click on play right here, our player goes into the running animation. It's good. It's not bad. At least we know it's working, but this is not how we wanted. We wanted to go back to idling whenever we stop the running state. So that is going to be your challenge. And your challenge is to stop the running animation. So you need to add to our run method a way to stop the running animation. And that means going back to the idling. So it should stay true while the player is running and false when the player stops. Use the code we've created when flipping the spot. So pause the video right now and go ahead and do the challenge. Okay, welcome back. So how did you get on with that? I hope it wasn't very hot or I hope it was at least a bit challenging. So let's see what we need to do. Well, because I've told you will need to use something from the flips bright method. We are going to check if our player is actually running. And we'll do that by simply copying the following line, which checks if our player has a velocity on the horizontal plane. So now we have a boolean for running horizontally. And what we can do, because this is actually a boolean and it's true whenever the player is running and false if the player is not running, we can directly set it right here and our animator. So liver replace that with no, sorry, I mean, running, running horizontally. And let's do one more step. And that is extracting this method, method and to an outside one because it's just a bit different. We'll call this changing to running state. And now we save all of that. We have a changing to running state which checks if our player is moving in the horizontal plane and if he is, that means our running horizontally is true. That means our animator sets the running to true. And if he's not running, this running horizontal will be false. And hence, our animator will suddenly be running to false. So let's go ahead and see if that worked. Click on play. Our player is initially in the idling animation or state. And now if we move to the left, he starts his running. If we stop, he stops and goes back into idling, go rate. So this is the foundation of controlling our animations from our code. We set up our state machine. We have parameters which we can access in our code. When a particular thing happens, we can manipulate those parameters using our code and changing the player state. I hope you enjoyed the video and I'll see you in the next one. 26. Adding The Ability To JUMP!: Welcome back, my favorite game developers. In this video, we are going to add the ability to or player two jumps. So as you can see, he can now reach platforms that were unattainable before. And he can jump from one platform to the other. And as you can see, it's very snappy, is very exciting and it's going to be very, very fun. So let's not waste any more time and let's jump in and gets k's. So first, I want to talk about the jumping mechanics and how they are. So the jumping mechanics will be a bit different than the running mechanics. Why is that? Well, because running is different than jumping. Because when we run we actually pick up speed slowly. But when we jump, we technically immediately have a velocity upwards. So I just want to show you how our velocity actually increments. So if we print the layer velocity to our console right now, let's go ahead and try that. As we start to run without player, you can see that it's 00 when we start running to the right at increments slowly from 0 to 9.79.8 and eventually to ten, then goes back to 0. And the same goes for when we click on the left arrow. But we don't want that our game. We actually want our players to immediately jump as soon as we press the space bar or whatever button we would like to be processed. And we'll do that using a different kind of function than the get access will be using the input dot get button. So if you read the description right here, you can see that it returns a true. So it's a Boolean, it returns a true during the flame, the user pressed down the virtual button identified as birth_name. Anyways, what you need to take out of this is that it immediately turns something into true and then back to false if we press a button, and that's what we're going to use. And of course instead of input will be using cross platform input manager. Because as we, as we said before, we want this to be a multi-platform game. And let's jump in and get started with it. So first thing we'll do is we'll remove this parent because it's done its job, it's finished service. And we're going to create a function or a method right here, which we'll call simply jump. And now if we save that, we have the option to extract. We have this little light bulb lightbulb on the left. Click on it and click on generate method. Don't worry about whatever is written already inside of it. It's a private void method just as we want. So what are we going to do? Well, first thing we're going to do is we're going to use a oil, create a boolean. Boolean is going to be called, is jumping and that is jumping is going to get an input from the cross platform input manager. And we'll use the function that we just described, the get button down. So let's open, they're open it up and we can see that it takes a string reference as an input. So let's go ahead and find the string reference of the jumping and put. We go into project settings that is docked here on the right. So click on that, make this a bit bigger. And let's scroll down and see where we have the jump. There it is. So it's Jump and it's positive button is space. So let's copy this because it's a string reference. And as we've said before, whenever we have a string reference, we always, always, always go and copy it. So now we have the is jumping Boolean set and ready. Next thing we need to do is we'll need to add velocity to our player in the y-direction. So let's go ahead and do that. So we'll create an if condition. And if is jumping. That means if our player has pressed the jumping button will create a vector. Two will name this jump velocity. And this jump velocity will be equal to a new vector two. And in the x-direction will only have my, I'm in my rigid body. So my Rigid Body 2D dot velocity dot x. And in the y direction, we will want to add a velocity, a speed for jumping. And this will be dependent on your preference. It could be five, could be ten, it could be 20. And whenever we have such a variable, when we have something that is variable, it's much better to create a variable for it, just as we did here below for the running speed. So let's go to the top and create a serialized field. And serialized field is something that we can adjust from different scripts. Maybe we won't need it right now, but let's just go ahead and make it a serialized field. So it say float, float, and we're going to call it jump speed. And initially let's go ahead and make it 1515 F because it's a float. So 15 F. And let's add it to our jump velocity. Okay, great. And as a final step, we need to add this velocity, jump, my rigid body dot velocity. Velocity is equal to our jump. Jump. Velocity. Oh, okay, great. So save that. Let's go back into Unity and see if that worked. Make this a bit smaller. Click on play. And now we move left and right. And if we press the space button, we can see that we jump. But that jump is a bit floaty as you can see, but at least say start. It's a huge leap forward in our game development. Surely get it, leap forward. Okay, i will not make that joke again. So let's see what we can do in order to make this game a bit more snappy. So we can see here that we have a physics 2D option and our project settings. And what this allows us to do is allows us to adjust the physics 2D of our Unity engine. And we have many, many options to adjust. We have maximum rotation speed, we have translation speed, we have angular corrections. We have a lot of stuff in here. I will leave a link in the resources to go check out the physics 2D in the unity documentation, you can go into every single detail that you want. But for now we're only interested in the gravity right here. As you can see, our gravity currently in the x direction is 0. In the y direction, it's minus 9.81, which is exactly the same gravity that we have here on our planet. So if we click on play and we jump, we can actually adjust this right here. So if we make it, for example, minus 27, now if we jump, we don't jump as high as we did before. So this is where we begin to tune our jump depending on how high and how snappy we want our game to be. And a small reminder whenever we finish adjusting something in our play mode, if we unclick from play, see that it goes back to its original value. So keep that in mind because you need to remember the value that you chose when you were in play mode. And that takes us right into our challenge and our challenge, or your challenge is to adjust your jumping. So June the gravity and jump speed to make jumping mechanic to your taste. And base your tuning on how many tiles you want your player to be able to jump. So you can either make it totals three tiles, you can make him the best and highest jumper and the entire world. It solely depends on your preference and how you want to make your gain feed. So, pause the video right now and go ahead and do the challenge. Okay, welcome back. I hope that wasn't too hard. I hope you enjoy that type of challenge. So let's click on play and see what our player does. So we move left and right and we'd jump. And that jump is a bit too. Nausea think. So let's make this gravity 100 and now it's a bit more snappy. And in order to help our player Champollion, let's click on player, go to its inspector and let's make the jump speed. I think 50. So let's see 50. Now our player jumps and you can see that he actually disappears below the platform, which is not good. And we face this problem before, as you can remember from, I think it was when we added the Iran speak to him. So we need to fix that before we continue. I don't know if you face this kind of problem while doing the challenge. I hope you didn't. And it's not very hard actually. If we go into our players rigid body, you can see right here that we have something called Collision Detection. And it's currently on discrete. And if we click on the list, we can see that we have another option which is continuous, and this is what we are going to choose for all player. Now what does that mean? Well, discreet is it checks for collisions every certain amount of time while continuous is, as it says, it's continuously checking for collisions every, I think microsecond or millisecond, I'm not sure, but discrete is, for example, every one or two seconds it checks for a collision. And the continuous checks constantly, constantly for collisions. Now why do we have the discrete option? Because we might not have a body that it's very fast or for example, a slow moving bird or something that will not need a continuous collision with things around it. But if we have something like our player, for example, right here that has a gravity that is 100. He falls right through our world. So we'll make it continuous. Continuous is a bit more heavy on the processor of unity, but it's okay, we can handle that, I'm sure. So click on apply, go back into projects. That's make this, let's make this gravity 200 because I think we need it to be 200. Let's make the jump speed 50. Save that, go back into play mode and see if that feels nice. It does feel nice. So let's see. I think it might need snapping to the ground. I think the gravity's perfect. Let's see if we want to make I think that's enough. I think 54 a jump speed is perfect. So I hope you tune that to your preference. You don't have to make it just like me. You can have it whatever we want. It's your game, it's your preferences and see you in the next video. 27. Tweaking Jumping Using IsTouchingLayers(): Welcome back everyone to a brand new video. And in this one, we are going to be fixing our jumping mechanics. So as you remember, maybe in the previous video, whenever we try to jump without player, we could double jump and triple jump and jump into infinity. But in this video we are fixing all of that. And now our player only jumps when he's touching the foreground. So if we tried to jump multiple times, we can only do with once. And that is more realistic, that is more favorable. And I'll see you in a bit. Okay, so what we want is we want our players to jump only when we're touching the foreground. So fright. Now, if we use our player, we can jump multiple times, which is not good. We want only to be able to jump whenever we are touching the foreground. And we'll do that using layers. So if we go into our foreground, we can actually see that we have layer right here in the default, and actually everything is currently in default, but we will be changing that. So first thing we'll do is we go into the layer, click on here, and you can see that we have this add layer right here. When we click on that, we have the option to add a lot of layers. So first thing we'll do is we'll create a layer and we'll call it ground. And now we have a ground layer. Now what's the difference between a layer, a sorting layer and layer and tax. Well, layers are used whenever we have multiple types of, let's say collisions when we want to control what collides with another thing and how the physics of different objects interact with you travel. A sorting layer is used for rendering things based on what sorting layer they are on. So if you want, for example, we've used the sorting layer to render the background behind the foreground and behind the player. And finally, tags are just an extra step of organization. Four layers, they are used in the code. If we have, let's say the player may be, may have, a layer, will have a layer for the player of course. And if he has a layer, may be we want him to interact with different objects in different ways, and that's where we use tex. Okay, so let's demonstrate how the slayer works. If we go into camera, you can see that we have something here called calling mask, which renders everything. We can actually turn that off, turn off the ground. And oh, we didn't assign the ground to the foreground. Now foreground has, is on the ground level, on the ground layer. Save that, go back into camera, go back into the game view. And we can see that everything under the ground layer, which is our foreground right now, does not render. And if we turn that back on, we can see that we can see the foreground again. Okay? So. Now we need a way for our players to know that we are touching the ground layer. And of course we'll be using that through the collider because the collider is the main thing that holds our player on the foreground. And we're going to do that using something called a collider to d dot is touching layer. So what does this function do? Well, it returns a Boolean whenever this collider, Collider 2D, which will be the player collider, is touching any collider on this specific layer mask. So what is this layer mask? It's some, it's an integer that is put inside of touching layer. And it tells us which layer we are. So how are we going to use this layer mask? While we thankfully have a function which is called Layer Mask dot get mask. And this allows us to actually write or get a string reference of the layers name. And it returns an integer, the Layer Mask created from the layer name. So we get our layer name. We put inside of layer mask. We use it for, we put inside of the ghetto mask that is used by the Layer Mask. And we put all of that and sat inside of is touching layer to be used by the collider. So we'll do something a bit different right now because it's time for your challenge. And your challenge is to stop the Maltese jumping. So you'll need to use the collider 2D dot is touching layers. You'll need to use the Layer Mask dot GetMax, layer names which should be ground. That's a small hand. And we will have to complete the logic and stop the player from multi jumping. So I know this challenge, but early I haven't showed you how it's done, but I've given you all the resources you'll need, and I've given you all the examples and methods. So pause the video right now and give this challenge ego. Kay, welcome back. How did you get on that? So first thing we'll need is we'll need to go into our Visual Studio. And before we get started, I know I've told you actually that will need a reference for our collider because colliders are the components that use the destruction layer. So let's go ahead and get a reference for our collider. We know that our player has a box collider on him. So let's do that. Let's create a variable that is a Box Collider 2D t. And we'll call this my Box Collider 2D. And we'll use in the Start, My Box Collider 2D will be the component Box Collider 2D that is on the Player O K grid. Now, why is it telling me that? Oh I typed in my rigid body by mistake, excuse me. So it's my Box Collider, 2D or k. Great. So now what we'll need to do is we need to prevent this jumping method to execute unless we are touching the ground. So how are we going to do that? We'll do that using an if condition. So, so first thing, let's type in if and open the brackets and what should we write inside of it? So we'll need to write inside of it. My Box Collider 2D dot is touching layers. And inside of this touching layers, we'll write layer mask because as you see it's asking us for a layer mask. We type in Layer Mask, dot, get Mask, and open the brackets. And now you can see that it's asking us for a string reference. And I can already hear you. You're telling me that if we have a string reference, we need to go into Unity and copy it. So I will do, as you ask, we go into the layers, we copy the ground even though it's a very easy word, but you have to get in the happen of doing it. So now we open the brackets and what should be right inside of it? Well, let's see. We can do this two ways. First of all, we can take all of this code in here and put it inside of these two brackets. And whenever we are touching, the ground layer will execute the code. But there is a different way and a much smoother way. So that way is, first of all, we'll add an exclamation mark just behind this statement. And what this what this exclamation mark does, it negates whatever is in front of it? The condition inside of this one is false. It will execute whatever is inside of the curly brackets. So let's say we are not touching the ground. That means that this is touching layer returns false. And because we have an exclamation mark right behind it, it makes this whole statement is true and it executes something inside these brackets. And what is inside these brackets? It's something that you've never seen before. Maybe, maybe you do, but it will actually return. We've used return before in the previous section. And what this return, those without anything, actually takes us out of our jump method. So whenever we write return without anything next to it, it simply just jumps out of the jump function and it continues in the update or wherever, wherever it wants to continue. So save that. And let's see if that actually works. So let's get back and to our unity and click on player. That's means smaller. Click on play. And now while we move, we move, we jump. But if we double jump, we cannot double jump anymore because we are not currently touching the ground. But there is a problem here. As you can see, we get stuck in the wall. So if I go next to a wall and I continue to click on the left button, you can see that the left arrow, you can see that we are stuck to the wall and will fix this problem later. Another thing is that we have double jumping. If we are touching a wall and that is not desirable, we'll fix that in the next video because this one is getting a bit too long. I'll see you in the next one. 28. How To Prevent Wall Jumping: Welcome back everyone to another video. So as you can see here, whenever we click on play, we have two problems without player. First of all, if we jumped next to a wall and keep on pressing the left arrow or the a button. We can see that he keeps getting stuck on the wall. That is a problem of friction. And second problem here is that if we can actually double jump on the wall so as you can see, he doesn't touch the ground and yet he can still jump. That is, go and fix this to show this a bit better. So if we go into our tiled pellet, choose the eraser, choose the foreground, erase that. Choose the platform, go to background and actually draw something. Save that back into game. And now you can see that we can double jump on the wall without even touching the ground. So we'll fix that also. Okay? First thing we are going to solve is the friction problem. And to do that, we're going to first of all do the My favorite part of all project creation and that is creating a folder. We'll call this materials. And inside of materials, we are going to right-click and create a physics 2D material. So create that, we'll call this 0 friction. Okay? So I've left in the resources a documentation about physics materials. D you can read all about them, but honestly it's very simple. So if we click on this, we can actually see here in the inspector that we have two options. One of them is friction and the other one is bounciness. So friction is what gets stuck to the wall will put to 0 and bounciness is what makes us bounce. So for example, if you want to add a trampoline to your game, you can create a physics 2D material with bounciness and added to a tramp. Clean. So now let's go into layer. And because we are, we are actually able to do the jump, double jump because of our collider. And if we click on our box collider, we can see here that we have something called material. And this material takes a physics 2D material. So what we're going to do, it's obvious we are going to drag our 0 friction material and put it on the box collider. As you can see, we can also apply that to our prefab. So apply that. And now if we click on play, let's go to our wall and we can still double jump, but we no longer get stuck on the wall. And neither do we get stuck here nor there. We don't get stuck anywhere. Oh, okay, great. So first part of the video is done. The second part is your challenge. Your challenge is to prevent the player from wall jumping. So first of all, you stop the player multi jumping while touching the wall. And I'll give you a hint, which is to add a second collider at the feet of our player. So you have to add a second collider, make it. So that it fits in the feet of our players, need to add a different kind of Collider. I recommend using the polygon collider. And you should make this collider the thing that has to touch the wall. Okay, those are enough fence. Pause the video right now and do the challenge. Okay, welcome back. So I hope you try to do it. So let's get this show started. First thing we're going to do is we're going to add a component. And that component is going to be a polygon collider to d y polygon. Well, because we can make a box out of it. And since we've already YOU, since we're already using a box collider, we can't use that. So right now we are going to edit this polygon collider to make it just at the feet of our player. So let's make this a little bit smaller. And if you want to delete the unnecessary lines, simply hold on, hold on control. And you can see that you can't delete multiple sites. So we'll leave this one. Get the song closer, the swan closer or control delete, delete, that. We don't even need this one. And now we have a box or actually polygon collider right around. Our players fit and make it just a little bit smaller. So, I mean, under the box collider of our players, so make it this big, this big, and that, I think that is enough. Save that and apply it to our peripheral. Oh, okay, great. Now we have a polygon collider on our player. Great, save that. Now, what should we do next? Well next will have to add this polygon collider to our box, or instead of our box collider here. Why is that? Well, because now our polygon collider will no longer touch the walls whenever we want to jump. So in that way he will not do a vulture. First thing we'll need is we'll need to get a reference to our polygon collider. So simply create a variable of polygon collider to the type. We'll call this my layers feet. And we're going to UPS, sorry for that. And we are going to, my players feet will be a component which is a polygon Collider 2D. I want to get, okay, great. So now we have a reference to our players fit that script. And now we're going to change this. So we're going to change the my box collider to my feet, my tears feet. We save that and let's go into Unity and see if that worked. So now if we stand, we can jump, we cannot double jump. And if we go to the wall, we cannot jump on the wall multiple times. Excellent. Oh, okay, great. So I hope you enjoyed this short video and I'll see you in the next one. Everyone, sorry for dropping by, but I thought this is a great opportunity to remind you of doing something very important and that is committing our changes. So as you can see, I've been committing my changes constantly. So I will stage all right now and will commit this change, changes. I'll call it dropped the friction to 0 and prevented wall jumping. Great. So I hope you are doing your part of the job of always saving and committing your work. I'll see you in the next one. 29. How To Add Climbing Mechanics: Welcome back everyone to a brand new video, and this will probably be the longest video in the series. So, but it's going to be worth it because when we click on play, as you can see here, we have those sheets and those sheets actually help us climb on our well in our environment. And because of it, there are places that were previously unreachable like that surface over there that we can now climb on our sheets. It's very fun. It's very cool. And I want you to not get very frustrated with the length of this video. I'll see you in a okay, so first thing we're going to do is we're going to be importing sprites. So let's just go ahead into declarations or unclear resources. Get the declarations and put them inside of sprites. And let's go ahead and create a folder. We'll call this folder terrain. Why not click on declarations or know that scholars. And by Ron meant, I hope I've typed that correctly, put them in an environment and let's slice up our spreadsheets. So make this 30 to make this multiple. I'm sure you're already very familiar with what we're doing. We've done multiple times and we are going to slice it up. So go ahead and click on sliced up grid, grid, cell size. So 32 by 32 and slice that baby up. Okay, great. Now or click on Apply. And I'm not sure if those are called drapes or they called Hanging cheats or I don't, I'm not sure. You can call them whatever you want. Save that. And by the way, we're using it because I didn't find any other sprites. Well, actually free the other sprites. But that's okay. Let's go back. We'll use whatever we have at hand. And it actually makes a more fun game. So now it's time for a challenge. So I want you to finish the climbing. First thing you need to do is setup the climbing tile map with its layers. And by the way, this is a mega challenge. And then you'll need to create a climb method. You'll need to check if our player is touching the climb Bing layer. And you will need to add a climbing velocity to the y-axis using the get access method. Finally, you will need to trigger the climbing animation while our player is climbing. Now, this is a huge challenge. It's the biggest challenge we've done so far. So if you feel a little bit overwhelmed, you can start and then pause and then start again. Or you can watch me do the challenge. And whenever you feel like you have everything under control, simply pause the video and continue on. I'll give you your time. So pause the video right now and go do the mega challenge. Okay, welcome back. How did you get around that? So let's talk. First thing we need to do is we need to add. Toils in here. So let's click on the drapes that we need and select them. Hold Control. Oh, sorry for that. So hold control and select the things that we need. Drag him into our scene. It will ask us to create these styles. So let's go into tiles. They are terrain, No, they're not terrain tiles will create a new folder and these will be the climate goals. I hope climate is written correctly, so Climb mumbles, and now we have them in our palate. So let's go ahead and edit this. Edit, please. So now we select, well, with second, select this one and we're going to move it here and put it just over the our other Tiles. Click again on lacked to move them and save that. And now we have the ability to draw our drips. Cool. Now, let's try that for a second. Oh, and before we do that, let's go ahead and create a tile mapping grid. I mean a tile map. So 2D object, tile map, and we'll call this tile map goto specter. We'll call this tile map climbing. Excellent. Now, back to palette. Click on climbing. It's already clicked and now we can draw it, but not in our scene. Before we do that, I want to create a small platform. So let's go ahead and to foreground. Let's choose two of them and we'll delete it because I don't want this here right now. Let's go back to background, finishes that. And let's see. I want to make a bit of editing in here, so I will maybe speed this video up. Oh, okay, welcome back. So let's continue. So as you can see, I've created this platform right here that our player can get too while jumping. We can only get to there using our special drapes. So that's going to climbing and let's add our drapes. And as you can see, we cannot see them. So we'll change that by creating some layers for our rates. Go into add layer. And let's create here a layer for climbing. No, it's not the sorting layer, but we'll use that also to touch our drapes. And we'll create a layer for the sorting layer. And now we have it rendering in front of the background, but behind the player. Excellent save that, go back to climbing, go into the inspector, Click on the tile map renderer, and in the sorting layer make this climbing. And now we can see it perfectly. And also let's make the layer on the climbing rate. Another thing we should do is we should add a collider. So let's go ahead and add a box collider to it. And let's see, this collider is 100% wrong. Let's make it smaller and smaller. And zoom in and make sure that the surface that the player can touch in order to climb as inside the drapes. So make it like that perfect. And one other thing we should be adding is a composite collider. So Composite COM ports Collider 2D. And we'll make sure that the rigid body is static and that our box collider is used by composite. Save that. Oh, okay, excellent job. Let's continue on. Next thing we'll need to do is we'll need to create a function for declining. Because as of right now and we cannot climb anything. So if I click on play, our player simply bumps into our hanging cheats. And another thing we need to do is we need to make sure that our composite collider right here is a trigger. And what this does it, it can be used as a collider, but we can't actually collide with. So for example, if we jump on it, oh, actually I'll play or maybe can't get to that. Oh, no, he can't. So he doesn't need the ladder. Great. So as you can see, our player does not collide with the drapes. Save that. And next thing we're going to do is we're going to go into our Visual Studio and go ahead and create our climb function or method. And we'll generate that. So we have a climb function which is private and doesn't return anything. First thing we're going to do is we're going to check if we are touching the climbing layer. So we've done that already and will use my players fit. I would rather use my feet to climb. So as touching layers, layer mask and the Layer Mask or use the get mass component and it needs a string reference. That means, even though we know that climbing is very easy to write, We'll go back, copy it, and paste it inside of here. And we won't be using the same method we've used in jump. You will know why very soon. So next thing we're going to do is we're going to use the get access. And if you feel that you can continue to challenge at this point, simply pause the video, check the challenge again and see what you need to do and completed on yourself. So pause the video. Okay, we're back. So let's go get the axis. So well, be used the same method as we used for the running. So we'll create a float that is called control throw. And we'll use the cross platform input manager, dot. Get axes, and this time it should be on the vertical. So let's go see what? Oops, this is a challenge again for you. So let's go see in our project settings and whereas the inputs, input manager check the vertical and let's see the US and W. Copy the vertical, go back and to unity and I'm in Visual Studio and pace that, great. Next thing we'll need to create a climbing velocity to add to our player. So go ahead and do that. It's exactly the same as for running, but now it's climbing velocity. So climbing velocity is equal to a new vector two. So now what we need to do this, we'll need to add a velocity in the y direction, but keep the x-direction velocity the same. So we will go into my rigid body two d dot velocity dot x. So this velocity will stay the same, by the way, if you want to try it, you can actually make the velocity on the x 0. So that way whenever our player actually touches the drapes, he gets stuck there and he cannot move anymore, which is a bit more logical. But because this is again, I think I'll keep it velocity x, feel free to make it 0 f. And next thing we're going to do is we're going to add a control throw in the y direction. But we already know that that will be too slow. So we are going to create a variable right here. And of course it's going to be a serialized field. It's going to be a float and it's going to be climbing speed. And our climbing speech should be, I think 8.5. It is a good climbing speed. So control throw will multiply that with our climbing speed. Close that final step. My Rigid Body 2D dot velocity will be equal to the climbing. Nope, I mean, I meant climbing velocity. Thank you. Close the semicolon. Always remember to close the semi-colons. And now we've said everything. What else do we need to do? We need to check if something actually worked. That's confidence for you. So save that everything is saved and click on play. And now we can move around. If we jump, if we jump, we can now climb and if we let our player drop, he actually falls down from the drips. Oh, okay, excellent. One thing I want to do is I want to make this a little bit longer. So that's a little bit longer, just like that, we can even make them touch the ground, which becomes sort of like a ladder. Actually exactly like a ladder. So go back and check this. Click on play. Let's see our player an action. He touches the drapes and he can not. Ok, he needs a little bit of a push in order to jump on this. That's because our collider is not touching the feet of the player. Let's change that. Let's go into inspector and make the box collider just a little bit bigger. Oh, oh, Talk Box Collider didn't go with the climbing. That's unfortunate. That should be corrected but no worries right now. Saved that. Click on play. And now we should be able to climb. Oh, okay, great job. Let's now final step will need to add the climbing animation whenever we are on the drapes or whenever we are climbing. So in order to do that, it's super simple. We already have the reference for our animator and we already have a boolean for the climbing. So as we did before, I'll give you another chance to complete this because it's very easy. Pause the video. No, you want to watch me do it ok, so my animator, so my animator dot set Bool. When we are actually touching, we're always going to be in the a climbing animation. So we'll go ahead and get the string reference. Copy that, go back to visual studio based. And it's going to be true. And when we're outside of the if condition. So whenever our player is not touching the sheets anymore, he can actually go ahead and stop the animation, which means setting the climbing back to hope what happened there and setting back the climbing to false. Save that. That was a long video. Okay, so click on play. And now our player gets stuck to the drape and goes into the climbing animation. And let's try this again. And actually you can see that he hangs on the drip. Now, one thing we'll fix about these is when our player actually touches these drapes, I want him to get stuck to them and not drop down every time. We'll do that in the next video because this one is getting too long and I'll see you in that one. 30. Tweaking Climbing Mechanics: Okay, so a couple of things that we need to change in here. First thing we're going to change is we're going to go into our sprites and go into our sprites editor. And if you go here to the upper left corner, you can see that we can actually customize the physics shape. And this is the first thing that we're going to do to our trips. So we click on Generate and we can actually change the outline of our box collider that we are going to add. Why are we doing this? Well, because I actually want our player to only be able to climb if he's actually holding and touching the drapes. So make them just inside this inside the drapes. It will help you. It will snap to place. So click on whatever sprite that you want and click on the generate button right here and get them a bit closer to the center. That way they will move and actually feel more, a bit more realistic. So not that much. So that's go ahead and keep these inside. We can actually even this one to it. You don't have to be that accurate. But if you want to be that accurate, Yukon and everything is good, this one's good, this one's good, this one's good. Click on Apply and we're ready to continue. And now I've made a mistake, a small stake previously, and I've added a box collider. So we'll have to remove that component and actually add a tile map collider to D And make sure that it is used by composite. So check that. And the composite should be is trigger. Okay, great, Save that. Next thing we're going to do, because through trial and error, I found out that actually using the feet for climbing is not a good idea. So let's go ahead and change it into, nope, into my box collider, and that will be better. So everything should be fine except for one thing. And if we click on play and we jumped on our drape, we can see that our player slowly starts moving down a free let off the w or the up arrow key. And that is where your challenge comes in. And your challenge is to stop the player from sliding. So first thing you need to do is set the gravity on the player's rigid body. And then you need to set the gravity to 0 while the drapes, while the player is on the drapes. So this will need a bit of research, just little bit of research. And I am sure you will be able to finish the challenge. So pause the video right now and go ahead and do your best. Ow, kay, welcome back. So let's get started. Let's get started as starting the video. So if you click on player and look at the rigid body, you can see here that we have something called the gravity scale. And this is if you hover over it, it's how much gravity affects this body. And this is the component that will be manipulating in our code. How are we going to do that? Well, first thing we're going to come here and create a variable that is a float. We'll call this the starting gravity scale. And what will this value be? Well, it's going to be the starting gravity scale or the gravity scale that we start off with. And it's going to be the original cavity scale on my rigid body. So we'll type in start gravity scale. It's equal to my Rigid Body 2D dot the gravity scale. And this will be one of course, but we want to be more precise using my body's gravity scale. Next thing we're going to do is whenever we are actually on the drapes or touching the drapes, we want to set my rigid body dot gravity scale to 0 F. So now whenever our play is touching the climbing mask or the climbing layer, the gravity scale will go to 02 refers that effect will change it back to the gravity scale of starting gravity scale. So if we are touching the climbing layer, my rigid bodies gravity scale is going to become 0 and else so when we are not touching the climbing, our gravity scale will be set back too, the starting gravity scale. So save that, go back into Unity. Wait for it to understand what is happening, and let's click on play and see what happens. So now if we climb up, our player stays on the drapes and doesn't slide down without touching the keyboard. A girl rate. So I hope you enjoyed this quick video and I'll see you in the next one. 31. Cinemachine Follow Camera: Welcome back everyone to a brand new video. And as the title suggests in this video, we are going to make our camera follow our player using something called Cinna machine. So as you can see now, if we move our player, the camera isn't static. It doesn't stand still and wait for us. It moves with us. And even if we climb, it moves with us when we're walking, it moves with us and when we jump at, also goes wherever our player goals. So or as you can see, we have virtual cameras. We've added a brain to our cameras. So now it's actually thinking about things. And I'll see you in just a bit. Okay, so what are some machines and why do we need them? As you can see right now, our player just moves in the environment and the camera does not take notice of him at all. And what we want is we want the camera to actually follow our player as he moves through the level, because we'll be adding a much bigger level that will spend from here and two here, maybe up, maybe down. We don't know, but we want the camera to be following him. Now before Cinna machines, all what you needed to do is you would actually need to create a script and end that's great. Script. Create a serialized field that would get the player and use his transform to go and follow him every step of the way, which was very cumbersome. But now we have the power of cinema machines, correct? So let's start off by importing machines. And in order to do that, you need to go into window up here, here. And you need to go into Package Manager, click on package manager, and go into your Unity registry. And you should have this cinema cine, which is verified right here. And now what you need to do is you will simply need to click here on this install button. It may download something. I've already downloaded the package, so it's simply going to install. Oh, okay, great. Welcome back. So now as you can see right here on the top of our screen, we have something called a sinner machine. Now, what is a cinema machine? Well, a cinema machine is something that allows us to create virtual cameras. We still have our Main Camera. And on that camera we put something called a cinema cine brain. And that brain drives the other virtual cameras that we will be creating. So why we actually use these virtual cameras? Well, in 3D games, these virtual cameras are used to create cutscenes. For example, whatever game you play, whenever you see a cutscene, it's probably because they used a cinema machine or a, I mean a virtual camera. And in our case, for a 2D game, we'll use it to make our game a bit more dynamic. So let's first of all go into our main camera and click on add components. Make the smaller click on add components and simply type in a brain. So now we're going to add a brain to our camera. So cinema cine brain, click on that. And now we have the brain setup right here. Next thing we're going to do is we're going to go into our hierarchy and create an empty game object. And this empty game object, we'll reset. It. Doesn't matter. But I'd just like to reset, Thanks to have them all in one single place. And let's rename this to our cameras or simply type in rows. Okay, and this is for the sake of organizations. Organization. So let's put main camera under our cameras. And now let's go ahead and to send a machine and create a 2D virtual camera. So let's see, we have this create virtual camera, collect on that. And now we have something called a CM, the camp. And if you look to its right, you can see that we have something called here, follow. Now, I've left a link in the resources for everything you need to know about cinema machines. You can go ahead and read the entire document or you can simply just glance over it and get a sense of what things are. So for example, they look at the follow the position blending are very important things. You can look at the lens. There are many, many, many helpful information right here that you can read all about if you don't understand it right now. But let's go back into Unity and focus on the important and main things. So we have this follow and this is the most important part. So it's the object that the camera wants to move with. And that object is of course our player. So simply click on player and drag him into the follow. And now this camera should be following our player. I another thing, because it's somewhat important and it's very dependent on you. It's under lenses, you have something called orthographic size. And this is actually the size of our cameras. So you can make it bigger and you can make it smaller, and it depends on how you want your game to feel. So for example, our main camera, we can see here that we have the size, I think it's 5.02. And for our virtual camera will also be 5.0.2. Let's make it five ergo rate. So now let's go ahead and rename our CMV Cam, which is a very weird name. Let's simply call it VR virtual camera. And we'll put it under cameras. So now we have cameras under a single object right here, and it's much butter. So save that. Let's click on play and see what actually happens. So now as you can see, while moving, move in our world, the camera follows our player. So now it's much more dynamic and it feels. Like a true 2D game. So let's go out from that and let's discuss a couple of things about virtual cameras. Now. If you go here, if you're still clicked on virtual camera and you look in the inspector, you can see right here that we have something on the body which is a transpose. So let's go ahead and change that and make sure that you have it under framing transpose. And you will get all these different weird options right here that we will discuss. But before we do that, go up a bit and you will find that you have another option right here that is called game window guides. If you click on that, you can go into a game and you can see that we have different windows. And each one of those windows has a different effect on our virtual camera and how it uses the environment or how it follows our play. So let's start things and explain a couple of these. There are a lot of options we won't cover all of them. Feel free to go into documentation and read about them if you want to be meticulous with the first thing we have is the look ahead time. So Let's click on play and start the game and start tweaking from him. So if we choose a look ahead time, you can hover over it. It doesn't say anything, but I'll tell you what it does. First thing it does, it actually determines where the player is going to go. So now you can see that this yellow dot, actually that yellow dot represents where our camera is looking at the moment. So we have both of these on 0. You can see that r dot moves with the player, however he goes. But if we add some look ahead time and smooth that out, the yellow dot will precede the player. And it will calculate or determine where the player might be going next and will smooth out the transition of the camera. Next thing we have is we'll have something called the dead zone. And this zone, if we increase the size just a bit, we can see that we will have a zone inside of our guides or window guides. And if we move inside this dead zone, the camera will not move. It will only follow the player if he steps outside the zone and it's determined by this yellow button or yellow dot. So now, let's go here. For example, if we move inside of our dead zone, we do not register or the camera does not move with our player. What else should we talk about? So I think we'll add a bit of that zone right here will make it 0.20.2. Oh, okay. What else should we oh, excuse me. So 0.2 by 0.2, please start whom and what else should we be looking at? We have something called the damping. And let's go ahead and increase. The best way to find out what all of these do is simply by increasing them and trying the game out. So now damping, you can see that it slowly goes to where the player is. Doesn't immediately jump to where he is and put it to 0. You can see that the camera becomes very fast and it actually has its own feel to the game. And all of these can be tweaked to your preference. They can also be made a very extreme, they can be made to 0. It depends on your preference, on how you want to make your game field. And always remember whenever you change things in here, you need to remember them. Remember them because when you click on play again or go out of the play mode, everything will be reset. And now it's time for your challenge. And your challenge is going to be to set up your follow camp. So first thing, you need to tune your, the virtual cameras to your own preference based on how you want your game to feed. And you'll do that using the camera size, using the dead zone size and using the look ahead. So you can pause the video, or it's simply the end of the video. Wait for it to finish and go ahead and set up the virtual cameras to your own preference because it's your game. It's not my game. I do it the way I want and I want you to do with the way you want it to be. So I'll tweak a bit and I'll see you in a bit. Okay, so I'll just make a few changes right here. It's not going to be much output the dead zones to 0.2 in the width and the height. And I'll think, I'll add just a little bit of look ahead with a bit of lookaheads moving and the damping. I think I'll keep it the same. And if we click on play right now, let's see how that feels. If we walk, let's turn off the window guides. So if we turn off the window guides, so as we move, our camera moved was with us. Maybe I'll add a bit more smoothing, so make it three. And it really feels very smoothly. Make this a bit more 0.02 and great, I think this is smooth and cool enough. So I hope you tweak your own virtual cameras to your preference, and I'll see you in the next one. 32. Cinemachine Confiner Extension: Welcome back everyone to a brand new video. And this one, as you can see, we've made a bigger level, which needs a bit more tweaking, but it will work for now. And what we've done is now if we move our camera, as you can see, it moves freely without player. But if we go to the edge, you can see that it no longer moves beyond this edge. That means we've created a world confining. And why did we do that? Well, it will give our game a sense of immersion. And whenever our player climbs, he no longer sees anything beyond the realm of our world combiner. So let's not waste any more time and let's jump in and get started. Okay, so the problem right here, right now is that whenever we play, we can actually see what's going on behind the scenes. So this takes out the emergent from our game and makes our game actually not feel real and feel like it's worked on, it is, but we don't want the player to know that. So we have to change what's happening. What we're going to do is we're going to create a confined around our level. And this confined or will not let our camera move beyond it. So let's do that. If you go into our inspector and scroll down, you can see right here that we have something called extensions. Let's go ahead and add an extension. So click on that. And you can see that we have a lot of options. But what we're going to be needing is this cinema machine con, finer. Click on that. And below it you can see now that we have a new component that's Santa machine confirm finer. And it needs a bounding shape. That is to d. Great. What we're going to do is we're going to be creating a tile map. And that tile map will be our world combiner. And it will stop our camera from moving beyond that. Let's click on File Map. Right-click on that. And let's create a 2D object which is a tile map, will change its name to world confined. And now we have a new tile map setup. If we go into our tile pilot, we should have our WorldCom final. And you can choose to have your pile that represents the word confinement or what ever it is. But I will choose to have it as this center block right here. So let's go ahead and create our world confined there, just around here. Okay, and now we have it set up, but still, this does not work properly, properly. And that's because we still haven't added the bounds for it. So what I'm going to do right now is I am going to make our level just a little bit bigger. And in order to see how this camera actually works, and I'll make this a quick video using the magic of video editing. So see you in just a bit. Okay, welcome back. So as you can see here, I've created a platform. I've increased the size right here. I've added a ladder in order to reach the top and some kind of weird room right here. I'm not sure what it does. And that's basically it. And what I just wanted to accomplish right here is just to make our level bigger to move it. So now let's go ahead back into our tile and choose WorldCom finer and create the confinement around our world. So let's go ahead and do that. Make it this big. And let's go ahead and make it this big right here too. So this depends on how you want it. Don't you don't have to make it exactly the way I am making it. You go ahead and create your own platform and make your own world confined. But what you need to keep focused on is that we need this right here. As you can see, this is the camera that we have and you need to make sure that this camera actually fits. So never create, for example, something that's very small, like like here. And then this doesn't allow our camera to fit between those two spots. So make sure you keep that in mind. So let's control z two times in order to reverse these changes. So next thing we're going to do is we're going to add a polygon collider to our world confined. So let's go ahead and do that. And why are we doing that? Well, because if you look closely into our visual virtual camera down here, you can see that it needs a collider to D that will tell it how it will be confined. And a polygon collider is the perfect way to do that. So as you can see, it's very big and will change that very quickly. Click here on edit. And let's go ahead and add it to our confined. Now this doesn't have to be perfect. You just need to make sure that the green lines are inside of your world combiner tiles. So let's go ahead and make it this big. And we choose a polygon collider because it's very easy to manipulate. So make it this big, and then hold control to delete that. And now we have. A square. Well, it's a polygon, but it's a square. And make sure that the green line or inside this, these tiles, or whatever tiles you've chosen to make the world combiner N. And I think it's great and it's working fine. So save that. And now let's go ahead and add this world confined her to our virtual camera. So click on virtual camera, camera again, go down into the extensions and simply hold down ops, hold down on the world confinement or wait to go back down and hold down the world confined and drag it into the bounding shaped 2D. As you can see now we have this bounding shape. So let's play this and see one thing that is wrong. So now we click on play, and as you can see, our players simply disappeared into the unnatural what's called below there. And why is that? Well, if we click on player and take him into this spot, for example, and click on play again. He's still disappears into a mature even where that is. And why is that? Well, because our player is confused, he's not sure where he should be or what should he be interacting with because our world confining right now has a polygon collider on it and he doesn't know if he should stand on this polygon or should they float on this polygon, he doesn't understand what's happening. And the problem with that is if we go into our project settings, that's close that and go into our physics 2D and expanded. If we look down here, we can see this matrix and what this matrix is. It's, if you read it, it's saying layer collision matrix. So it tells us what layers interact and collide with each other. So for example, you have climbing that interacts with every single layer that is. And for example, default also interacts with every single layer that is a available. And if we look into our player, so go back to Specter. First of all, our world confinement is on the default layer, and our player is on the default layer. That makes them both interact because of this matrix. And to turn that off, you can simply click on this button and it will stop the interaction between those two colliders. And this is where I take you to your challenge. And your challenge is going to be to create a camera confined R. So first thing we need to do if you haven't done so already is create a bigger level for your player and camera to move in. Second thing you need to do is add a collision to the world collider confined, I mean tile map. And then you need to create a player layer and a WorldCom finer layer. And last but not least, you'll have to adjust the physics layer matrix for player and 40 combiner. So pause the video right now. You already know how to create these layers. You've seen me create the bigger level and at the collision. So the only thing that you are not very familiar with, R as the layers metric matrix, but I'm sure you'll do excellent job. So pause the video right now and go ahead and do that challenge. Oh, ok, welcome back. So let's get this done. So first thing we'll need to do is we will need to click on the player and go to inspector. And we'll choose this layer and we'll add a layer. So we'll create our layer layer, and we'll create our world confined layer. A nother extra step we'll do is we'll create a sorting layer for the WorldCom finer. We don't have to do this, but just in case we'll keep it behind background because that's where we want it rendered. So save that, go back into player and make this player on the player layer and apply it to the prefab, go back into the world combiner. And let's go ahead and make it a world confining layer and go into the tile map renderer and make sure that it's sorting layer. Is the world confined and save that. And now let's go ahead to the Project Settings, scroll down in the matrix and as you can see, the layers that we've created, the world confinement and the player are now available. So what we'll be doing is we'll be turning of everything that the world can finer, interact with. So now the world confinement does not touch anything, it does not affect anything. It's simply confines our camera in a determined space. So now if we save that, let's go back into our player and move him here to the edge. As you can see even in our scene, our camera moves freely. But whenever we get to the edge, you can see that it does not move anymore. So let's try out our new cameras. Click on play. And now we move. As you can see, the camera does not go anymore behind the scene, and now we can jump and okay, we barely cut that. And now as you can see, we no longer see what's happening behind the scenes and we can get to that edge unfortunately. But as you can see, we've created a confinement and made everything much more realistic. So why do we even want this to be an hour game? Well, this is really cool. First of all, second thing, It feels like a real world and it gives a sense of immersion to whoever is playing our game. And he understands that there are limits and boundaries to our world. Plus he doesn't see what goes on behind the scene. Get it behind the scene. Okay. I need to stop making those jokes and I'll see you in the next video. 33. State Driven Cameras: Welcome back everyone to a brand new video. As you can see, we have something different right here in our hierarchy, where we've created a state-driven camera. And we've added lots of things right here that will be explaining and thorough detail. But, but as you can see now when we are idling, the camera zoomed in and when we start running, the camera's zooms out. And when we jump on the hanging sheets, we can see that the camera's zooms back in. We can jump, we can move, and the camera's zooms in and out. And our player feels that we know whenever he's running and walking, and that gives them security and it makes our game much more professional. So I'll see you in a bit. Okay, so let's go ahead and create a state or animation driven camera. So I will be using the word state and animations interchangeably. They mean the same thing in the context. So go to Santa machine and look for state-driven cameras. Click on that and this will create a CM state-driven camera one. And we'll change that name to state driven camera because we don't want everything to be mushed together. And as you can see, we have a virtual camera. So let's go ahead and first of all, child, our virtual camera that is used under the stage given cameras. And now, if you scroll down and state different cameras in the inspector, you can see that we have virtual camera children. And that means that whenever we want to add virtual cameras to us, to our state-driven camera, we need to child them. So what do these virtual cameras under state-driven cameras do? Well, they are used for every state or animation that we have. So let's go ahead and delete the one that was already present. So delete CM camera and keep the virtual camera that we had and rename it to virtual camera running and duplicate that and create a virtual camera idling. So now we have under state-driven, a running virtual camera and an idling virtual camera. And another thing that we need to take into consideration is that we'll need to add the player as our animated targets. So as you can see here, we have something called Animated target. And let's drag the player into that. And now we have the player as the one that presents all of our animations and that's what we need. Next thing we'll do is in order to differentiate between running and idling, we are going to change the orthographic scale of each camera. So this is where it comes to your preference. So for example, if you want to, the player to be, so let's say zoom into the camera whenever his idling and zoom out whenever his running, you need to go into the virtual camera, go to lands. And increase this orthographic size to, let's say six. Let's make this 16. And the virtual camera for idling will be four. And as you know, this is purely based on your preference. You can make them bigger or smaller depending on you, but I'm just doing example numbers for the sake of the example. Ok. So next thing we are going to do is we're going to demonstrate what's happening. So now our player is, for example, in this scene and he moves but nothing happens yet. Was that well because we forgot to create these states. So now let's go ahead and add a state. And what this does is it creates a new state. And that state is called idling. And the camera for it is the virtual camera of idling, will create a another state. And this will be for the running state, and it will be using the virtual camera for running. And now if we save that and if we click on play, and let's see what happens. So as you can see, it's a bit more zoomed in. And when we start running, we can see that the camera pans out. When we start the running, we zoom back in. But as you can see, it's a bit too fast. It goes out and then back in, if you like that kind of zooming, it's great. No need to change it, but we can actually make modifications to it. And the way we do that is we have many, many options. So first thing we have the weight and this actually wait to go back, for example, to either link. So let's make this, for example, 1 second. And now if we run and stop running at wait, 1 second and then zooms in a another option that we can change this minimum which will slow down the I'm not sure what it does exactly, but it, let's make it five for example and see what happens. So now we move, we run, and then we go back up and down. So it takes five seconds, I think, to zoom out, and then it takes 1 second to zoom and okay, so now we know what minimum is. It's the minimum time to wait before we go into the next state of virtual camera. But back to 0. What else can we change year? Well, we have the default of land, which determines the amount of time it takes in order to actually do the animation or the zooming in and out. And we can actually choose what we want to change. So for example, we can change the ease in or ease out. And let's make this for example, to seconds. So now when we start walking, it takes two seconds to zoom out and we stop, wait 1 second and then it takes us 2 second to zoom. And let's get out of the play mode. And as a final thing I want to tell you about is you can actually create your own custom plants. So click on Create Custom blends. And we'll add it inside of the animation. And it will be called state-driven camera and save that. And you will have some kind of weird arrow right here. Don't worry about it. If you simply cleared that up, it goes away. And every error that you can simply clear and it doesn't break the game is not that bad. Okay, so next thing we're going to do is we go into custom plans and here we have the blender, so we simply drag that and to send a machine and now we can create our custom lands. So let's go ahead and do that. First land we're going to create will be from idling and to running. And it will be an ease in and out. And the time it will take to do that will be, I think it should be very fast. So I'll make this 0.5 seconds. And let's say the second blend will be from running to idling. And I think the ease and out should take, I think it shouldn't take more than 1.5. So this will be sort of, so let's see how that works. If we click on play. Now we move, we directly move to the running. The camera pans out immediately. If we stop, it zooms in and takes 1.5 seconds. So what else should we do? Well, we should also add a virtual camera to the climbing, but that will be your challenge. And your challenge will be to add a climbing State camera. So you need to create a state camera for climbing. And you'll need to make blending between other cameras and thick climbing cameras to your own gain pace. So go ahead and do a challenge, and I'll be here waiting for you. Oh, Okay, welcome back. So what are we going to do? So what we're going to do is we're going to duplicate the idling and we're going to call this virtual camera lining. So what should the climbing cameras do? Well, I think there are two ways to go about it. I think that whenever we are climbing, we should zoom in. So the player makes sense because the player, when he's climbing, he cannot see very far because he's focused on climbing the sheet. Okay, that's not very logical, but that's the logic of my gain. So I'll make it a bit smaller and make it a 2.5. Okay. 2.5. maybe is too small. Let's make it. How much is idling gets? 43. Okay, I think three is good enough. Now we go back and state-driven cameras and let's go ahead and add some landing. So in here I will choose to go from any camera to climbing. It will take it will take two seconds. I think two seconds is good or 1.5 as to 1.5. And from the climbing to any camera, I think it should take two, maybe 2.5. because let's think about it because whenever he stops climbing, he gets to that. He's tired. He's still looking at the ground and then he moves his head up and sees everything. Okay, great. Excellent. So save that. I know it's not very logical, but just hanging there with me. And you can create your own game logic by the way, and you don't have to follow mine. So now he runs the camera, pans out. When he stops running, the camera zooms back and if he jumps and hold down the ladder or I mean the hanging sheet. Well, I didn't see much change in that y o because we haven't added it to the state. So let's go ahead and add a states or new state, climbing and climbing the ladder. Saved that back. And now let's demonstrate. Don't forget to add the states or now we run, we zoom in, we jump and it zooms in. And when he gets to the top, it zooms back out real quick. And I don't like that effect. It needs a bit more change, but not to worry about it. We'll figure that out later on when we tweak our game. I hope you enjoyed the video. I hope you had fun in this section. And as a last thing we'll do is we're going to commit our change. As you see, I've been committing it all along. I hope you are too. So we'll create animated driven states with an exclamation mark because we've finished the section. You've been amazing. I want to congratulate you and I want you to take a second to appreciate all the hard work that you've been doing so far. So give yourself a high-five and I'll see you in the next video. 34. Section 5: Adding Enemies And Bombs - Making Enemies: Welcome back everyone to a brand new video and a brand new sections. So this will be a bit of a longer video, but it will be worth, because we are finally adding some enemies into R c. So as you can see here, our enemy, whenever we press on play, Go into the scene. Our enemy walks. And not only does he do that, he actually flips whenever he gets to a wall. As you can see him, he has a little crown on his head and he keeps bouncing and bouncing and bouncing left and right. Now, we can still we still don't have the ability to get hurt by them, but we'll add that very soon. I want two things from you. First of all, I want a lot of concentration. And the second thing I need is your patients. So let's go ahead and gets dark. Okay, so adding enemies. Finally, first thing we're going to do is we will go into the resources and import the enemy. Sprites will create a folder. We'll call this folder the enemy. And we'll add these protein to the enemy folder. Now what we're going to do is we're going to slice this up. We're going to make an animation out of them and we're going to create a new game object that's called enemy with sprite, a sprite renderer, a rigid body, a collider, and everything else. So we've done all those steps with player. So if you feel that you have the confidence and of course the courage, let's go ahead and do a small race. I'll be doing everything and I'll be talking about it so you can do it with me at the same time and we'll see who can get that done first, 0, K. Let's begin. So first thing we're going to do is we're going to go into the sprite will make the pixels per unit. Let's go ahead and make them 30. We'll make these private mode multiple, and we're going to apply that. We'll go into Sprite Editor and we see that we have 123456. Let's go ahead and get our trusty calculator. So we have 228 divided by six. That makes 3838. Let's go ahead and slice it up. It's already 38 by 28. Click on slides and they are perfect. Apply that, go back. And now we have our sliced up sprite. Let's go ahead and create an empty game object. We'll reset it to its original place. Let's put it here on the platform, and let's go ahead and rename it to enemy. Now we have an enemy game object. Weight. It didn't rename enemy. Please enter, and now it's an enemy. Let's go ahead and add a sprite renderer to our enemy and will choose a default sprite for it. And now we still can't see him because we need to create some layers. So let's go and add a sorting layer to our enemy. We'll call this sorting layer enemy. And we'll put it between the climbing and the player. So it's going to be rendered and floods in front of the background, but behind the player and the foreground. Okay, that's done. And now go back to enemy, make the sorting layer on this product as enemy. And there you go. We have our enemy present in the scene. Let's make him a bit bigger. I want to make I think 22. Let's make him 22. Okay. Now he's bigger and looks kind of better, bigger than the player. Excellent. Next time we're going to do is we'll add a rigid body. So Rigid Body 2D component will make him kinematic. And we're going to add a collider to our enemy. So I'll choose a capsule collider will also frees the rotation on the Zed for the rigid body. Close that up. I don't think we need to do that. I'll just do that for the sake of doing it, just in case. So let's go ahead and edit the collider will make it small. We don't need to make it big. And this is the collider that will determine when our player gets hit. So I'll make it small, as small as possible while still making it fair. So I think just about yea big is good enough. So just like that. Oh, okay, great. You don't want to add a big hit box to your enemy because that would make the game a bit unfair. Okay, now we're good to go. Okay, so casual cloud, what else do we need? Well, we need an animator on the enemy Gn, and we need to create an animation. So let's do that. Select the sprites, right-click and create the running animation. So running. And let's go ahead and take it to animation folder. But first thing we need to do is we need to go into animation and create a folder. We'll call this player to start organizing everything so we don't have multiple runnings. And then we'll create a folder and we'll call it enemy. I love creating folders. It really gives us a very organized field to our game and our hierarchy. Now inside of the enemy, inside of animation, we're going to create an animator controller and name it enemy. Then we'll go back into the sprites and get our animation, put it inside of enemy folder, and we'll add it to the animator here in our panel. Okay, one more step. We have to add the animator to the Animator and our inspector for the enemy saved that. What else do we need? Well, we have everything, so let's go ahead and demo. See what happens if that worked. Coping to the scene view and our enemy is not doing anything. Why is that? Well, I think because he's not looping. Save that, go back into play mode. Look for scene, and now our enemy is running. A very, very, very cool. Okay, great. Now what we'll need to do is we'll need to add behavior to this enemy and make him go, at least right now to the left side of our screen. So we'll create a script for the enemy, and we'll call this simply enemy. So enter mean create a new script was the name of enemy, create and add weight for Visual Studio. Why did it open? Okay, now we have the enemy script go back into assets and put the enemy inside of skirts so we don't lose it. Okay, thank you. Visual Studio. Why do you keep opening up back into the scripts now, double-click on enemy, and now we have a brand new script for enemy. Yea. So what do we want to do? Well, we want to make our enemy move, at least for now to the left. Why is that? Why is the left? Well, because described by default is looking to the left. So let's go ahead and do that. First thing we'll need in order to make our enemy moves to the left is to create a rigid body reference. So we'll create a rigid body to the variable, which we'll call enemy rigid body. And we'll get the component right here in the start. So any rigid body equals equals o, what's minus four equals get component. And it's a type of Rigid Body 2D. Next thing we'll need to do, an update will make our enemy rigid body are run to the left. That means that we will write enemy rigid body dot velocity equals new vector two. And what should we write inside vector two? Well, we want him to move in the left, on the horizontal plane in the left direction. So will only be adding something to the float x nought to the y. And since we're adding something to the X and it's different at say, flow class, go ahead and sterilize it. So make a serialized field. It will be a float and we'll call the, this enemy run speed. And let's go ahead and make it. I don't know, maybe five F We can change it up anytime you want for now, let's make it five F, and let's add it to the enemy Ron speed. But one thing, and in the y direction, it's going to be 0. And but one thing you have to keep in mind is that because we are going to the left, that means the velocity should be negative. So we'll put a minus just behind enemy run. Save that. Let's go back into Unity and see if that worked. So save that, save everything. Click on play. And let's make sure we seen and now our enemy runs and runs and he keeps running behind the foreground. And he, Where are you going? Oh, wait, wait, wait. Okay. So at least it's working. Now what we need to do is we need to make our enemy flip whenever he gets to the edge of the platform. That way he goes round and round from one side to the other. So he'll run to the Edge, Hill, flip on that edge and run back to the wall. And whenever he gets to the wall, he needs to flip again. And that is part of your challenge, or your challenge is to make the enemy flip. Now, this is not an easy challenge because when the enemy reaches the end of a platform, we need to make them turn around and go to the other direction. So I'll give you a couple of hints. First of all, you need to flip horizontally like we did in player. You'll need to use a collider to determine when to flip. So you'll need to add in another collider to the enemy. And that collider will know whenever we reach a wall or we enrich the end of a platform, you'll need to, well, that's the box collider that you'll need to add in order to detect the collisions. And I'll give you a big hint. That big hint is to use something called On Trigger exit. Now we haven't covered on sugar exit or enter yet. But I'll do, I'll give you this big mega challenge in order for you to discover something new. Because as I've told you, my goal is to make you an expert problem solvers and not just watch me create a game and research everything for myself. So simply give you the resources and the documentation and show you that right now. So it's a collider 2D, which would be of course the collider, the box collider that the enemy has. It will use something called Onsager exit to d, which takes in a collider 2D. So if you read the description, it's sent when another object leaves a trigger collider attached to this object. So whenever we leave with our box collider, something which should be the ground or the wall. We will have the ability to do something inside the non-trigger exits. So let's get this done. But first, pause the video and go do the Challenger. Oh, okay, welcome back. So how are we going to do this challenge? We need to flip our enemy. First thing we're going to do is we're going to add a box collider to this enemy. And this box collider will be representing something called a Periscope. So if you don't know what a Periscope is, it's something used in the submarines. Do you know what a submarine is? It's a ship that floats or not float actually that swims at I'm not sure if it's cold, swims underwater and it has a Periscope. And that periscope is like a lens that goes up from the ship and it can look over the water. I'm sure you've seen it in cartoons or in some kinds of movies. And we call this one a periscope because it will be kind of like a submarine but reversed. So this box collider will make sure that we are exiting through the platform. So if we take our enemy right now and we start moving him, so he moves, moves, moves, moves, moves. And whenever he gets to the edge right here, okay. It will trigger the non-trigger exit, which is a function that will flip or a twelv flip inside of it. But the entrepreneur exit is used whenever our box collider exits a certain thing. So whenever that happens, we need to flip the sprite to minus1 and then our enemy will start running the other direction until he gets to the wall. And when he gets to the wall and exits through the collider, then again, we flip one more time and he goes back to the other side. And why does this work? Well, because as you can remember, on the foreground we have this. Where is it the compost collider? We have this composite collider, and that's how the entrepreneur exit works. Whenever our Collider or the collider on the enemy exits through, for example, here, this wall right here. When it exits through it, we will trigger, we will use the entrepreneur exit and whatever is inside of Onsager exit, which will be our flip sprite will execute and our Player sprite will flip. Okay, so I hope that wasn't too confusing. I'm not even sure. So let's save that. Let's go back into Visual Studio and let's go ahead and start with. First thing we'll do is we'll create the Onsager exit. So if we simply go down here and start writing on trigger, Visual Studio are amazing and best friend gives us a lot of suggestions. And one of them is on trigger exit too. So now what should we write and south of the arm trigger exit, first thing we have to write is the flip sprite solving side of the entrepreneur exit will create a function which will be flip sprite. And this flip sprite is going to be pretty similar to that of player. But the only difference is, is right now we are, we don't actually have any running horizontally or velocity, or we don't need to check for anything because all the movement is dynamic. So the only thing that we'll need is this line right here, which checks for the direction or the sign of the velocity on the rigid body. So let's go ahead and generate the method and simply paste this right here. And one more thing we need to change is the enemy rigid body. Ok? So now whenever we trigger the entrepreneur exit two D will go into the flips pride, and this flip sprite method will check for the enemy rigid body dot velocity dot x sine. So based on that, it will flip the sprite. O kay, caret. Next thing we'll need to do, and now this works perfectly fine, but the only problem is our enemies still goes in the same direction that he's going because we haven't changed how he runs. It's still an update. We have our enemy that rigid body velocity is still in the same direction. And in order to fix that, we are going to create a method that is called is facing left. So what is this method? Let's go ahead and created and we'll see what it does. It's a Boolean. It will be a Boolean and it's called is facing left. O case. So what is, is facing left? Well, it's a Boolean that will return the transform or dot local scale dot x. And it will check if that scale is bigger or smaller than 0. Why is that? Well, because if we go back into your unit, him and we look at our enemy, we can see that whenever he is moving left or is he's facing left. Up here on the transform, we see that his scale is one. So if he's facing left and that means his scale is bigger than 0, that means that the function or method is facing left returns true. And if he's not facing left is if he's facing right, that means his scale will be minus one. That means it will return false. And how are we going to use that? We're going to use that right here in the NMI dot rigid body or here in the update. So let's go ahead and do that. So this is facing the left will check for the transform dot locals kale and dot x of course. And it will check if it's bigger than 0. So effect is bigger than 0. This will be true and this function or method will return true. And that means if is facing left, is facing left. We will make, we will make our enemy go in the left direction. Else. That means if he's not facing left, let's go ahead and copy this. And we will remove the minus sign. So let's remove this, make it all tighty and good. And let's go and check if that even worked. So we'll put the enemy right here. We'll click on play. Let's go into the scene. And it didn't work at all. Why? Where the hell did this guy goes? So if he reaches the wall, he also doesn't do anything. Why is that? Well, I think that's because. Our enemy doesn't have a layer yet. So let's go ahead and add a Enemy layer. So enemy layer. And save that. And we'll go into the matrix and make sure that our enemy only interacts with the player and the ground. So save that. Let's see if that works. Now, go back, click on play, check arsine and our enemies still goes and he keeps going until he reaches the climbing. So what's the problem? Problem is that we actually should make this box collider right here a trigger. And that is the very important, and I forgot to do that. And why is that important? Well, because of the name of the function that we're using, it's called On Trigger exits. So this enemy must be a trigger. I mean, the box collider on it should be a trigger. So if we go back well, let's put him in here so we have the time to check for the enemy going to sin and he should flip and he does end to the wall. He also flips. And if he goes back, he also flips and everything works perfectly. So let's review the code just a little bit because I know it might be confusing. So our enemy has a NME Ron speed and that enemy Iran speed is constant every time, but it own knee changes directions based on the direction our enemy is facing. So what we did is we used the is facing left function or method that checks if our player is facing left based on the transform that local scale 0.8x. So if our player is facing left, scale will be one and his direction will be to the left. Hence we put a minus next to the enemies Ron speed. And else if he's not facing loved, that means he's facing right. That means his local scale is negative. That means the urine speeds should be in the right direction. Next thing we did is we created a on sugar exit. And this entrepreneur exit is activated when other our box collider that we've created as a periscope under our enemy. It, whenever it exits a certain, what should we call it, a certain Collider. Whenever it exits that, it is triggered and whatever is inside that method gets executed. And what we've put inside of it is a flip sprite, which flips based on the enemy rigid bodies velocity sign. So I hope you enjoyed the video. I hope it wasn't very confusing. I know it was a long one. So thank you for bearing with me and I'll see you in the next one. 35. Player Hit: Back everyone to a brand new video. And in this video we are going to make our player vulnerable to our enemies. Now, whenever we touch our enemy, you can see that we fly away and we play a small animation that turns us white and we can't actually move for about two seconds. So if we try to move right now we can't, but after two seconds, we can't. So this video is also a bit long, but it's also very, very worth it, cause we are starting to create mechanics for our game. So let's not waste any more time and let's get started. A. So I'll start off by giving you a challenge. So your challenge is going to be to create a dramatic head. So when player touches the enemy, We need to trigger some kind of kicking. Fear will need to change the players animation. And we'll need to stop the ability to move for two seconds. So I know this is a hard and we're standing up for the challenge, but I'm sure that you are up to the task. So pause the video right now and go do the challenge. Okay, welcome back. So before we get started, first thing I want you to do is I want you to go into the ripple, go to version control or source tree, and go ahead and stage all from the previous video. We didn't have time to do that, so let's go ahead and call this added enemies and made them around. Okay, that's enough comment that, and now it's saved in our version control. Let's go back into Unity and let's think about what we are going to do. Well, we want our players to get hit whenever he touches the enemy. So go into the player script and let's see what we are going to do. First thing we'll do is we'll add a method that's called layer hit. And this player hit should only be called whenever our player is touching the enemy. So we'll need to go ahead into the unity. And something we need to do before is make our enemy, the enemy layer, on the Enemy layer. And another thing we can do, we can actually prefab are enemies or now we have a prefab of the enemy because we already have everything set up in him almost. So let's get back and let's see here. So player hit can only be called if our Box Collider, 2D dot, nope, I'm And my box collider. So my box collider, whereas it, My Box Collider 2D dot is touching, is touching layers. Sorry, I don't know what's gotten into the Visual Studio. So it's touching layers, layer, mask, dot get mosque y. What didn't make it capitalised? Ok, so now Layer Mask, dot get Mask. And finally, we can add the enemy right here. And because it's a string reference, we go to the enemy, click on the Add Layer and find the string preference for enemy. Go back into Visual Studio and at that, now open up the brackets. Now if you're curious how I'm moving this. Well, actually I highlighted on hold Alt and I press the up arrow. And now an order to indented to the right, we simply click on Tab go rate. Now let's go ahead and generate this method. We have a player hit right now. And what should we do inside of the player hit? Well, what we want to do is we want to first of all, our player in the year. So let's go ahead and create a variable for that. It will be a serialized field. It will be a factor two. It will be a factor two because we want the player to get kicked in the x direction n and the wind direction. We'll call this hit kick. And it's going to be a new vector to, with what variables should we make it? What, how hard or how high should it be? I think 50 F by 50 F is a good kick. We can we will be able to change it up in our Inspector later on, so no worries. Let's go ahead and delete this. And we're going to add this hit kick to our rigid body velocity. So my rigid body velocity, dot velocity, okay, is going to be hit kick. But that's not enough. We want to multiply it by something and that something is going to be our I'd just write it out and I'll tell you what it is. So it's going to be minus transformed dot local scale, okay? Dot x and one f. So save that and let me explain what this means. First of all, of course you understand what hit kick is, but why are we multiplying? It was a new vector two with the minus transform lot local scale. Well, let's say for example, our player is walking towards the enemy. So let's take this player and he's running towards the enemy. So his scale is one. So if he gets hit, he will be launched into the air. Okay? But the problem is that we don't want him to launch into the enemy. We want him to launch away from the enemy. So that's why we've put His, we've multiplied the hit kick by a new vector which is minus transform dot local scale. So that way He's facing the enemies that way, or from the left side, okay? Or in that direction, he will get hit by a minus one and he will jump to the left. Or, and if he's from this side and his scale is minus1, he'll be sent to that side. Okay, so I hope that explains that. So click on play. And let's see if we let the enemy goal, we touched him and we jump away. So let's see that again. And he actually got stuck into the climbing. Let's get another hit. And let's see again one more time book or gay, correct. We can, maybe we'll change the hit or the force of the hit later on. But for now I think it's good enough. So if you at this point feel that you have everything under control and you want to continue to challenge alone. I encourage you to do that. If not, let's continue on. We are going to be importing our head sprite from the resources that I have loved you. Let's go ahead and put them inside of where are the sprites inside of the Conqueror sprites, great. So this is the head. We are going to make it 30 pixels per unit. We are going to make it multiple. We are going to apply that and go into the sprite editor. We will grid by cell size, and I will leave this was 58 by 58 with a 20 pixel padding slice that up, perfect. So 58 by 58 with 20 padding, apply that. And now let's go ahead and create the animation for our players hit. So go into animation and we'll, what should we call this? Well, getting a hit, Save that, and move it to the animation folder and to the player folder inside of animation. And what will we do now? Well, we're going to add it to our animator. And how are we going to make the transitions right here? So we are going to make the transition of Getting kid from any state. What that does is where whatever our status if all play as running is jumping is. I don't know, climbing, idling. If he touches the enemy, he needs to trigger the getting hit and trigger the animation of getting hit. And let's see the animation right now. If we getting head, let's see that. Oh, okay, excellent at works. Fine. And what should we do? Should be looping. No, I don't think it should be. So whenever our player gets hit, its b can be from any state And then he should transition back into idling. And let's see how should we make those transitions. So as always, we'll turn the transition duration to 0, so it's instant, instantaneous. And we need to of course, add a condition here which will be a trigger, not a Boolean because we don't need to get back. We only needed to be a trigger. And we'll call this hitting just to stay consistent with the triggers above it. And now we'll add that condition right here, and we'll see how we will be using this trigger instead of the Boolean. Next thing we'll need to transition back into the widening, and I think we'll make that transition to. Let's see how that will that transition B. First of all, this would be 0 right here. So save that. And to go from the hitting into the back to the idling, I think we are going to make the duration time. We can actually make it, let's say one. Okay? So whenever the hitting, getting hit finishes or we can make it to, for example, we'll see how that happens after we actually stop the player from moving. So let's go ahead and save that and go and trigger the animation when we get hit, the way we do that is by getting our animator. And instead of set Bool, we are going to use this right here. That's called set trigger. And it takes also a string reference. So let's go get it. Hitting Control C. Well, nope, not here. And Control V. And now our animation should be triggered. And because we've added an exit time, it will exit all on its own. So click on play. And let's see if that works. So our enemy there and we get hit, and as you saw, we play the animation. Let's do it again. And we're back to idling or gay, great. Again. So let's stop that. Let's move on to the next step, which is, let's see, our challenge again is to stop the ability to move for two seconds. So how are we going to do that? First thing we'll do is we'll create a variable right here that will be a Boolean. And that Boolean is going to be something that we'll call is hurting her. Think, ok, and what does this hurting do? Well, first of all, it's going to be false when we start the game. And what should this variable do? Well, inside of update, if is hurting. So if our player is hurting or free negated, so we'll add an exclamation mark. So if our player is hurting, hold down Alt and move it up and press Tab and everything is great. So if our player is hurting, we do not want to be able to run, jump, climb or anything. We want to stop our played dead in his tracks. So what we've done here is we've created a variable which is, is hurting, which will only, which will be true whenever our player gets hit and false later on will create something for it. So if hurting, if is hurting is true, this will make this whole statement false and we will not be able to enter the following methods. But if is hurting is false, the statement with the negating exclamation mark will be true and will be able to do all of that. So let's set, is hurting too true. Whenever we get hit. And let's see if that works. Go back into Unity, click on play. And we get hurt. And we cannot move anymore however, we try. So let's click on play again, exit and go back to Visual Studio. So now what should we be doing? Well, we need to turn this hurting back to false. And how are we going to do that? After two seconds? We're going to do that using something called Cole teens and what our coroutines. Well, it's a method that can suspend the execution of instruction until a certain condition is met or certain conditions with an s are met. So this suspensions are known as yield. And in our example will be used, will be suspending the time until our player can move again after being hit. So turning is reverting back to false. I have loved the unity documentations for coal routines in the resources so you can go and read all about them. But this is the main idea behind coatings. And coroutines are extremely important and unity the game development. So it's a great skill to learn. And let's go ahead and do a coating. So the way we initiate a call routine is the following. So we type in I, enumerate all. So I in numerator. We'll call this stop hurting. And that's it. Next thing we'll need to do is we need to write yield, return. And next thing we'll need is new. Wait four seconds. So now we can wait for a certain amount of seconds. And as we've said, we'll do two f because it takes a float. And after we waited for two seconds, we are going to turn is hurting back to false. And we'll be able to move our player again. Now before we continue, we need to call the routine. And the way we call co routines as we simply type and start co routine and inside of it, we give the co-routine name so it's stop hurting. Close down the parentheses, save that, and everything should work. Go back into Unity, click on play. And now we get hit with fly away. And after two seconds we can move back again and everything works perfectly fine. We get head, we see the animation. We stopped for two seconds. Now we need to tune everything of it because we keep running, but that's okay. We'll turn it later. So let's see everything here. And let's see what should we explain. So first thing we check if we are touching the enemy, and if we are touching the enemy will go into the play head. Inside of play hit, we add the velocity which is hit kick. And that hit kick is multiplied by the other direction that we are facing using the transform local scale dot x. We then set the trigger of hitting. We will set the is hurting too true, which stopped us from using all the methods inside of, inside of update. We then start a co-routine that waits for two seconds and then turns back is hurting to false. So I hope the video wasn't too hard. I hope it wasn't too confusing. If it is still confusing, go ahead and do it again and again, and make sure you understand what they call routing is, because it's very important. And I'll see you in the next video. 36. Drop The BOMB: Welcome back everyone to a brand new video. And in this one, as you can see right here, we have a bomb. And what does this bond do? Well, for now, it doesn't do much, but it does explode. So if we go near it, it starts burning and it explodes in a huge joined explosion. But our player doesn't get hurt yet. So let's not waste any more time and let's get started. O k. So first thing we're going to do, and the most important part of starting anything new is we're going to go into sprites and we're going to create a folder. So the folder will be the bond, and that's where we will be putting out pomp sprites. So let's go into the resources and get all the bombs prides that I've provided you with. And now we can see that we have born boom, bump on and bomb off. So now what we're going to do is we're going to create an object which will be a bond. So let's go ahead and create it. Will call this the bomb, and we'll reset its transform. And now we can find that right about here. Ok, good. Next thing we'll do, actually, let's go ahead and put it up here with our player up here, so we can put them next to each other and experiment however we want. Next thing we're going to do is we'll add a renderer. So renderer, whereas the renderer, and we'll need to add a default sprite. And in order to do that, let's go ahead and start slicing up our sprites. So let's choose multiple right here, even though it's only a single sprite, apply that go into these pride and let's sliced it, slice it up. It's 52 by 56, and that's how much we want our sprite to be. So I'm doing this very fast because you're already familiar with the steps. Go into the bomb, on, do the same thing, apply everything, slice it up, 52 by 56, apply, that came. And finally we have the Boom. Boom should be also 30. I think we'll make this bigger later on to have a bigger explosion. But the slicing will be the same. So apply everything and now we're set. So let's go ahead and add the sprite of the bomb. So it's simply bombed of and we can't see it. Why is that? Well, of course you already know it's because we don't have a proper sorting layer. So let's go ahead and add a sorting layer that we'll call bomb. And we'll make it render and front of the behind the player, or even just behind the foreground. So save that. And now we go back to bomb and choose the bomb, and now we have a bomb. Oh, okay, correct. Next thing we're going to do is we're creating animations. So let's go ahead and do that. First thing, we'll create a folder. Such an amazing video for the folders. So create a folder called Bombe, and inside of it we'll create, of course, animator controller will also covers animator controller bomb and simply drag it into bomb. And now if you click on the bomb object, you can see that we have an animator ready for us to use animations on it. So back to Sprite, choose the bomb sprites and go ahead and create an animation. We'll call this animation burning. Let's go ahead and drop it in bump animations. And let's go ahead and create the bone animation. And we'll call this animation also. Boom. Okay, add how many O's u1, drag it into bomb. And now let's go into the animator of the bomb. So what should we do now? Well, first thing we are going to do, of course, is we'll add the burning. And this burdening will go directly from entry. Then after the burning will go into the boom, but not, not like that. Before we do that, we actually need some idle state because as you know, the bomb doesn't trigger immediately. We want it to trigger at a certain time that we'll discuss later on. So first thing we'll need is we need to create an animation from just this single sprite. So let's do that. It allows us to do that and we'll call this idol idle Bob. And it will be a one sprite animation. We'll drag it into bump. And this will be the first an animation that will the first state if you want, that will be set from the entry. Next thing we'll do is we'll add the burning. And this burning will be triggered by some kind of trigger that will add. So if we add a trigger right here, we'll call this trigger burn. And finally we'll add the boom. And this bomb will be triggered or will go in the transition using something called the exit time. We've already talked about extra time, but we'll discuss it more right now. So let's go ahead and create the transition from idol bump to burning and burning to boo. So from idle bomb into burning, if we look right here, we don't need any transition duration and we don't need any exit time. All we need is a condition, and that condition would be our br trigger. Next thing we'll need to make the transition between the burning and T Boone. And this transition duration would be 0, but the exit time right now will be one. So we wanted to automatically transition from burning into exploding, which is the boom animation. And by exit time, if you hover over it, you can see that exit time in normalized time from current state. So what does that mean? If you look at the timeline right here, the way this animation will work as we move through burning. And finally, when the burning finishes, we'll transition into the boom animation. So it will happen automatically without our help. So if, for example, this exit time is not in seconds, it only measures the time it takes for the explosion animation. I mean the burning animation to finish. So let's say we add a two right here. You can see that it will take the amount of time of two burning animations to finish, and then it will do the book. We'll make it one. And what we are going to do is we will go, we are going to make the burning animation a little bit longer. So click on the bomb, go into animation, and click on the bomb in our hierarchy, go into animation and click on burning. Click this little arrow right here, and we can see that we have these sprites burning. So let's go ahead and copy them and choose the frame we want to paste in and based on that, and then again, pasted in another time. So now our animation as a little bit longer, if we click on play, we can see that our mom is burning and ready to explode. So everything is set. Everything works fine. I think that's save that. And what we should talk about next is the bomb mechanics that we're going to have. So what are our bound mechanics? So first thing when a player gets close to the bond, the bond will start to burn. Then the bond will have a blast radius. And if the player inside this blood radius, if the player is inside the blast radius, he gets thrown and gets hit, so he will need to get hurt. And finally, the bombs should disappear when the explosion is finished. So I tried to make this video in one single tape, but it turns out it's too long and I don't want you to get tired. So what we'll be doing is when the cover this one in this video, when the player gets close to the bomb and starts burning, and then we'll cover the bomb disappearance. So will explode the bomb will destroy it. And in the next video, we'll do these two points. And it's time for your challenge. And your challenge will be to continue the pomp mechanics. So first thing you need to do is you need to trigger burning when player gets close and you do that using something we call a ONE trigger enter. So first thing you'll need to do is add a box collider or any color that you see fit our bomb object. And you need to use something called On Trigger entered to D. Of course I've provided the link and the resources and it's, it's kind of similar to the entrepreneur exit 2D that we've used previously. Go ahead and read all about it in the unit documentations and use it. And next will have the bomb disappears when explosion animation finishes. So I'll give you a hand for that. Also, you need to destroy an object using destroy whenever the bomb explosion animation finishes. And this will be a bit tricky because we'll introduce something new. But let's, I'll give you another hint, which is events. So adding events and animations. Ok, so pause the video right now. Go do some research. Go try your best, and don't worry about making mistakes. I'll see you in a bit. Oh, ok, welcome back. So what should we do first? First thing we're going to do is we'll go into bombs. Were, we are already here and we're going to add a box collider. Why a Box Collider? Well, it doesn't matter. You can add any collider that you like. But for now we'll be adding a box collider. And I think we'll make this a bit bigger. So that way we cover. So when the player gets into this radius, it will start to burn and we'll make it a bit smaller right here, exit the editing mode and save that. Next thing we're going to do is we're going to create a bomb script for our bomb because we're going to be modifying its behavior. So create, bomb, New Script, and create and add. And now we're going to go into our assets and put this script and sag of scripts. I like to do this before we skip up Visual Studio. And I like to do this before we even click on the bond because it will present the some problem if we don't do that first. But anyway, let's go ahead and start our bombs script. So first thing we'll do is we're going to create an arm trigger enter to the method. And if we go into the resources, we can see here that it's sent when another object enters the trigger collider. So when an object enters the collider of our bomb, it will trigger this method, which is entrepreneurs enter to the, which is different from Onsager exits, which, which triggers whenever we exit the collider and before we forget, so we don't make the mistake we've done previously. We need to make sure that the box collider is a trigger. So save that and back into Visual Studio. So what should we do here? Well, as we've said, when the player enters the entrepreneur, I mean, when the player enters the vicinity of our bomb or enters the collision collider on the bomb. It should start the animation. So first thing we'll do is we'll get a reference to our animator. So animator, and we'll call this my animator. And we'll get the component from the start, which will be get component animator. And we're set. Next thing we'll do is we'll trigger the Burn. So it's set, Trevor, open this up. And because it says true ring reference, we always go back and get it. So copy that, paste it, close that, save that. And let's see if that worked. So wait for unity. Click on play. And now if we touch the bomb, explodes, go rate. But let's do that again because I want to show you something. If we get close, you can see that this, these particles right here are still present. So what we need to do is we need to get rid of them. Ok. And before we do that, I want to make the explosion a little bit bigger. So let's click on bond, and let's go to animation, the boom. And let's choose this one. And I want to make it bigger. So click on this prides and let's go ahead and make it 15. See how that okay, it's good enough. Let's make it ten. Yes. A giant explosion. Yes, that's exactly what we need. Okay, great. Save that. And now how are we going to destroy using the destroy method? And if you go into the resources and Unity documentation, we can see that there is a method that allows us to do that. And what it does is it removes an object or component or S. So it will remove the bomb object completely from our scene. So we'll do that. And the way we'll do that is we'll create a function right here or a method. We'll make it void and we'll call it destroys bomb. And we will only do one thing and sort of destroy bomb and destroy. We're open the brackets and we will send the game object. And this game object represents the game object, which is our bond that has this mom script attached to it. So it's a very simple and easy reference for our bomb. Save that. And now the final step is where are we going to call this function or method? And where we're going to call it is from the book. And as I've told you, it's about events. So if we move right here and our frames, the last frame is where we want to eliminate the bomb. And if you look closely right here, you can see that we have this button that isn't telling us anything, but that is an event. And if we click on it, you can see it adds a little capsule right here, that is an event. And what this animation event allows us to do, it allows us to choose a function from the script that is attached to the bond. So if we click on it, we can see that we have either the entrepreneur enter 2D or the destroy bombed. We'll choose the destroyed bomb, and it's very simple. It's very quick. We'll save that up. We'll collect on play. And now if we enter the vicinity of the bomb explodes, and as you can see, it's destroyed. So we no longer see it in our scene. And also we no longer see it right here in our hierarchy on the left side. So exit the game mode and let's go ahead and prefer our bomb. So prefab the bond. We have it in our prefab, save that everything is good. And the next video we are going to be hurting our player and we'll be sending him flying off. So I'll see you in the next one. 37. Exploding Our Conqueror: Welcome back my favorite game developers to a brand new video. And in this one, we're actually going to make our bonds actual bombs. Because not only does it explode right now, but a free are too close to the bomb. It throws us away and we cannot move for two seconds until we can move again. And we can go there. So let's try again. Oh, the Balmer also disappears. So let's not waste any more time and let's get started. Okay, so now we need to hurt our conqueror whenever he, whenever the bomb explodes, next time. First thing we'll do is we'll activity updates right here. And we're going to create a method to do that. And that method is going to be void, void, explode, bomb. Ok. And what should we do inside of explored bump? Well, we'll need to check if our play is in the vicinity of the bomb when it explodes. And the way we are going to do that is using something in Physics 2D called overlap circle. As you can see, it has multiple parameters in it, but we'll use mainly the point, the radius, and the Layer Mask. And we'll also, as you can see right here, it has a return type of Collider 2D, which is helpful to know. And in the description you can, you can see that it checks if a collider falls within a circular area will also be visualizing the circular area. But first thing we need to do is we need to use the function. So it's physics 2D dot overlap over lap circle. So what is it? Where is it? So overlaps circle. And as you saw before, it takes the point which is the center, going to be our transform.py position. It takes also a radius. So because the radius could be variable, let's go ahead and create a variable for it. So it's serialized field, which will be a float, and we'll call this radius. And now the radius will be, I think three, f is enough. So let's go ahead and add a radius. And finally, we'll need to add a Layer Mask. Why add a Layer Mask? Well, because we want the bomb to only interact with the player, we don't want it exploding, anything else. So let's go ahead and add a Layer Mask. We already know how to do that. It's pretty similar to the astonishing layer, and it requires a string reference or let's go and get that from the player. Click on the layers, the add layers and simply copy the layer on which the player resides. Save that, and everything should be working fine. Next thing we're going to do is we're going to visualize it. And the way we're going to visualize is using the gizmos. As you can remember. Remember, the gizmos were used here in unity when we wanted to make our camera icon a little bit smaller. It's here on the top. As you can see, it's gizmos and we can affect many things. So what is gizmos? Gizmos are used to visualize debugging and setup aids. And the way it does that, it draws on the scene. And these are one of its static methods. And the one we're going to use is the draw wires field. So let's do that. And one other thing we'll need is this mono behavior dot onDraw gizmo selected, which we'll be using to an order to use the gizmo straw wire speed. So let's see how it happens. I know this might be confusing, but this is very important and it's not that hot. So private void and on draw gizmo selected, that's it. Next thing we'll need is the draw wires. So we'll write gizmos dot draw wires fear. And as you can see right here, the parameters are the Centre, which of course will be the transform dot position. And of course that it would need the radius. So we will simply give it the radius that we've created. And this is extremely hurtful because now if we go into our scene and we click on bond, you can see that it gives us a, what they call it a wire, a spherical wire right around our bomb. And now we know how big or small we need to make the radius. So a few drop here and the bombs script, you can see that you can increase the radius and make it smaller and bigger. And it's very helpful because it will tell us how big or small we want to make the explosion. Or at least the blast radius of the explosion. Ow, kay, so now we should start adding different behaviors to the player. Before we do that, I would just want to check if everything is working. So let's go ahead and create an if condition. And what should we put inside of the if condition? We should check if we actually got a player inside the radius. So as you can see, the overlap circle returns a collider 2D. So let's go ahead and put it inside of a variable. We'll call this player collider. It's going to be equal to this circle. So if Player Collider, this means if we actually find a, a player collider, we're going to print to the screen, hey, coach you running. Okay, so save that. And now if we go back into Unity, we should see something printed to the console. So if we go near the bump, it explodes, but we can't see anything. So why is that? Well, because we haven't called The explode bound yet. So where are we going to call the exploding bomb? And we're going to call it from an event using the animation event that we've discussed in previous video. And I'll give you a mini challenge. So I want should use the animation events in order to call the explored bomb when it explodes. So take this mini challenge right now, pause the video and try to do it. Oh, Came mini challenge. Time is up. So now let's go into up. Nope, that's stopped this back down, going to animation. Click on bomb and choose the boom animation. So let's see on which frame should we add it? I think it should be on this frame. Okay, so click on Add Event, and now we can choose a function, will choose the explode bomb. So we have destroy bomb, which destroys the bomb and explode bomb, which explodes the bomb. And let's try this again. So now our player gets near, it explodes. And in our code console we can see that we have, hey, CO2 running. Let's try this again, but not be in the vicinity of the bomb, so we trigger it, we run away and nothing prints to the screen. Excellent. So now we don't want to print anything. Instead we want to throw out player in the air. The way we're going to do that is also using something called rigid body dot add force. Ok, so this video, there are a lot of new things, but I've left everything in the resources and you can go check them out, read as much as you want about them. They are very basic things. No need to worry about it. So add force, very helpful function to add that adds a force to the rigid body. And as you can see, it takes a vector, three fourths and a mode. I don't think we'll be using the mode right now, maybe later. So a force is applied continuously along the direction. And this is what we are going to need. And as you can see, it's applied to a rigid body. So we've deleted the print. So now we're going to add a force to the player. And the way we're going to do that is first of all type and here they are collider dot. So now we need to get the players rigid body using this collider. And to do that, we will simply use the get component, which is super helpful. So the player collider will get the rigid body component off of him. So Rigid Body 2D that is present on this collider. And we're going to add a force to that rigid body. And now as you can see, we need a vector two 4's, and let's go ahead and create it. So as the radius, this force is also variable and can also be used from the inspector will call this a factor two and we'll name it the explosion force. Oh, okay, excellent. It's going to be a new vector two. And what should we give it a force of, it should be 200. Oops, 200 by Should we add in the y direction? Yeah, sure why not? So we'll add 100 F in the y direction. Save that. And now let's go ahead and put it inside of the explosion force. Closed there up, save all of that. And what else should we be doing? We should test this and see if it works. So now we stand next to the bomb. It burns and it barely moves. He moved I think half an inch or even have half an inch. So let's go into bombed and increase this to and let's make it 2 thousand just to see if it works. So now the bomb burns, explodes and moves our player a little bit more, but still not enough. We will make this seven thousand, seven thousand. Save that click on play. Come on, bomb explosion, throw us in the air. Ok. This is not bad. Southern 1000 is good. Ok, I think we shouldn't add any in the y direction, and let's add one and another 0. So this is 10 thousand saved that I think this should be enough. Okay, I think that's enough. And now it's time for your challenge. And your challenge is going to be to hit our player. So we need to hurt the conqueror if his inside the radius blast. And I'll give you a couple of hints. First of all, you need to make sure that the player hit is public because we are going to use the collider that we found to get the player script and access the player, hit and hit our player. So pause the video right now, this challenge isn't too hard. You're, I think you have all the necessary skills to complete it. And I'll see you in just a oh, ok, welcome back. So what we should be doing right now is we'll need to call the hit player, which will trigger the animation and cause our player to hurt. And as I've told you, I've noticed it's a private, so let's make it public. So we can use it from different scripts. Save the player, go back to bomb. And now we should write here, player collider dot get component. We access the, Nope, not the plane, we access the player. So now we have access to the script. And what we can do here is acts as the player hit, save that. And let's delete this row right here because it doesn't hurt our organization. And let's go into Unity and see if that works. So what's supposed to happen right here? That when we walk into this bump and that explodes, we should move a couple of feet away from it. And then we should not be able to move for two seconds and we should see the animation. So let's try it. Act explodes, whoa, and we can't move. And we saw the animation. Why is it so good? Okay, sorry. So did you see how strong that explosion rules? So let's try that again. That was unexpected, it explodes, we fly away and we can move for two seconds. Again. Let's try it. At explodes. We fly away, we can't move. And after two seconds we can. Excellent job. I'm not sure why. Then. Now our player flies away. We should configure the explosion EBIT more. I'll see you in the next video. 38. Adding The Attack Ability (How To Use Arrays): Welcome back, my favorite game developers. In this video, we are going to add the ability to R player to defend himself from the enemies. So if we click on play and we go down to our enemy as he's attacking us, we can punch him with the hammer. Of course nothing happens. But here we can say, haha, I've hit the enemy, so we punch him again. Of course, it still takes us out, but we can punch him right now. And in the next video we will kill the enemy. So grab on to your seats and let's get started. Oh, okay. So first thing we're going to do is we're going to be importing the attack sprites. So let's go into conqueror and let's go ahead and get the attacks sprites from the resources that I've left you. And let's go ahead and dissect. Or I mean, slice makes 30, make this multiple. You're pretty familiar with the procedure right now. So let's go ahead and do manual dissection. And how much should this be? Let's slice it up and see what happens. So slice setup, what is the matter? Why doesn't want us to slice it up, please? Oh, case or let's change this to 58. Now can we slice it? Ok, So this is too small, let's make it bigger. So I think yea big, which is 78 by 5878 by 58, slice it up. And now we have a deck sprites sliced. Apply that. And let's go ahead and create an animation for the animation, we'll call this decking. Great. Let's go and put it inside of animation and animation, we'll put it inside of player. So now in the animator, the animator of our player, we need to add the attack, the attacking animation. So drag that in the animator. And how are we going to make the transitions for the animator? I mean, for attacking. So attacking can be accessed from idling and from running. So you can attack while you run and while you're standing still. And of course we'll have a return back to those two states so you can run and kill all the enemies in your path. That means we are going to make a Boolean. And we'll call this Boolean attacking just to stay consistent with the things above it with the other triggers. So the transition from idling to attacking should of course have a transition duration of 0 and should not have any exit time. And the condition on it will be at attacking should be true. The same goes for running with a transition duration of 0 with no exit time and with conditions of attacking to be true. Now the transitions back should all have a transition duration of 0. And actually, you know what, attacking shouldn't be a boolean and it should be, yes, delete that. It should be a trigger and we'll call this tagging. I'll tell you why in just a second. So let's go back. Condition is still true right here, and the condition is working fine. Great. How helpful is unity? So now, when we go into attacking animation and we want to go back, we'll make an exit time and that time will be one. So when the attack animation finishes, we go back to idling or we can go back to the running if we are already running with a transition duration of 0. So save that, make sure to turn attacking into a trigger, not a Boolean. And let's go ahead and do a challenge. So your challenge is to make our player attack. We want our players to attack when we press a certain button. So I'll give you a couple of events. You need to use the get button down because it's pretty similar to jump. We want the attack to happen immediately. We are going to trigger attacking animation. And finally, we are going to use physics to the similar to the used and bond to get all and focus on the word all enemies in attack range. So we'll have to use not overlap circle but overlaps circle o. So the challenge, the first two things are not that hot. We've already done them, I think multiple times. But the hard part will be the physics to D because it has a raise in it. So if you feel that you can handle that, go ahead and pause the video and do the challenge. Okay, welcome back. So let's see if our attack animation actually works. So we click on player, choose the attacking. And let's see if that works. Let's zoom in on our player and click on play. Okay, so the attack animation is working perfectly fine. So let's close those down. Save all of that, and let's go into our player script and see what we need to do here. So we first need to create a method for attack. So let's do that. So what tag in here? And let's go ahead and generate that method. So to generate it, it doesn't. Okay, no worries. And let's go ahead and create our own. So private void because it hasn't any return value at Tech. Excellent, so now the squiggly red line should go away and it does. So what should we do an attack? First thing we're going to do is we're going to get a input from the player. So if cross platform, cross platform, input manager dot get button down, of course. And what should we write inside of here? Well, we should look at the inputs in our project settings or let's go there in Unity. And see you in the input manager, what we have to help us, and one of the things that could help us is the fire, which uses the left control or the mouse button 0. So let's copy, fire one more 0, I believe is the left most button. So let's copy that. Let's go back and let's put it in here between the two quotes. And let's open up our if condition and what should we write inside of f condition? First thing I think we should cover is triggering the animation. So my animator trigger and we should trigger the ad attacking. Let's make this smaller. That's go into an animator. Copy this back to Visual Studio. Click on that, save that. Let's see if that works. So click on play. And our player now attacks whenever we press the mouse button and stops, goes back to idling or to running. So if we explode your book, Cool. So now we can run while hitting and we can continue to run. And if we are standing idle, we can also hit and then go back to either. Excellent. Next thing we'll need to do is we need to create a hurt box for our player. And that hurt box will help us to determine the, well, use the overlap circle on the herd box in order to hit the enemies. So let's do that. First thing we'll do is we'll create a hurt box object. And you'll see why in just a moment. So let's go ahead and create the herd box. There it is. And let's reset the 0 right now, I mean the z axis. So now we have it in our plane. And let's see, we'll call this hurt box. And what we're going to do with this hurt box is we're going to actually child to our player. And you'll know why. Actually, I'll tell you why right now, as we have learned about children and parent relationships, the children go with the parents and we want the hurt bugs to always be attached to our player. So as you can see right now, if our player moves to the right, our herd box moves with the player and stays in the same position that we can predetermine. And we'll fix up the position of the hotbox later on. But now what we need is a reference to that box and our scold. And the way we do that is we'll actually create a serialized field that's created under here. So let's create a serialized field. And this field will be, is of type transform. So this will be a hurt box of type transform and we'll simply call it hurt box. Save that if we go back into Unity right now. Okay, go back into Unity. And if we open up the script on player, we can see that we have a place to add our herd box. So let's simply drag that in there and put it inside. Let's try to apply all of that. And now the herd box will be part of the player prefab. So if we look in prefab, we can see that the hurt box will be part of the pre-fab, which is very helpful. Okay, so what next? Next we'll need to add a radius, just like we did for the bond. So we'll need to create a radius for the hurt box. And let's go ahead and do that first thing we need to serialize field again. So now let's go ahead and create a float and we'll call this attack radius and this attack radius for now, let's just make it three and we'll see how we can fix that up later on. And another thing we'll do is we'll need to visualize the attack radius. And this will be a mini challenge where I want to go and get the onDraw gizmo and use it for attack radius. So pause the video and do the Menu Challenge. O K Min, challenge time is up. We go into bombs. Let's simply copy this and let's put it in the bottom of our player script because we will not be using it a lot. And one thing we'll need to change as the radius right here. So let's call it attack radius. And of course it will be not the transform dot position, but instead it will be on the list lead that it will be on the hurt box dot position. So the transform of our herd box and not the player. So now we go back into Unity. And if we click on the player, we can see that now we have the herd box and if we move it, VIP layers, hurt box, or the radius moves with the herd box. So what else should we do? Well, I think we should make the attack radius smaller because it's too big. And what, how will actually calibrate this is will go into the player's animations. We'll click on attacking. And by the way, you can do this however you want. But for example, I wanted, I want the radius to be exactly as big as this hammer swinger, maybe a bit bigger. So let's put it right here and let's make the radius smaller. Okay, so like that. And, and I think this is enough. Yeah, I think this is good enough. Or maybe we can just push it just a little bit to the right. No worries about that. It will not be noticeable. And in fact, to be even better because we'll hit the enemy from a distance and yet still feel that we've hit him the correct way. You can calibrate, calibrate that during gameplay. No worries about that, as long as it works properly right now. Okay, what else should we be doing? Well, now we need to check for the enemies, enemies inside of this head box. And the way we're going to do that is using the overlap circle. So let's go and try to do that and attack. When we click the fire button, we, we trigger the attacking animation. But what else will be doing is we'll be using, will be checking for any enemy that is in the vicinity. So physics 2D, dot overlap over lap all. Whereas it over circle all. And let's open up and see what it needs. So first of all, it would need the point which will be, of course the hurt box dot position. Next thing it will need the radius, which will be the DAC radius. And finally, it will need a layer mask. So let's go ahead and add the layer mask of the enemy. And we'll, even though we know how to write enemy and it's super easy, but as always, we go and get the string reference I've cited, I think almost 1000 times now. So I hope it's really ingrained in your mind and I keep saying it because I've I've spent hours and hours trying to figure out what the hell is wrong with my code. And it was all because I written the string reference in the wrong way. So just saying, anyways, for now, let's see what we need to do is if we hover over this overlap circle, all we can see that it returns a collider 2D. But it doesn't just return a collider 2D. It returns an array of Collider 2D. You know, it's an array because of the little brackets that are present two right here next to the collider to the. So let's go ahead and talk about a raise. What are a race? Well, I raised, allow you to store multiple objects of the same type in a single variable. How does that work? Well, we declare them just like we do with variables where we have a type, we have a name, and we have the value that we give to these arrays. And the only difference between a race and normal variable is these two brackets right here. So this is basically an array. It's a collection of objects with the same type. So as you can see here, we have integer and it's an array, it has a name, it's the number of enemies, and the value are 461171. And another note that you need to keep in mind is that the, these values are counted from 0. So this is the 0, this is the one, the two, and the three. So it starts from 0. This is very important to remember and to keep in mind. And I think that is very associate associated with arrays. And something that we'll be using right now are loops. And we'll be using for each loop. And there are different types of loops, but we'll talk about the for loop and I think in a couple of videos later on, but for now we'll be using the foreach. We'll explain that for each. The for-each loop allows you to go through each thing in a collection of things of the same type in a array. So for example, this is not an example, this is the structure. So this is how we write it. It's a foreach. We have the type, we have the thing which should be of type, what type? And it's inside in things which is an array that has objects of type, this type right here. And what this does is it helps us go through each thing in things and do something to it so we can apply a method, some kind of method to that thing. Or we can use that thing in a method or we can execute other things outside the realm of the methods that they have or whatever. So let's go ahead and do an example and see how that will be helpful in our code. So we go back into our visual code and let's go ahead and create an array right here, which would be of type called 2D. It will be an array using those brackets and we'll call these enemies to go, to hit equals this one. So now we have an array of enemies to hit. What we need to do right now is we need to go over each of these enemies and print out something. And by the way, a question I'm always asked, why are we using overlap circle? Oh, well, we'll using overdubs circle all because maybe later on you want to add multiple enemies that attack you at the same time. So we want to hit all of them and not just a single one and love the other one, attack us because that would be not very illogical. As you can see, our conqueror right here has a giant Thor ish, a hammer which will crush any big that tries to attack him. That's why we're using overlaps, circle all to get all the enemies in front of us. And lets go back right here. So let's go and create a for-each loops for each. First thing we'll need to do is we need to write a type which will be off collider to D. So the thing we can name it whatever we want with name it enemy. So, so every enemy in enemies to hit will simply for now just print out Haha, wait, no capitalized haha. I've hit you. I've hit the enemy with another two exclamation points just to add the drama. So save that, and let's go and see if anything works. So click on play right here. And we'll go down, find the enemy. Wait, wait. And if we hit the enemy and go into the console, we can see that haha, I've hit the enemy. So let's go ahead and try that again. When the enemy comes our way, we hit him and we hit him again. So we can see remove the collapse. We can see that we've hit him four times. No worries about that. Again, if we comes we hit them with the hammer of, of course, nothing happens to him, but still we can see that everything works perfectly fine. And this is a very exciting part of our game development journey because we finally have the means to defend our conqueror. And I'll see you in the next video. 39. Killing Off Our Enemies: Back my fellow game developers and this video, we have added the ability to kill our enemy. So now we don't just punch empty air. And now actually when our amine enemy tries to kill us, we kill him first. And as you can see, his squiggles on the ground just a little bit and then disappears. Okay, great. I hope you're excited for this video because it is amazing. We are finally killing things that are in our screen. We have the ability to destroy everybody. So let's not waste any time. Let's get started. Okay, so first thing we'll do is we'll be importing these price and sprites and slicing them up and doing the usual creating a time animation. So you're pretty familiar with that already. So I'll do it fast. So click on the debt and resources go and drag it into sprites. And sprites, put it inside the enemy. And we'll chop up the sprite. How big was the Run? It was 22. Interesting. I don't remember doing that. So 22 multiple applies sprite editor. How much should we splice this? So 64 by 64, nope, not good enough. But see 28 sliced up. Maybe more. See 32s rises up to beg. How biggest? 30, maybe no, bigger, bigger, just a bit bigger. What does that mean? Oh no, well wait, it's 1230 sorts for so I think this should be let's see. Nope, 36, come on. Okay. Calculator, let's see, 152 divided by four, it's 38. So 38, so close 38 satellites that up, apply everything and now go ahead and create the animation. So the animation will be dying and we'll put it inside of the enemy folder and animation. And we'll choose the enemy. And let's go ahead and add the dying. And this dying can be from any state. So let's zoom in just a bit to see what we're doing. This dying could be from any state, so we'll make the transition. And of course we'll add a parameter which will be a trigger. So it will be dy, simply Dai De Yi. And next thing we are going to do is will go into the where's that? Let's zoom in on our enemy. So our enemy now has the dying and will change the transition duration to 0 exit time. There is no exit time and the condition will be to die. So you are conditioned to dying is today. And the animation, if we click back on our enemy and click on dive, play that animation. Okay, cool. So our enemy dies and he looks. Perfectly fine. Excellent. How about we make it a second? So if we dies, he keeps struggling on the ground. We're not trying to be sadistic or anything. We just want to make the animation longer for our pleasure. Still sounds statistic to me. So control v. And again control V. And now our animation should look like this. So we dies and he keeps wiggling on the ground. Great. So save that. Everything works perfectly fine. I guess we've added the trigger and now it's time to create a method for our enemy to die for. So let's go into Visual Studio. And Visual Studio, we are going to go into the enemy script. And right here in update, we are going to add the dying. But before we do that, let's do a bit of organization to keep the update looking fresh. And we'll extract this method and call it enemy. Enemy movement. Gay and under enemy movement will create the dying. And how should this dying work? So let's create this. So it should be a public because we'll be accessing, accessing it from the outside. And it will be a void. And we'll simply call going. Let's go ahead and open it up. And excuse me. We don't need it and update. Just a force of habit. So dying, a great what do we need inside of dying? Well, for now, let's simply just triggered the animation. So do we have a reference to our animator? No, we don't. Let's go ahead and get it. So it's going to be a Animator. Animator, and we'll call it my animator. Just to make things simple, we'll get the component as always get component the animator. And now we have a reference. Delete that. Now we have a reference, do we? Yes, we do. So my animator will set the trigger and which trigger is going to be? It's going to be dy and let's go ahead and be wild about this and will not go and copy the string preference because it's a three letter word Ku. Next thing we'll need to do before we demo it, we need to check him player. And instead of printing something, we'll need to actually access the dying. So the way we're going to do that is because we are going through each enemy. Just as we did with the bomb. We are going to write enemy. So enemy, which is the enemy right here, dot will get the component. So get component. And it is going to be the enemy script. And from there we're going to use dying method. So save that and let's see if that works. So it will call the dying. The dying will set the trigger to die and our enemy will buy. So. Where our player, let's put them down there because we don't want to jump every time. Guess. Let's put him right here and let's click on play and see what happens. So click on play. Let's wait for our enemy to live and we portion. Ok, so as you saw before we went flying. Oh, whoa, OK. Take It Easy. So as you can see, our enemy has died, but he can still hurt us and he is still moving. So what should we do about that? Look, oh, he's still hurting us. So what should we do about that? Well, the problem is that all of his components are still working and you go into enemy. We can see that his captured collider is still working, which hurt us. His rigid body is still on, which gives him the ability to move. He still has the box collider, which give him, gives him the ability to flip sprite and go the other direction. So what we need to do is we'll need to turn all of those off. And the rigid body body types should be set to static in order to turn him off. So let's go and do that. So we'll get back into code. And next to dying after the trigger set will get the component for the capsule collider and will not need to create a reference up there because we will use it only once, so it's okay to get it. So the capsule collider, what should we do in order to turn them off? We'll set the enabled to false. And what that does is if we go into Unity, back into Unity and enemy right here, you can see that each of these components has a checkbox next to it. So when we write dot unable equals false, that means that we've turned off this capsule collider. Let's turn it back on and keep it applied to everything so you get the idea. Now we'll also need to turn off the box collider and will need to set the rigid bodies body type to static. If you want to do a mini challenge right now, go ahead and continue that. So you need to turn off the box collider and said the body type to static. Okay. Did you try to do them in a challenge? I hope you tried. It's just the couple of code, a couple of lines of code. So now let's go ahead and access the box collider. And this box called lighters and enabled will be turned to false. And finally, the rigid body, which we have a reference for what it is. It's the enemy rigid body weight. Why did I name my animator and a rigid body? So this is a great time to learn a new trick. So highlight this one by clicking, double-click. And if you hold control and press R, R2 times, you can modify it everywhere that it is present. So look at all the instances where we've called my animator. Look what happens now if we delete my and right enemy. It changes all the places where we've used this name. And that is so cool and extremely, extremely helpful. Ok enough of that, let's go into my enemy rigid body dot. And let's go ahead and type body type. And this allows us to change the body type. And Visual Studio helps us immediately by telling us that we need to type rigid body type two D. Click on tab. Now we have it. And we can choose between dynamic kinematic. And of course we choose static. Save that. And let's see if that works. So we click on play. Our enemy goes the other way, we punch it and now he moves just a little bit on the ground and he's did girl rates on now we have the power and we cannot hit him anymore. He can he can not hurt us anymore and does not move. Excellent. One other thing we need to do is we'll need to delete or I mean, destroy our enemy from the scene. So we need him to disappear up after two seconds. And that will be part of your challenge. And that challenge is to destroy the enemy. So wait two seconds and then destroy the enemy. You will do that. After I give you a hint, which is use coatings that we've learned in the previous lessons. So it's a great time to apply your coral team knowledge, which will be a very helpful skill in the future. So pause the video right now and go do the challenge. Ow, kay, welcome back. So let's go ahead and complete the challenge. First thing we're going to do is we will go into the dying. And here we are going to create a eye enumerator. So I in numerator. Numerator, we'll call this, actually. Let's just call it die or no, no. We'll call this destroy, destroy enemy. Okay, so now we will destroy the enemy and this will be a co-routine. That means we'll have to healed return and the new wait four seconds. And how many seconds should we wait? I think two is good enough. And after two seconds, we are going to simply destroy the game object. So as I've said, the game object, this game object is a reference to the game object, which has the enemy script attached to it. Save that, let's go back into Unity. And this should, in theory work perfectly fine. And we got head, let's try this again. So the enemy attacks and we punch him in the face to seconds. And he's still here. Why is he still here? Come on. Go away. Let's see what we did wrong. Oh, we didn't call the co-routine, so let's go ahead and start the coltan. I hope you didn't make the same mistake I did. And your challenge while you were doing the challenge, if you're doing the challenge, not just staring and waiting for me. So start coroutine, destroy enemy. And now we click on play. And we punch and nope, we run after him and we punch and two seconds later, he did. Oh, okay, great. I hope you enjoyed the video. I hope it was fun and I'll see you in the next video. 40. Section 6: Controlling Our Game - Adding Levels: Welcome back everyone to a brand new video and a brand new section. So as you can see here, things quickly got out of hand. We somehow have three levels. We have this teeny tiny level right here. Then we have this level one that we've been using so far, but I've been using so far, we don't know what you've created. And finally, we have this last level which is even weirder and even bigger than the previous one. So I am so excited for adding a new level store game and talking about level design. So let's jump in and gets dotted. Okay, so first thing we'll do is we'll go into our scenes, which we haven't been too much lately. And let's go ahead and rename this level 0 to level one. And it will ask us to reload, simply click on yes, duplicate that, and replicate that one more time. So now we have a level one and level two and level three. Let's go ahead and rename level 32 main menu. And now I'm going to teach you a very cool technique so we can load all of our levels and the same scene at the same time. The way we do that is actually very simple, but you have to be very careful when you do that. So first thing you do is simply click on level two and drag it. And now you have two levels and you can actually also go ahead and drag the main menu. So now you have three levels in the same scene in that are right now on top of each other. So how do we take them apart? In order to do that, you have to select everything and I mean everything and you have to make sure that everything in your hierarchy is selected for that, for example, for main menu, simply click on this arrow. If you don't see it, click on the w or click up here and drag it to the left or to the right. It depends on how you want to make it. But for me, for example, I want the main menu to be on the left. And then go ahead and do the same for level two. So I'm holding down Shift and I'm pressing on the last one right here and drag everything to the right. Okay, so now as you can see, we have these three level Simon simultaneously present in one scene. Now, why is this helpful? While, let's say for example, you want to make a series of levels. We can put them one next to the other and see how they flow and how they look from the outside. That E1 is bigger, one is darker ones brighter, one is dimmer, whatever it is. And a another good benefit for it. Maybe you want to create one big giant level. And that big giant level is a series of small levels. So you can go ahead and zoom out and create all those levels and see each one of them and connect them the way you want to connect them. So next thing we'll do is we'll see how each of these work. Because now if we click on play. Ok, so wait for that to load. We don't even know in which scene we are playing. And if we go back, we can see that we've been playing in all three scenes. Ok, so let's get out of the play mold. So what you can do, you can actually go, let's save all of that. So you can actually go, For example, in level two, right, the click on it and you can unload the scene. And that way it's no longer loaded. And for example, you can unload the level one scene. And now when you click on play, you'll be only playing in the main menu mode. I mean, Main Menu level. What else can we do? And here, I think it's time to make the main manual level. So in Main Menu, we won't have any bonds, we won't have an enemy. And the state-driven cameras will be simply turned off. Why is that? Well, now you will find out because we are going to take our player, put him here, and the Main Menu won't have anything on it. So I'm going to remove all of this. And the main menu will only have this drapes right here and this little column. And it will be an experimentation level for the player to just run around and jump in. And that's it. So do a level, I agree. I will create a level in about 30 seconds using, of course, the magic of editing. So see you in a bit. Oh, K. So welcome back. So as you can see, I've built this level very quickly. I've made a couple of mistakes and there's nothing fancy about it. Or player just moves around and jumps around and nothing very exciting, but this is the Main Menu level. So now what we're going to do is I'm going to issue you a challenge. And that challenge is to make three levels. So you'll need to create, first of all, a main menu. You can make it the same as me. You can make it different. You can remove the drapes, maybe just to have our player learn how to walk and jump and run. And the other one is to create a level one which you already have. You can tweak it, you can make it different. And finally, you need to create a level two. And that final level will be of your own design. I will not be showing you what I'm doing because I want shoe to create one. I'll only show you the final product. And next, you need to keep in mind that you need to make the progression logical between levels. So you don't want to make level too much easier than level one because that won't feel very progression. The player who's playing your game will not feel the progression. Will not feel the sense of accomplishment that he's on a second and harder level. So make sure you add more variety in your second level and so forth, so on and so forth. And finally, you need to determine where the end point of each level should be. So you don't want your player just walking aimlessly in the world. You need to know what is the point that he needs to reach in order to complete the level? So pause the video right now and go ahead and create two more levels. So welcome back. How did you create your levels? I hope you had as much fun as I have. So this is our main menu, so we select for King, never do that. We select all of the components on it. And let's drag it down here. And as you can see, we still have our world confined. So we can edit that and make it smaller. We can even delete it, but it doesn't even matter. So let's make it like this, make it smaller. And let me show you my second levels. So as you can see, I've created my level too. I didn't add any enemies or bombs yet, so I'll add them later on. But let me just show you what I've created. And this is, this is my players so I can walk him. So he starts of the level right here. He jumps down. He maybe I'll have an enemy right here with some, maybe a bump and a bomb right here. So the player needs to jump. There's a bomb here, there's an enemy right here, so it needs to quickly jump right to this platform. And then he walks, walks, walks, and then he jumps down here. Maybe there's an enemy that he needs to kill. Then he jumps right here, there is a bond, there will be a bomb right here. He jumps, he grabs on the drapes and starts climbing for his life. So whereas my player, okay, he starts climbing and climbing and climbing. Here will have some kind of diamond and maybe three diamonds right here protected by a peak NME waiting for him. So we keep climbing, Wikis keep climbing. And finally we get to this platform right here. And there will be the destination that the player needs to reach. And this is my level. So don't forget if you've created your second level. Don't forget to make the OR just the world confined there. As you can see, it's not perfect by any means, but it works. I've tried it and it works perfectly fine. So I hope you enjoy creating your second level and Main Menu. And what else should we do? Well, we should finally talk about something very important, which is level design. And it's very, very crucial that you understand the flow. So for example, right here, there's nothing too fancy. Well, this week we're going to give much thought to level one, but as you can see here, maybe we should have removed all the climbing ability and maybe not add bombs, for example. And then in the second level we add bombs and maybe in the third level we add bombs and enemies. And maybe you could get for, I mean, so every level should have its own flair. So maybe later on you can make platforms that are invisible. Maybe you can make dark levels and et cetera, et cetera. But for now, we finish the video. I hope you enjoyed it. Hope you gave your level much thought because it's the most fun part of creating games. It's the essence of 2D platform, so I'll see you in the next video. 41. Exit Door: Welcome back everyone to a brand new video. And in this one we're actually putting our game to gather because now not only do we kill enemies, not only do we explode, but we also have a dork. Well, it's not just adore, it actually opens up. And if we go near it and we click on the w, it closes and we actually go to the next level, as you can see right here, we have a level two. And in our scene, if we zoom out, we've actually went to the second level, which is very exciting and very cool and really gives authenticity to working. So let's not waste any more time and let's take our conqueror on an eight venture. Okay, so first thing we'll need is we'll need to go into this level two and set our player right here as the starting position. And the next thing we're going to do, we'll go to level one, see how helpful this is and we'll set his position, I think right about here. And that should be fine. So save all of that. And now let's go ahead and unload the scenes. So we'll unload level two and we'll remove it. Then we'll unload the main menu and remove scene. Save that. And next thing we're going to do is we'll need to visualize our level exit. And the way we're going to do that is by adding sprites. And before we do that, we're going to create a folder. So fun. So go ahead and name this door. Now, go into the resources and go and get all these sprites that I have loved you there. So go ahead and put them inside of door. And now we're going to slice those babies up. We'll make this 32 and we'll make it multiple, and we'll apply it and go into the sprite editor, slice that up. It's perfectly fine as the way it is. So it's 46 by 56. Apply that. Go into the opening. We actually have opening sprites and closing sprites. So make this 32 multiple apply, undoing this very fast because I believe you already know how to do all of that. So grid by cell size, the how much that was that it's 48 by 56. Nope, it's not used a calculator. Our trusty calculator sorts to 30 divided by 12345 and we get 46 or 4646 by 56 lies that up. Next thing, let's go ahead and slice up our whereas closing. So let's go ahead and make this 30 to make this multiple apply all of that got the sprite render and slice it up, Apply. And now we have a closing and opening. And so what are we going to do now? Well, we're going to create an object, and that object is going to be reset. And it's going to be called the exit door, which is the name of our video. Cool, isn't it? Next thing we'll do is we'll add a sprite renderer and we'll add it. A default sprite, which I think will be the idle door. And as you can see, we can not see it on the outside of the realm of our world. So in order to fix that, we'll need to create layers and you go ahead, pause the video and create those layers. No. Okay, so let's go ahead and add layers. First thing we'll add a layer, not a sorting layer, because we'll use it later on. And we're called the slayer in third doubles or just interactable. Okay. Did I write interactable correctly? So we'll copy that and we'll add a sorting layer B render in front of foreground. And I think in front of the bomb or not in front of the bomb. Anyway, it doesn't matter. Let's make it In front of foreground. And we'll save that. Let's go back and to the exit door, make it an interactable and it's sorting layer will also be the interactable. And now we have a door Ku. Next time we're going to do is we'll create the animation. So let's go into animation and do the best part of all. And now we go back into the door and we'll create the closing animation. So create an animation closing and will create also the idle. So it's a one sprite animation. Idle, no need to call idling. We already know what that is. And finally the opening. And let's go ahead and create the opening. Oh, okay, great. So let's go ahead and click on all of those and drag them into animation. And we'll take those again. And we'll drag them into the door. Next thing we'll do is we'll create the animator. So animator controller, we'll call this exit door. And outside of our animator, first thing will drag the animator and to the exit door. And now if we click on exit door, we have an Animator component that has been added automatically with exit door on it. So now what, what should we do in our animator? First of all, let's close out our handy calculator and go into animator, animator calculator, all within R. So now we're going to add idle. So the door will be idle when we starting gain. Next thing, we'll add the opening of the door and then the door will close because I have never honestly never seen a door that closes before it's open. That's a bad joke. And now we need to create the transitions. So we'll make a transition from idol and to open, and then from opening and closing. And now we'll add parameters to keep them in check. So let's go ahead and add a parameter which will be a trigger, which will open the door. And we'll add a parameter, I mean a trigger or a trigger parameter that will close the door. And let's go ahead and remove the transition duration, will remove the exit time and we'll add a condition which is opened that goes from idle to opening. And then in the transition from opening to closing, we'll also remove the transition duration, remove the exit time, and the close trigger. Save all of that. And now we'll need to find a way to change those triggers or athlete, or what I mean is triggered those triggers. And that means changing the behavior and that means coding calico. And now let's go and add a component. We'll call this exit door. Go ahead and create a new script and create and at, and we'll wait for unity to understand what one. Wait for it. Okay, great. Now unity is ready for our coding. So let's go ahead and add exit door to scripts. And from scripts, if we double-click who we will access the exit door. And now Visual Studio is opening. So what should we do now? Well, what even is the point of our door? Well, it's the exit door, as it suggests. So what we want is whenever we get to near to the door, we want that door to open up. And if we click a certain button, we want the door to close and we want to go to the next level after about two seconds. So how are we going to do that? Well, let's start off first of all by creating a way for us to open the door. And the way we are going to do that is using the On Trigger enter. So first thing we'll do is we'll need to add a box collider to our door and let's go ahead and see if that box collider. Yep, I think it's perfectly fine. And because we're using entrepreneur enter will make this a trigger. Save that. And before we go, I want to make sure something is that we only want this door to interact with player. So the from the input manager will go ahead and go into physics. And here we have the interact bubbles and our layer collision matrix. So let's go ahead and turn everything off except for the interactable between the player. Oh, okay, great. And now let's go to our code and start coding, which is my favorite part after creating folders. So we're in Visual Studio. We don't need the start and update for now. If we'll need them, we'll create them. What we need is an On Trigger enter to d. And for now simply on sugar enter 2D, we'll set the animation of opening. So will not need a reference to our animator because it won't, we won't be using it that much. So will simply go ahead and get the component, will get the animator, and will simply set the trigger, set. The trigger, and that trigger will be open and it's a string reference. So we'll copy that, put it inside of here, and we'll save it. And let's go ahead and demo. See that work. So our player moves. Okay, barely he punches and now door opens, but ok, so a small problem, we need to render the door behind the player. So let's go back and to the layers in the inspector. Go to add layer, will check the sorting layers and we'll make, whereas the interactable will make it render behind the player. Save that again. And let's see. Click on play. And now we run to the door, it opens up and it stays open. And okay. I thought something was wrong but because we are touching the climbing. Okay. Not no worries. So the door opens now we need a way to close the door back up. And the way we're going to do that is by creating another method. And that method is going to be called Avoid public amin, I mean, sorry, public. Why public? We'll find out in just a minute. Start logging next level. And why did we create this function before we, let's make this a little and login next level. Okay, great. So now what we want is we want to create a function or a method that will first of all closed the door. And second of all, we wanted to take us to the next level. So we'll need to use something called seen Manager. And you'll learn about seeing Manchu right now and will need to build our scenes. Depending on the levels. And what else should we do? Well, we will need to find out in which senior at, and we'll need to go to the next one. So first thing we'll do is we're going to set the trigger for closing. So animator, and we'll go ahead and set the trigger to close. Ok, never do that. Let's go ahead and copy it. Okay. Close. It's fairly easy, so it's close. So now the door closes. And next thing we want, as as I've said, we want to go to the next level, but not immediately. We want to go after, I think maybe two seconds. So that means we're going to create a co-routine. So start coating. And what should the name of the method B? And let's go ahead and create it. It's going to be an eye enumerator. I'm pretty fun. I'm pretty sure that you are familiar with our enumerators and coroutines, and we'll call this load next level. And of course we are going to yield return. New, wait four seconds. And instead of simply writing two here will create a variable that we can edit will actually make it a serialized field. And we'll call this safe load. And we'll call this second too low. And we'll make it two. And this is a much better way than simply adding a random number right here because it gives us the ability to control what we're doing. And finally, we're going to do what? First of all, let's go ahead and add the load next level right here to avoid any errors. And now what should we do? Well, first thing, let me teach you how to build the levels one after the other. So go back into Unity, go to File and click on Build Settings. And now in-built settling settings, as you can see, we have this scenes in built. And actually this is where you build your game and you can change the platform that you'll be using. That's why were we were using cross-platform actually, because now you can build up for a PS4, you can build it for an Xbox one, or Android or iOS, anything that your heart desires. And for now, let's keep it on this one. And here is where we add these scenes. And as you can see, we only have one scene right now in our game. And adding scenes is fairly simple. We go into our scenes folder and we simply drag the scenes that we want. And you will add them based on how you want your game to flow. So you won't be putting the level two above Level one because they go, as you can see right here, they are in a array or they have indexes which will go from 012. Ok, so now we've put our scenes in a build index and we can simply exit that. And now let's go back into Visual Studio and learn a couple of sin management. First thing we'll need, as we've told before, as I've, as we've done before, we've used when we wanted to use the cross platform with told it that we are using the Stan, Unity standard assets, the cross-platform manager, and will do the same when we want to tell it that we want to be using seen management. So let's go ahead and add that. And these are called namespaces. I'm not sure if I've told you that before. So it's Unity engine dot seen management. So now we can actually grow, go from one scene to the other. And the way we're going to do that is first of all, we'll get our currency. So where are we currently standing on? So it's going to be a variable, and when you're not sure what kind of variable it is going to be, you can simply write. Var. And that will be, well, IT will change depending on which variable it's given. So var, we'll call this current seen index. And it's going to be equal to senior manager. Ok, dot get active seen. So this will get us the current active scene. And not only that, but we'll also need to go and get the build index. So what are we doing here? Let me tell you one more time. We created a variable and we call it var because we're not sure what we are going to get. We're going to get an integer, but maybe we're not sure, so we can call it vd. Then we have the name which is the currency in index. And we can get the current scenes index by using the Scene Manager, which we can now access because we've added the namespace of using unity engine, using Unity engine scene manager. Then we go and get the active scene and we get it's build index. So now, because of this variable, we know on which scene we are residing. Next thing we're going to do just after that is we're going to load the next scene. And the way we do that is we use the scene manager. We simply write lope scene. And inside of here you can see that it gives us the scene built index. So it asks us which scene would you like to go to next? And the next thing we want to go to is the current scene. So it's the current scene index plus one. And this will take us to the next level. So everything should be working fine. We'll try it later on. But what you need to do right now is you need to do the challenge. And your challenge is going to be to access the start loading next level, which is an exit door from the player scripts. So we usually use the player script to access loading level method using a certain key or the get button down or you can do whatever you want. So a small hint, you need to make sure we access it only when we are touching the interactable. So you need to make sure that we are touching the door before you go and get it. And you'll need to use find objects of type, which is something new. We've never covered it. And I'm sure you can go and research it. There are many documentations about it, and it's fairly easy. It's not that complicated. So pause the video right now and go ahead and try to do the challenge. O k. How did you get on with that? And I hope it wasn't too hard and I hope you tried your best as always. So let's go into our players corrupt and in here that go up into the update. And let's go ahead and create an exit level. And this will be a new method that we will extract. So let's go ahead and generate this. We, I don't think we'll need to put it up here, but for now, let's keep it up here. So first thing we'll need to make sure of is we need to make sure that it's actually touching the interactable before we do anything. So if and if our Box Collider 2D, wait, nope. Why do I make that mistake? My Box Collider 2D dot is touching layers. And which layers are those? Well, they are the interactable. So let's copy that back end to Unity and let's base that. And oh, we need to add a Layer Mask to that. So click on space or Layer Mask, dot get Mask. And now inside of these brackets we can actually paste that. Oh, okay. And we'll close it up, but not, not, not for now. First thing we'll need to negate all the statement. So if we are not touching the interactable, we will actually access this if condition and we will return, which will simply go out of this method and will not do anything. What is it telling us this something is wrong? It's telling us that we have, okay, so I need another parenthesis and everything is fine. Next thing we'll need to do is we'll need to use the cross-platform input. So if cross platform input manager dot get button down, now you can use something different than get buttoned down. Maybe you want to use the axes, but I don't recommend it. So we'll use get button down for now. And what should we add to this string name? Well, I think I feel like I would like to use the inputs of the vertical. So when we, when we open the door, we can actually press on w or us to exit the level. And I think it's a good way. So let's go ahead and choose vertical. 42. Main Menu & Success Level: Welcome back, my favorite game developers. In this video, we are going to create a main menu and we're going to create a success level. So what are those? So success level, as you can see, is a weird level. If we go into it, we can see that we have a winner, winner congratulation message, and we can jump right here. And we have this main menu button that highlights every time you go over it. And if we click it, it takes us to the main menu at the bottom told us, and now we can also have, we also have this Start Game button, which if we click will take us to our first level and the door takes us to level two and so on and so forth. So I'm very excited for this video. I hope, I hope you are too, and I'll see you in a o, kay, so first thing we'll do is we'll go into the main menu and let's go ahead and click on our player. So as you can see right now, our camera, which is right here, if you double-click on it, it's right here. Our canvas is right here, and that is a result of us and moving it in the previous video. So let's click on our player and tile map and click on w and move that back into our view right here. So let's see going to the camera again, and let's make it a little bit bigger. So we'll increase the size from four to about yea big, which is good enough. Let's make it just a little bit bigger. And okay, so I think that is perfect. Cou, let's move this up a bit. Okay, save that. And now let's go ahead and create a button. So how do we create a button? While it's fairly simple, we simply right-click on here. In our hierarchy, go to U i, and choose the button which is right here. So as you can see right now, something very huge has been created right next to us. And if we double-click on button, we can see that it's some huge giant button and it's part of the even bigger canvas. If you've noticed something called Canvas has just been created, which houses the button and which has a text on it, and an event system. So what are all these things? So the canvas is actually what that holds, everything that we want to print on our screen. So the Canvas holds the button, text and any other UI that you have on your screen. And the event system is used in order to check for any click of the button. So let's go ahead and move the button right here. And we can look actually in our game view, and we can see that the button is right here. So let's do something cool and put them side-to-side. So now we can see where the buttons. But as you notice, whenever we move the screen, make it bigger or smaller, the button actually moves. And that is not a desirable effect. So the way we are going to change that, as we go into the Canvas, click on Canvas and go into the canvas scaler. And instead of constant pixel size, make it scale with screen size. So now however we move our scene, the button stays in its place. But as you can see, it's a bit of a weird movement. And why is that? Well, if you click on the button, you can see right here that there are many options and the most important one for now for position wise, It's the anchor. So the anchor, as you can see for the button right now, is the middle of the screen. And what we wanted is to be on the top middle of the screen. So now it will be more natural and depending on the movement of the button. So let's customize our button and I'll show you how to customize it. So click on the button and as you can see, we have this rectangle in here that will enable us to make the button bigger or smaller. So click on this blue circle right here, hold Alt, and you can make the button as big and as small as you want. Next thing we'll do, we'll change this button, this button text. So if we go into the button, let's go head. And what should we call this? Start game because this is on the main menu. And let's go ahead and also call this Start Game button. Okay, and we'll call this canvas the OK, the Main Menu canvas Cu. And let's go back into text and we can actually change the font of the text so we can make it bigger. We can change the font style and we can make it bold. And we can go ahead and change the entire font if you want to add some kind of font in it. We can also change the way the text is rendered on the button. And we can change the color of the text so we can make it green, for example, but we won't be making into green. And we can also change how the button looks. So let's start customizing our buttons. So first thing we have the normal color. Let's change that up and we can choose a color from our scene. So we'll choose this red color or something. I'm not sure. You can change the highlighted colors. So when our mouse moves over this button, it will be highlighted. So we'll change that to be yellow. Will go ahead and choose some coloring here. So this yellow, and it's very nice to make all your colors on the bottom the same as the colors in the scene, gives it a more authentic look. Next, we have the pressed color, which will make, let's see what should we make it? We can make the, yes, this is a good colour. And what else do we have? We can I guess it's basically that will change the color of the text. And let's go and change the color because I'm not liking the scholar allot. Choose a colour may be, it will be the color of the tiles, for example, not the good. Let's change up. Again. We'll choose some kind of yellow button. Okay, I guess that's good enough. It doesn't have to be perfect. For now it needs to work. So now you know how to add a button that's reset that and choose the potent and you can change the position of that button. I'm gonna put it right here at the top, in the middle. So if we go into play mode and wait for it to understand it. But now as you can see, we can click on the button up there while we move in our scene. Actually, let's make this game view bigger and scale it down so you can see everything. So now we have a button that we can hover over. And I think we need to change the color of the start game and we can click COOH. Now we need to start adding functionalities. Ok, so we don't want just a button right there that doesn't do anything. We needed to actually do some stuff. And the way we are going to add stuff to it is, well, you guessed it we are going to add a script to it. So if we scroll down, we can actually add components to the bottom. So let's go ahead and add the component, and we'll call this menu, and we'll create a new menu script. So create and add and will wait for it. And we'll wait for it. Okay? Now we go into the assets. We put the menu inside the scripts. And from scripts, we'll go ahead and go to menu. Okay, so now we have a menu script. Let's delete everything in here because we won't be needing neither this nor the update. What we will be needing as we'll need this button, as you've guessed it already, we need, whenever we click the button, we want to start the game. That means we will be going to level one. And what that means is that we'll need to load scenes, and that means that we'll need our scene managers. So let's go ahead and add using Unity engine dot sin management. So now we can use scenes. So let's go ahead and create our first method. And it's going to be a very simple method which is going to be void. And this method will load the first level. Ok, nothing fancy. And what will right inside of it? We'll simply tried to load the level one, whatever that level is. So we'll need seeing manager dot clothed scene. And we'll simply write in here the index of the first scene, which is one. Okay, because we currently on the main menu we are at seeing 0. Next thing. Order to add that functionality to our bottom, we need to go back into Unity and we need to click on our button. And right here you can see that we have something called On Click, and currently the list is empty. So let's click on the plus. And this will give a, how should I call it an, a mission for the button when ever week? So as you can see right here, we need to add an object to it. And that object will simply drag the button and it will be the start game. And currently we have no function. So if I click on this and go into menu, we can see right here that we should have. Where is it? I wonder where it is. O, okay, okay, so we need to make sure that this is a public method. So save that. And now if we go back into our button, we should see right here on menu that we have the load first level. So save that. And let's go into gameplay. And two came mode. And now we can run, we can punch and if we click on the start game, we immediately go into our level one. And if we go through the door to seconds later we're at level 20, kay caret. So now what you need to do is you need to complete the challenge. And your challenge is going to be to create your success level. So use the same formula we used for main menu to create the success screen. So you'll need to add a button and maybe some kind of text above it. And I'll give you a hint. The only changes you need to make is to the scene manager dot load C. So do the same for success level with its own button. But the only changes is going to be two script. And you can even use the menu to load the main menu. Only change we need to be to the scene manager dot load C. So pause the video right now and go do the challenge. Ow, kay, welcome back. So let's go ahead and create our success Green. First thing will go into seen will take the main menu and we're going to duplicate it. So now we have the main menu and Main Menu, one that's changed its name to success level. Now we have a success level. Let's double-click on success level, and it's pretty similar to our main menu, and that's the point. So let's first of all change the canvas to success, level canvas. And the start game button will now be the Main Menu button. Because after we finish the game and we go to the success level, we want to then have a button to take us back to the main menu. And now let's go ahead and text, and let's change the text to Main Menu. Oh, okay, great. I don't think we'll need to change the button color and whatever will keep it the same. But what we'll be doing is we'll be adding some text. Which will tell our layer that he has one. So as you can see right here, we have this text and it's small and here. And by the way, why they make the campus that big? Well, I'm not sure 100%, I live the resources in the description for the canvas. But I believe it's a way for unity to keep things organized. Because if you, for example, want to change things in our scene right here, it may be a bit cumbersome to move buttons around them, put text in places, in weird places. And it's also a way for humanity to use measurements or something like that, but it's not that bad, so no need to worry about it. So let's go ahead and change the text right here and we'll call this winner. Winner with two exclamation marks. And let's make this a bit bigger and we'll align the text in a different way, will increase the font size. Okay, that's too big. And we'll make the text color yellow. So it's like a trophy that they want. And now we'll make it bold. And we'll center. You know what, I'll make this even bigger and increase the font size. Oh, okay, cool. So now we have a winner, winner. Whenever when a chicken dinner, if you play Bob G. So now the text will be when are taxed? Nope, let's remove the capitalization when our text. And what else should we be doing? Oh, yes, now we need to make this main menu button actually take oh, and one more thing, excuse me. So will anchor this winner, winner to the top? Correct. Okay, where was I? Ok, we need to add a different functionality to the main menu. So instead of taking us to load first level, we need to now make it take us to the main. And as I've told you, the only one change and that is 2pi scene load. So seen load level. So let's go back and let's go ahead and create a new method right here. We'll make it public, void and load main menu. And the only thing that will change, it will be the same. So seen manager dot load seen at now instead of a one, will simply load the 0 and save that. And one other thing we need to make sure of is that we need to the success level to our built-in. So as you can see, we have main menu, nonzero level one on one, level two on two, and now successful be the save that. And I. Another thing we need to go back to the Main Menu button and make sure that instead of the function that previously loaded load first level, okay, first is written incorrectly. So first, First, I hope nobody noticed that save that, go back and it should fix itself. Nope. That's by the way, we will have to change it. So instead of the load first level, we need to go to Menu and we'll need to load Main Menu and save that. Let's go back into main menu and make sure that everything is correct. So start button on click menu. The function is load first-level, save that, go back to success level, and let's play and see what happens. So our player moves around, he punches, he jumps, and main menu, if we click on the button, it should take us to the main menu. And if we start the game, we start at Level one. Excellent. One other thing we need to do, let's change the success level just a bit to make sure that the player understands that we're in a different place. So let's simply remove the sheets right here. And let's go into foreground. That's remove those. And let's add something cool to it. Let's remove the background here. And we'll click on this one on background. And let's draw something like that. So just a bit of background. And let's go into foreground again. And we'll simply add this one right here and this one right here. And this should give the feeling of being an infinite level. So now, if we save that, if we go into the play mode, we can see that, okay, it feels as if the game is infinite and if we jump up here, we can leave, which is very cool. And if you want to play around with stuff, you can actually make, add a box collider to this button and the player can stand on the button and then click Main Menu and then start game and then play the game. So I hope you enjoyed the video. It was not very hard video, it's easy, it's just about UI. You can go ahead and experiment and add whatever you want. So have fun, and I'll see you in the next video. 43. Game Session: Come back my favorite game developers to a brand new video. And in this one we've added pressure. So what do I mean by pressure? We've been hit multiple times and we didn't die. But now, as you can see, we get hit once. If we try to do that again, we get hit twice. If we try to do that again, the third time we are back to the main menu, so we do not have infinite lives anymore. And that puts the player, whoever is playing your game under pressure. So let's jump in and get started. Okay, so we want to start managing our conquerors lives. So what we're going to do is our conqueror has a certain number of lives. And when ever he gets hit, he loses alive. And eventually when he has no lives left, we will restart the game from the main menu. So currently if we get hit 100 times, we will keep on playing, which is not very good because there is no consequences to getting it and removes all pressure from the player, which is actually bad, believe it or not. So you might be wondering, why not simply use player and why do we need something called a game session? Well, when going from scene to scene, our player is reinstantiated and everything else with him. That means that all progress on player and other objects are gone. The problem we have is that every time we go from one scene to the next, for example, from level one to level two, all the game objects are reinstantiated. So if he lives, are stored on the player or the score, which is much more important, stored on the player or any other game object. That player is reinstantiated and all the progress on this player is reset. So for example, if our player has 400 score or has three lives and loses two of them when he goes into the next scene, or the level to his lives are reset to three, which is not good, and his score is back to 0, which is also very bad because we want him to add levels. I mean, add the score from level to level. So our goal is to keep layer lives and score from one scene to the next scene consistent. And we're doing that by using something called the game session object that will keep all persistent data on it, such as Lives and score, which we'll be adding later on, and et cetera. So let's go ahead and create a game session. And it's actually extremely simple. We're simply going to create a game object. We're going to reset it, its position, and we're going to call this the gain session. Okay, next thing we'll do is we'll add a script which will be gained session, and it's going to be called game session. So go ahead and create and add that. Great. So now we have the game session right here in our assets. Drag it and put it into scripts. And let's go ahead and open it up in Visual Studio. Double-click on game session, and now we have the game session script. What are we going to do first with our game session script? Well, first thing we'll do is we'll delete the start and update because we won't need them. And we're actually going to add a method which we are not very familiar with because we haven't done it already or before, which is called Awake. And what awake is, it's a method that starts even before the start method starts. So as I've taught you in the previous videos and the intros and an our magic Game Cube, the start method is the first method that gets executed. But the awake, something that well starts before the start. So it's the first thing that executes, or the first code that is executed in the entire script is inside the awake method. And why do we need awake? Well, because we are going to create a singleton pattern. That means that if there already exists a game session, every time a new one is instantiated, it destroys itself. That way it will not be instantiated and will stay persistent throughout all the levels. What I mean by that is that whenever we go into another level, this game session script will look for all other games sessions inside of the next scene. If it finds a game session, it will destroy it and stay persistent. And let's go ahead and create this singleton pattern and you'll see what I mean. So first thing we need to do is we need to find all the game sessions in this scene whenever we awake. So we'll create an integer, which will be the number of game sessions. And this will be the find objects. Okay, so objects of type gain session. And because this is an integer, it will be the length. So this is fine game objects of type which you are pretty familiar with. For now. We've done it in previous videos. It looks for objects of type game session, and it checks the length because we're looking for objects. So now we have the length. Next thing we'll do is we'll need to check if this number of games sessions, Number of game sessions is greater that one. That means that if we have more than one game session, which is not the current one we're using, we're going to destroy ourselves. So that means destroy game object. Else. If we don't have any new games sessions, we'll use something called don't destroy on load and the game object. Ok, so what, this is called the singleton pattern, and it's fairly easy. So first thing we checked for the objects. If we have objects of type game session, of course, then if we have more than one. We will destroy it, else, we will not destroy it and we will keep the game session persistent. And we, and if it has scores or lives, they will go from one level or from one scene to the next. Okay, great. So what we need to create inside of the game session, as we'll need to create the player lives. I mean, we're going to process the players death. So let's go ahead and do that using a public. And because it's going to be used from different scripts, public, void, process, player, death. And next thing we'll do is we'll add a variable which will be a serialized field. It's going to be an integer and it's going to be Player Layer lives, and it's going to be equal to three. So what do you think we'll need to do inside of process players? Death? Well, we'll need to do two things. First thing, we'll need to check if our player lives is greater than one. And if it is greater than one, we are going to take life. Or take life or life. So we're going to take a life. Else. If we don't have anymore prayer player lives, that means we've lost all three of them. We got hit three times. We are going to reset the game. Okay? So if we get hit more than three times, that means we lose all of these. We will reset the game and if we still have a life, so if we have three lives, we've been hit once. That means player lives will be two, that means we're still greater than one and we will take a life. Let's go ahead and create both of these methods. So first thing we'll do is we'll generate the reset game and generate the method. And what should we do inside of reset game? While we'll need to take the player to the main menu, that means we'll need to be using the Scene managing management, manager. So using Unity engine dot seen management. And we are pretty familiar with what we are going to do. So it's going to be the scene manager dot load scene. And because it's the main menu, it's going to be 0. And another thing we're going to do is we're going to destroy the current game object. Why is that? We're going to destroy the game session that we're currently using. Because as you know, if we lose the game, our lives would be reset, of course, and our score will also be reset. So this current game session will be destroyed and we'll create a new one coup. And next thing we're going to have take lives, which is your challenge. And your challenge is to finish the tape lives method. So you need to reduce the player lives by one. And then you'll need to call the process player death from the player script every time our player is hit. So pause the video right now and go ahead and do the Challenger. Oh, OK, welcome back. So how are we going to do that? First thing, we're going to generate the take lives and method. And it's fairly simple because all that we are going to do is we will simply type in here, player lives and will right next to it minus, minus, and what this does it. And every time the take life method is called, the player lives will be reduced by one. So whenever we write minus minus next to a variable, it will reduce it by one if it's an integer and if we write plus plus next to it, so plus, plus it will increase the player lives by one. We'll use that later on for now we need the minus, minus. Finally, whenever our player gets hit will need to call the game sessions, process player death. And the way we're going to do that is we will go into player, will look for the player hit. And after triggering the animation and getting hurt. Or you can put it wherever you want. It doesn't matter. Will find game objects, gain object because we will have one object which is game session and arsine. And we're going to use the process player death. And this will check for the game session. It will find the game session. It will access the process player death. And in process player does. We will check if the player lives are greater. Then one, if they are, we will take a life. If they're not, we'll reset the game and our player will go back to the main menu. So this, we've saved all of that. Let's go back into our unity gain. Save all that. In game session we have player lives, so let's click on play and see what happens. So our Pig is running, let's go and get hit once. So player lives is to still greater than one. We get hit twice. Our player lives is one and last time we get hit. And will we are in the main menu scene. Excellent, so everything works fine. I hope you enjoyed the video. I hope you didn't find that too complicated, especially if you're new to the Singleton pattern. Anyways, I hope you enjoy it again and I'll see you in next. One more thing we need to do in order to prove that our gains session is persistent from scene to scene, is we'll need to see if our player lie lives actually change. If we go to another level. In order to do that, we'll need to add a game session to level two. And as we know, the easiest way to do that is to Prefab it. So simply drag it into the Prefabs folder right here. And we'll also drag the exit door because we're already in the prefabs. So save that and then go into scenes and check for level two. Double-click on player just seeing him and go back into reverbs and put a game session right here and the level to save that. So now let's test it out and see if it worked. So go back into the level one, double-click on the tile map because they are in different positions. So let's click on play and let's see get hit once. And as you can see right here, the game session is under don't destroy on load. So it understands that it should not be destroyed. So now we have player lives to, let's go through the door into the second level. And on level two we have the don't destroy onload came session. And as you can see, our player lives are still too and they have not been reset, which is extremely helpful. And you'll see why when we create also the score. 44. Hearts and Diamonds Pickup: Welcome back to another video and this one, as you can see, we have diamonds and we have hearts. So if we click on play, we can still walk, we can punch, but if we choose the diamonds and hearts, we can pick them up and the diamonds are actually shining. So let's not waste any more time and let's get started. Okay, so first thing we'll do is we'll go into the sprites folder and create a folder right here, which will be called the pick ups. Ok, cool. Now let's go into the resources and get the big diamonds and big huts that I've provided you and store them inside of pickups. Next thing we're going to do is we're going to slice up the diamonds because we have a cool animation on them. So let's make this 28 because they're very small, make it multiple. Apply that, go into the sprite mode and let's slice them up. We'll use the grid by cell size and they should be, I think 18 by 1418 by 14, Yes, it's 18 pixels by 40 pixels. Apply that they were perfectly. Now let's go into animations and also create a folder which is backups. So pickups. And let's go back into the sprites in the, where are the pickups? And let's go ahead and create these animation. And this animation is actually a shining diamond. Shining will be the animations name. Drag it into pickups. And from here will create a animator. So the animator controller will be diamond. And inside this animator controller will set up the shining state. Correct? And one more thing, we will need to make sure that it is looping. Save that. Now, next thing we will do that, stay the player away from here, put him on this ledge. Next thing we'll do is we'll create a game object. So empty game object will reset and put it right here, and we'll call this the diamond. Diamond. I hope that's correct. Next thing we'll do is add a sprite renderer. So you're pretty familiar with the steps, I hope. And inside of the sprites pickups, the diamond, let's simply put the first one and still we don't see it. Why is that? It's because of these Sorting Layers. And are diamonds and hearts will be interact bubbles. So now we can see them. And also the layer will be the interactable. So sorting layer and the layer physical layer will be the interactable. Next thing we'll do and will do this right now to save ourselves a lot of time, we'll simply prefab the oh, before we do that, we need to add. The, Whereas the animator to our diamond. And now we can actually go into the prefab folder and drag the diamond right here. And we'll be able to add to three diamonds. How ever we, how much our heart desires. So add as many diamonds as you want to the scene. Save that. Next thing we'll do is we'll need to add behavior to our diamond. So as you know, when games, whenever we touch a diamond, we pick it up and it disappears. So it's a diamond pickup script. So diamond pickup Script create a new script, it's called Diamond pickup. And let's create an ad. Oh, okay, so it's ready. Let's go into assets and let's put the diamond pickup inside of the scripts, opens up. We don't need it. And let's go ahead. Whereas it Diamond pickup double-click and we have start and update. So we don't need these start and update right now. If we need them, we can always create them later on. Save that and it's time for your challenge. And your challenge is to destroy the diamond. So when our player touches the diamond, it gets destroyed and destroyed immediately. So this should be one destroyed. So the diamond gets destroyed immediately as soon as our player touches it. So I have a few hints, but if you're feeling confident enough, I want you to pause the video right now and go ahead and do the challenge. If not, if you still feel that you need a bit of events, I'll give it to you. So add a collider, make sure it's a trigger, and use the trigger. Enter, of course, enter 2D to destroy the diamond. So pause the video right now you have all the hands and it's very easy. Go ahead and do the challenge. O kay, welcome back. So before we start playing around in the script, we need to go into Unity and will need to go into the diamond. And we'll need to add a component which is going to be a box collider to D. And it's a bit bigger than we need. So let's go ahead and edit the box collider and make it, yea, big, hope. Go back, choose Box Collider. And let's make it just like that. Maybe a yes, a bit bigger to fill the entire diamond sprite. So why did we prefer well, because right now this diamond doesn't have a box collider, so we'll simply apply all. And now these diamonds, all of them have box called lidars. One more thing to organize our hierarchy right here and to not make it a lot cluttered, will create a empty game object and we'll reset it and we'll call it the pickups. So pick ups. And we'll put all of our diamond. And Hearts later on inside of the pickups, Qu. So now we have our diamonds with box collider is o at one more thing, we need to make it a trigger. So make it a trigger and upped by all, save that. Now back into the Visual Studio. And as I've told you, will be using something called on what? No. What is that? Sorry for that Visual Studio on sugar, enter to D. And it's very, very, very simple. We simply need to destroy the game object. So save that back into Unity. Good luck can play. And now, if we jump on one of these diamonds, it doesn't disappear. Why is that? So let's see what's the problem. And in here we destroy when we aren't sugar, enter to D, It's on-demand pickups. What's the matter? Oh, wait, oh my god. We didn't even add the script. So let's go ahead and add the script from here, two diamonds. And now, I hope if we apply all, it should apply to all of our diamonds. Oh, this one has three. We should have applied it from here. No worries, simply remove it. And now if we save that and we click on play, hopefully they disappear. And as you can see, there are no more diamonds except for here. Let's go ahead. One more diamond. We go to it and the pickups is now empty. Cooh, Now next thing we're going to do is the hearts and it's your challenge. It's an extra cheeky challenge, is to do the exact same four hearts. So you have everything in your skills that you need to in order to complete the challenge. So go ahead and do it. Pause the video. Oh, okay, so just like we did the diamonds, we are, we are going to do the hearts. So let's see where we have the sprites for pickups. The hearts. It's going to be 28, it's going to be multiple. We're going to apply all of that. We're going to use this sprite renderer. I believe it's going to be also 18 by 14, hopefully. Yes. It is a lie that I hope you tried your best and does challenge because it's fairly easy and we've been doing it since. God know how slow, how long. So animation. And the heart is, what should we call this bouncing. So bouncing into the pickups, foo, into the pickups, and inside of pickups, let's create a another animator controller that's called hots. Capitalize that, hots. Even though it's one-hot. So shining, nope, not shining, bouncing inside of hearts. We have the bouncing state. Next thing we're going to do is we're going to create an empty, no, let's simply duplicate this diamond. And we'll call this heart or heart. And we have the same box collider. But now let's put it right here. The sprite renderer will be a heart. So we'll give it a heart. And it's going to have, what else should we have? The animator should be different. So let's go into the animation's pickups and give it the heart. Animator. What else should we do? The box collider, I think is perfect. And it will remove the diamond pickup component and we'll add another component which is going to be the heart. Pickups. Pick up, pick up, create a new script, and create an app. Now, make sure that you don't apply that because we'll need to make a prefab. So let's go into our prefabs and add the heart. Simply get the heart and drag it and it will ask you to, would you like to create an original prefab or a variant of this prefab, simply click on original prefab, and now we have hearts. So let's go into the assets and add the heart's pickup scripts. Let's see what else should we do? I think everything is great. What else? Okay, we have the collider. We have the collider as a trigger, back to scripts into the heart. Whereas the hot pickup, and just as we did exactly the same on sugar enter for now, will simply destroy the game object. Cool. So let's go back into our unity. Let's go into prefabs. We don't need to duplicate, simply go back into prefabs at this heart right here. And we'll add a heart, right? Or, okay, no worries. Put hearts on the pickups. So now we have two hearts again. Third heart. Why is it not changing the names? I don't think it matters. Save that. Click on play and we should now have the disappearing hearts and D disappearing diamonds. So for now, nothing happens. Later on we're going to create a score and we're going to create a Lives. And whenever we take the diamonds are score increases and whenever we take the hearts, our lives increase. So I hope you enjoyed the video. I hope you did your best on the challenges and I'll see you in the next one. 45. Adding Sound Effects (SFX): Welcome back, my favorite game developers. In this video, we are going to add sounds to our game. So not only do we pick up the hearts and diamonds, but also we have a sound. And if we pick up the diamond, we have in another sound. So I'm very excited for this video. It's a very cool video, ads flavor to our game and makes it so much more authentic. So let's get started. So we're going to add some sound effects, which is very cool. But the problem before we get started is, I've noticed a little problem is that our hearts don't bounce when we click on play. Only the diamond shine or the hearts, at least both bounce ones. And that's a very simple problem to fix. You just need to go into the animation, bouncing and make sure they are on loop time. So they are looping, so we click on play and now our hard bounds and are diamonds shine. But right now, if we pick them up, they simply disappear and we need to add some sound effects to make them much cooler. The way we're going to do that is we'll play a sound clip whenever we pick up the hearts over the diamonds. But we have a small problem. And that problem is, if we go into our slides right here, our problem is that the sound effect playing on diamond object will be destroyed, which means it will stop playing when this time and gets the straw. So as you remember, we've put inside of our own trigger enter 2D that the object will be destroyed. And every single sound effect that is playing during this destruction will also be destroyed and stop so that, that is a huge problem. So what is our solution? Well, we are going to be using something called used public play clip at point. And I've left you the documentation in the resources and we'll check it out right now. So basically what this does is it creates an audio instance of our sound effect independent of the game object from which it came, which is perfect for in our case. So let's go into the Unity documentation and see what play clip at point is. So it's a public static void method which takes in three variables. I am three parameters. And we're going to be focused on the clip, which is our audio clip. And we're going to be focused on position. The volume is not a big problem. So if you read the description right here, you can see that it plays an, an audio clip at a given position in world space. So this function creates an audio source, but automatically disposes of it, wants to clip has finished playing. And it is perfect for us. As you can see right here. Is it so you create a variable which is an audio clip. You give it a clip and then you use this audio source. Clip, play click at clip, at point, and you give it the clip and a position to play at. So let's go ahead and try to do the sound effects. First thing we're going to do is we're going to add a audio clip. So if we go right here and two hearts, diamonds pickups, let's do the diamonds first. Let's go ahead and sterilize a field. And this field is going to be an audio clip. So audio clip, and we'll call it Diamond. Pick up as fx, which means sound effect. Save that. So now we go back into Unity. We go back into Unity, and we go into the diamonds. And right now we can see that we have a place to put our audio clip. But what are, what are our audio clips? So let's go into assets and let's do the best part of creating projects. And it's upright here. Why did it created entitles? Go back to assets. And right here that's go ahead and create a folder which will call as f x, which are our sound effects. And in the resources I've provided you with two audio clips, which are diamond pickup and heart pickup. So click on those and drag them into the sound effect. So if you click on sound effect and click on one of them, you can see that it's an audio clip and it has many different variables and things to tweak. We can actually listen to them. So this is the diamond pickup. Not sure if you heard that because of the microphone, but it's a pretty neat sound that I found on the internet. You have the liberty to choose whatever sound that you find. Anyways, let's go into diamond, and let's simply drag this diamond as effects into the audio. And let's click on Apply All. And now all the diamonds have this diamond pick-up sound effect on them. Great. Next thing we're going to do is we're going to actually write the code to play that. So let's go right here. And when, before we destroy the object, let's go ahead and use the same formula that they've given us in the description in the docs, documentations of unity. So it's audio source. Audio source. And then if we click on dot, we have clip on point, clip at point. And it asks us for the clip which is the diamond pick-up sound effect. Next it needs deep position. So where should the position b? Well, if we go back into Unity right here, you can see that we have many different places to put it. We can put either on the already present diamonds or we can put it, for example, on the player. But I'm going to put it on the camera and I'll tell you why. You have this little button right here, which is 2D. If you click it, we go into the 3D. Mold. So let's make this bigger so you can see clearly what is happening. So as you can see right now, this is our camera right here. And as you can see, it's a bit distant from our playing field or our platform. Actually, this is very cool as you can see, this is our entire game, but in 3D, yet it's rendered on a TD 2D plane. And as you can see, the diamonds are a bit far from the camera, while our camera does move with the player. But for example, let's say we take the diamond and we run away, the sound would not be rendered correctly. So what I want to do is I want to play the clip exactly at the camera's position. And that is actually very easy. The way we do that is we give it the position of our main camera. So it's simply camera dot main, dot transform, transform dotplot session. So now we have a diamond pick-up sound, the fact that plays at the position of our main camera. So let's try and see if that worked. So click on play. And now you take the hearts, there is no sound effect, but if we take the diamond, Did you hear that? So now let's take the second Diamond and we have sound effects playing. So our game is much cooler right now, isn't it? So I want to show you another thing. And that thing is the will try to time it correctly. So if we take a diamond, okay, and we pause the game, you can see right here in the hierarchy that we have something called one-shot audio. And that all it creates an audio source and its audio clip is the diamond pickup, just as the documentation told us. And as you can see right here, if we click on the 2D and we click on the one shot, it is on the camera. So we continued again, we take another diamond and our game as function in 100% correctly. So next thing we're going to do is we're going to add a sound effect to our heart. And that is your challenge. And your challenge is to play the heart pickup sound effect. So when we touch our heart, we want the sound to play and we'll use the same formula we used in the timeouts. So I've showed you how it's done. It's very, very easy. Pause the video right now and go ahead and do the challenge. Welcome back. So how did you get on with that? It's fairly easy. We go into the hearts, we do the same thing. So we'll create a serialized field. We'll make it an audio clip. And this audio clip will be called heart pick up effects. Okay? And inside of here we're going to create an audio source. And we're going to use play. At Clip point. We're going to give it the heart pick-up sound effect. And its position is going to be at camera. The main dot transform dot position. Use the semicolon to close all of that, save it, go back into Unity. And now in the heart, choose any heart you want and give it the heart sound effects that I've provided you in the resources. All. And now, if we save that in the unity, click on play. And now we take the heart, we should hear the hard sound facts. And we do. Let's do that again. And again we hear the sound and if we can take this one. So now we've added sound effects to our game. So we have many other sound effects that we can add, which is very cool and will be doing them later in another section. So I hope you enjoyed the video. This video is very cool and very nice and it adds a lot of flavor to our gain. So I hope you enjoyed it and I'll see you in the next one. 46. Persistent Lives And Score: Welcome back everyone to a brand new video. As you can see right now, we have a score or 99 on the score, and we have 99 on the lives or the other way around. So if we click on play right now we can see that we have three lives and 0 as a score for pick up one of the hearts. Now we have four lives, and now we have six lives. If we pick up the diamonds, we have 300 as a score. And what else? If we get hit by a piggy? Now our lives are five. If we go through to the next level, we have persistent lives and persistent score. Oh, okay, girl rate. So this is a very nice video. I hope you enjoy it and I'll see you in just a bit. Okay, so first thing we'll do is we're going to create a canvas right here that will have a text solids. The right-click go into the u, i, and go and look for text. Great, so now we've added some kinds of texts. Let's put the game right next to our view right here so we can manipulate everything. Double-click contexts, where is it? And it's very far away from home. Let's put it right here, and let's anchor it to the top left corner. This will be our lives text. And let's go ahead and make it 99 just to represent how much lives we can actually have. And one thing we'll need to make sure of as we go to the canvas, canvas scaler and make sure that you scale mold is in the scale with screen size. Oh, okay, great. Double-click on that. Let's find our text again. And we'll make it bigger and bigger. And let's go and make it bold. And we'll make it white to see it correctly. Okay, let's make this a bit bigger. So we'll make this maybe 4545 is good enough. Now we have our lifestyle. Let's duplicate that and let's go ahead and anchor to the right. And I think you've guessed what we're going to call this. This is going to be not livestocks. One. It's going to be our Score Text. So let's go ahead and put it to the right. And this will be, let's see, how many. So I think it's going to be in the thousands, in this thousands. And I think one more time is enough. This will be our score. This will be our loves. Great. So let's go ahead and change this canvas and let's make this the score and lives Canvas. Okay, Ku, next thing we're going to do is we're going to access these two texts from our code. And we're going to do that, of course, in all games session. So let's go into game session. And here we can find that pickup games session. So the way we're going to add these two texts, texts into our code is of course using these serialized field. And we're going to be using something called text. And as you can see, it's part of the Unity engine dot u i. So check, check what's going to happen right here. Just delete that again. Right here we have the Unity engine, Unity engine scene management. And if we write text and we click on Tab, it will automatically add this namespace or library right here so we can use the texts. Cool. So let's go ahead and add the score text. And a neat little trick that I'm going to show you. If you have two variables that are of the same type, you can actually put them on the same line. So let's go ahead and add the lives text. And let's go ahead and create an integer which is going to be the score, and we'll set it to 0 in the beginning. Okay, so save that. And now what we need to do is we need to assign each text to a certain variable. And the way we're going to do that is we're going to assign them in a start. So let's go ahead and create a start method. Simply write start and click on tab and we have the start. And what should we do right here? Well, we want to tell the code that the score text is assigned to, or I mean the score is assigned on the Score Text and the lives text has the player lives. And it's very, very simple. So if we save that first of all, and now if we click on lives, text dot text is equal to player lives. But we cannot. If we close this, you can see that there is an arrow which tells us that we cannot implicitly convert type int or integer to string. So we need to convert this one to a string. And we do that using a very simple method which Visual Studio already tells us we should use, which is to string. And this string simply converts anything that we give to the text into a string. And we'll do the same to our Score Text, Song, Score. Text dot text is equal to score dot to shrink. And now if we go into Unity, has going to unity. If we click on play. But this game right here, if we click on play, we should have here 0 and here the score, I mean the score, the lives will be three and the score will be 0. But something we didn't take into account is that in game session we still haven't assigned them. So lives into the livestocks score and to these cortex. So click on play. And we have 30. But right now nothing happens. And if we get hit, also nothing happens because we still haven't updated the discourse and lives whenever we die. If we go into the next level. Nothing is happening here, and we'll fix that also. So let's get back into our code and see what we need to do. So we need to update the score and lives taxed whenever we get diamonds or we get punched in the face by the little piggies. So let's go ahead and do that. In take life, right here, we decrease declare lives, but we need to also update the text. Simply copy this right here. The lives texts, texts to string copy that and put it right under the player lives. Save that. And we'll need to do the same with the add score. But the problem is that we still don't add any score. So we need to create a function or a method for that. Let's go ahead and do it, will make it public because it will be accessed from the diamond pickup. So let's say public void. We'll call this add to score. And we are going to pass it a parameter. And that parameter is going to simply be called the value. And why do we need that? Well, because maybe you want to make certain diamonds have a certain more bigger value, or maybe you want to have small diamond and big diamonds. So this gives us our code a bit of flexibility. So simply, we are going to do the score plus equals value. So what this plus equals means, it sort of like this sort score, score plus value. And what this does, it increases the score. So for example, let's say we have 0, we add the value to it and we put it inside of score. So next time when we pick up the second diamond, this score will be added to the already existing score. And because Unity I'm in Visual Studio is very helpful, we can simply write plus equals, which is exactly the same. And before we go, we need to also update the score text. Save that. And now we have to use this add score to in our diamonds pickup. So right here we are going before we destroy and after we play a clip on point. Actually it doesn't matter if we put it under destroy or over destroy. Its the same. What we need to do is we need to find the object of type. And that object is going to be a game session. And in games session we are going to add to score and we need to pass it a value. So let's go ahead and sterilize a field. Because this gives us the ability to change where, whenever we want, it's going to be an integer and it's going to be the diamond value. And for now we're going to make it 100. And that's it because it's an integer and we'll pass it into the ad score parameter Qu. So now we have everything set up. We have the score, we have the text value. And now what we're going to do is we're going to test that and see if it works. So save that. And now, if we take a heart, our score didn't increase. I mean our lives doing increase. If we take a diamond, our score does increase. So let's see that again. Diamonds increase in score. If we die, we have this two right here. Let's try that again. If we get hit another time now we have one life. And if we get hit a third time, we start over. So now let's see why our lives didn't increase. And I think it's obvious because we haven't created any cold that gives us the ability to increase our lives whenever we take a heart, that it's going to be your challenge. Your challenge is to do the same for the player lives. So go through the same steps to update our player lives just as we did for the score and make them necessary. Small adjustments. It's fairly easy. It has a very simple solution. It's exactly the same as increasingly score, but as I told you right here with small adjustments. So pause the video right now and go do the challenge. Ow, kay, welcome back. So it's exactly the same. Right here in the heart pickup are going to find objects of type. It's going to be the game session. And we're going to add not to score, but because I think it's still a private school right here. And we'll see what do we have now. We have only the take life. We're going to create a function that is add lives. So let's create a public void at two lives. And simply we are going to add the player plus plus, which will increase the Thayer lives to one. And we're going to copy this and paste it right under to update the text. Go back right here, and let's go ahead and add two lives. And we don't need to pass any parameter because it will only add one life. So let's get back right here. Click on play. And now if we pick up a heart, it increases to four. And if we pick up a diamond and increases 100, but we have a slight problem. If we jump on top of a heart. It's currently four, it should be five, but it becomes six. So what's the matter with that? We'll fix that in another video at just needs a bit of tweaking. And for now, one more thing we need to take care of is if we click on play again, and for example, we pick up diamonds and whatever. So the little piggy helpless right there, we pick up a life and a free get hit, for example, now more than three times takes much more time for us to die just to make sure our mechanics are working. As you can see, we've been hit more than three times now. It's about five times and we can still live. So let's go and to the next level and see what happens with the scores and the text. Keep the same. Nope, they disappear. And that is a problem. What Gibbs? Well, as you can see, our scores and lives are not under the, don't destroy it. We need to make them indestructible. And the way we do that is we simply Child them to the game session. So now if we apply, all our game session will have as a child, a UI canvas with lives and save that. And now if we click on play and we pick up a couple of hearts and a couple of diamonds. We go to the next level, and the next level we have 6300, which is extremely useful and super cool. So I hope you enjoyed the video. I hope it was very educational because we are now controlling our game very effectively through scores and through lives. You need to make a couple of adjustments later on, but that's okay as long as the core mechanics are working. So I'll see you in the next video. 47. Bonus Section: Level Enter: Welcome back everyone to a brand new video. And as you can see right here, we have another door and our player standing right behind them. So let's see what happens when we click play. So when we click on the play button, are Player opens the door and appears from behind. And now if we go to the door, it opens up. And if we press the w R player, not only goes to the next level, but he also goes through the door and goes out of the door and then goes to the next door and go through it and goes to the next level, and he is a winner, winner. So it's a very exciting video. Let's not waste any more time and let's get started. Okay, so let's go ahead and first-world go into our sprites and get them. We have the door and the door out. So simply drag them and put them inside of where are our sprites? Inside of sprites. And let's go ahead and put them inside of our conqueror, whereas our Conqueror, there's our conquer. And now first of all, let's create, let's make this a bit bigger. Let's create the door n. So going into the door, and as you can see that let's go ahead and make 30, make it multiple, apply that and open these Sprite Renderer. So as you can see, are human or our conqueror goes from being here and to disappearing behind the door. So let's slice there up. Is it 64? It's 58 by 58. Hopefully, an open orbits not, it should be bigger. How big should it be? So let's see. If we, how big should it be? We should make it with, I think a 20 padding. So 20 padding sliced up and all of them are in the middle. Perfect, apply all of that. And now we have our sprites sliced up and ready to be an animation. So select all of them, right-click and create the animation, whereas it animation. And we'll call this animation this peering. Not sure that that's the way we write it disappearing. I don't think it is, and it will work for now. So put it inside of player that's opened the animator of our player. And let's go ahead and add this peering into the animator. Okay, cool. We need to play around a bit right here because I don't like the distribution of states, so it's fairly easy. Let's move the exit right here. Move the NSDate up, move the getting hit. Let's put the disappearing. Yeah, about here. Ok, so how are we going to make the transitions? So the transitions are going to be from idling because we get to the door opens, we click a button, so it's going to be from idling. And we're going to add it to the peering. And what parameters should we be adding? That will be a one-way transmission because whenever we disappear behind the door, we will not go into any other state or will simply leave the level. So we'll put this transition duration to 0, will remove any exit time that we have. And let's go ahead and add a trigger. And this trigger is going to be this disappearing, but the same name. And it will save us some confusion and this will trigger the disappearing. So let's go into the code and see where are we going to trigger this animation of disappearing. Let's go ahead into the Visual Studio. And where do you think we should put this or should we trigger this disappearing? Lets him in a challenge. Okay, so we should put it in the exit level and right before we start loading the level. So let's go ahead and get my animator dot set trigger. Let's open up and go ahead and get the reference. This is the first time I even think this peering and state how you write it. Ok, we'll paste it right here, save that. And now if we go into unity, click on play. Let's make this smaller. Click on play. And if we go through the door and click the W, He goes away. But as you can see, there are a couple of problems. Let's play that again. And we click on, if we click on the w, As you can see, first of all, the door closes before we leave. And second of all, if we continue to play the animation, when it finishes, we can still see the silhouette of our player right there. So two problems that we'll need to fix. First of all, let's fix the problem of our players silhouette still there. So that is fairly simple. We only, the only thing that will need to do is we will have to add a function which will disable the sprite renderer. So let's go ahead and add that will make it a public, or you don't have to make it public. So, but we'll make it just in case it's no worries. So it's a public void. Turn of Renderer vendor under is that how you write it? So we'll go ahead and let's get the component, get the sprite renderer or sprite renderer, whereas it sprite renderer. And Hughes enabled. And it's going to be false. Now, where are we going to call this method? Well, it's going to be called using an event animation. So let's go back to player and let's choose animation, go into disappearing. And right about here, he should disappear. So let's go ahead and add in event, and this event will call the function turn off renderers. So let's see if that worked. Click on play. That's go right here. Click on w And he disappears completely. Nuts. Next thing we'll need to do is we need to make sure that our at all keeps, stays open until our player goes through it. Fairly simple, the way we do it is also using an event system. So let's go into our Visual Studio and let's create a method right here that's going to be called public void load next level. And we're simply going to copy this right here, which is find the object of type exit door, not copy actually cut it. So control x and Control V. So it should remove it from up here. And you will know soon enough why we're doing this. And another thing we'll do just to save a bit of space will simply call the function turn off renderer right here. So turn of the Renderer. All right, in the load next level. Now you'll see why we did that. Go back into Unity. Click on the layer and look for the where is it disappearing? And right here instead of this event, let's change the turn off renderer and to the, Whereas it lobed next level. So what happens now is we will start the disappearing animation. So it will start disappearing. Then, after the disappearing has finished, we will start loading the next level and we will turn of the render. So let's see if that works. Collect on Play. And now if we go through the door, he will go door will close and then we will go to the next level, Qu. So now it's time for your challenge. And your challenge is to create a door, enter, enter, Add a entered or not an exit door with its own script to the scene from which you, our player enters every time at a level, start at a player appearing animation to the Animator and make the appropriate transitions. And trigger the player appearing animation and start. And finally, you need to position the player behind the door at each level. So create a enter door. And that enter door should be almost the same as an exit door, but it will have a bit of difference in the animator and a small difference in the way the script works. And you need to make the changes to the player so the animation of appearing so should play as soon as we start a new level and the player should be behind the door. So pause the video right now and go do to each other. Oh, okay, welcome back. How did you get wrong with that? Let's go ahead and create the appearing. So let's go into the sprites of our conqueror. Let's close down the door N, And let's choose the door out. And now we need to slice these up. So make this 30 minutes multiple apply. We go to the sprite editor and as you can see, our player goes from a silhouette and two appearing as our conqueror. So let's go ahead and grid by cell size. How much was this? Oh, it was 58 by 58 and it had a 20 padding. Slice it up. They are all in the middle. Perfect applying. Now let's go ahead and create the animation, right-click animation. And we'll call this peering. So put appearing inside of player and from player, let's go ahead and add it to our now very big animator. So peering will be set right here. So how will appearing work? Well, we'll have a transition from idling two appearing, which will have also a trigger. We'll call this trigger. Appearing. Fairly enough, simple enough. We'll have no exit time and will have a transition duration of 0. We'll add a condition which will be appearing. And now we need to add a transition back from appearing into idling. Now how is this transition going to work? Well, it will have no Transition Duration and it will have an exit time of one. So now we will trigger the animation of appearing as soon as the game starts, so it will be installed. And then we will, after the animation finishes and our player appears, we will transition back into the idling. Save that. Let's see if that, oh, before we do that, we need to trigger right here in the start. So my animator dot set trigger will first of all said The appearing. So that whenever we start the game, every, every level we start, our player will appear. So before we create the entered or let's go ahead and do this 1 first. So make this smaller. They can play and our player should come out of the wall. Let's click on play and see what happens. Okay, that was a bit fast. Let's go into another level to see it better. Okay, so we go through the door, we appear in the next level. And so now this is working. Next thing we need to do is we'll need to create the anther tour. Let's go ahead and do that. So we'll right-click right here and create an empty game object, reset its position, and let's put it up here. Let's simply take this diamond and put it next to these two diamonds. So game object. Let's make this smaller. And this will be the door. Enter. And let's go ahead and add a sprite renderer source, right? Renderer will have by default, it will be the interact bubbles and the layer will be interactable. Actually, you know, we, we won't need to add any layer. We will simply need a sorting layer. So let's go ahead and go to the door sprites and add the idle sprite to the door. Correct. So now we have a door. What else do we need? Well, we had to create a sprite, I mean, a script for it. So it's going to be door or let's keep consistent. So and third-order to enter door. Yes, it's entered or so creating new script and Theodore and we'll wait for unity. Correct. Let's go into the assets and let's put the door inside of scripts. So let's go ahead and open it up. And the Visual Studio until door, just like exit door but with a twist. So what will exit door have? Well, start it will start with triggering the open. Oh, we didn't, we didn't at the animator. And somehow it's still called game objects. So let's change that. And to enter door Qu, So what should the animator of our entertain your P? Well, it's a bit of a twist and a bit of a shocker, but it is going to be the same for the exit door. So we'll rename the door. I mean, the exit door to door, and we'll simply drag it and add it to the door. And it's going to be exactly the same. But only thing that will change is in the enter door script. So first thing we're going to do in the entered or script is we're going to whereas it so and her door. So as soon as we start, we are going to trigger the animation. So we'll get the component or the opening animation. So we'll get the animator, whereas it anyway taught or, and we're going to set the trigger and it's going to use the open. So open. And there it is. We've set the trigger as soon as the scene stocks. And now let's go ahead and go to the level one. Save that. Let's go and Prefab it. So where are our prefabs? Are prefabs. Let's prefab enter door, and let's go save that also. Let's go into the second level. Or before we go to the second level, let's put our player behind the door or right next to the door. So just like that, let's go back and to the levels. Where is it? So scenes level to, yes, save that and double-click on player to find them. Let's go ahead and add the Whereas the door where our prefabs doors so many folders at now. So add the so this is the x dollars product right here. And the entrance door will be just behind the player. Even though it's the same place. No worries, we can change that up. So let's take the player and the door and put them right here so we don't get confused. Ok, so great. Save that. Let's go back into level one and let's play it and see if our game flows smoothly. So publicly complaining, there he is, click on play, and as soon as the game starts, the door opens, the player appears. And if he goes through the door in level two, door opens, the player appears, we move. I can move to the next door, so let's do that. And finally, we appear in the main menu, which tells us that we are a winner whenever. So back to main menus, start game and we do all of that again and again and again. Cool videos, so works fine that c enter door and see everything and our animations set so and our player goes from one place to another. So I hope you enjoyed the video. I hope you find it as cool as I do because it's really, really cool and it gives the game as if there are no scene changes. We are simply walking from door to door and going into new and different levels. It's very exciting, it's very cool and I'll see you in the next video. 48. Adding SFX To Everything: Welcome back everyone to a brand new video and the very cool one, because we are breathing a lot of life and arcane. As you can see right here, our player now has an audio source and a lot of sound effects. So let's check them out. As soon as we start the game. Here, we have a door opening. We can pick things up. We can walk. If we hit our player, he dies and makes sound. We walk, we walk. Let's go to the bomb and see how does it burns. It explodes. And if we go to the door, we can actually go through it. Qu, So let's see how we do all of those sound effects. Oh case. Because our player would not be destroyed every time we pick him up. Unlike the diamonds and the hearts, will use a different method other than the play clip at point. And that is the L1 shop. So let's see what that is. So this is the Unity documentation, as you should be familiar with it. And we have the audio source dot play one-shot. So if we read the description, it plays an audio clip that of course will be giving it to and scales the audio source volume. Now the volume will not make a big fuss about it depends on your preference. If you want, you can make it bigger or higher or lower. Anyways, it plays a one shot. And if you can see right here, as it requires an audio source to play that. So we'll have to add something called an audio source. Let's get back into Unity and let's go into our layer. And let's add a component that's called the audio source. So now we have an audio source on our player. Great. Next thing we'll need to do is we'll need to give the player some audio clips. So we have a lot of audio clips and some of them will be part of your challenge. I'll do a couple of them and I'll leave the rest for your challenge. So let's go ahead. As you can see, we can add an audio clip right here to the audio source, but we'll do a different way which is giving the script right here some audio sources and it will use them to play and the audio source. So save that. Let's go into the player. And right here, we'll need to add a couple of serialized fields. So let's go ahead and create a serialized field. And it's going to be an audio clip. And we'll add the jumping as effects, will add the decking as a fax. And I think that's enough for now. Let's go and get them from the resources. So I've left you with a lot of sound effects and we'll be using all of them. But for now let's just get the jumping and the, Whereas it, the attack. Maybe we'll do a couple of more later. So put them inside of sound effects. And now we have the heart, I mean the attack and the jump. So why is it not saved? Let's save the player script. And as you can see, I've put them on a single line to save space. And because we can do that, we didn't do it up here, but This is for the purposes of having everything in front of us and not confusing you, especially in the beginning. So back into Unity, we can see right here in the inspector that we have the jumping and the attacking. So let's assign them. So jump to jump and attack to the attack and will apply also we apply it to the prefab. Save that. Now, let's go back into Visual Studio and see how we're going to play this. So first thing we'll need is a reference to our audio source. So we'll create an audio source and we'll call this my new force. And then start. Let's go ahead and assign the my audio source to get component and the audio source present on the game object. So easy steps you should be familiar with these. Next thing we're going to do is we'll need to add the jump sound whenever we actually jump. So right here we can see that whenever we add the velocity is a perfect time to add the jumping. So let's add it right here. So my audio source and as I've said, will be using the play one shot. So dot play one shot. All that it needs is the jumping sound effect. And let's go and find the attacking, whereas the attack, okay, so right here, whenever we play the animation, we get the colliders. We can put it right here. So it's my audio source, dot delay one-shot and the attacking sound effect. Save that. Let's go back into Unity and see if that worked. Everything should be set up. So click on play. Now, if we do the attacking, ok, so if you attack, we attack, we have a sound. If we jump, you can see that our player has a sound and picking up the diamonds also gives us a sound. So let's still not used to killing pigs. Ok, so now we've killed them and we have multiple sounds. If we hit multiple times qu, next thing, what should we do while I am going to use one? I will play an audio using an event just to show you and the rest will be all yours. And we'll do that with the door. Now we have two ways of doing this. First, we can add an audio source to the Enter and the exit doors. Or we can simply play clip at point. Both are good. There are no drawbacks to annual them. You can do you can do it the preferred your preferred way. I'm going to do it using the play clip at point because honestly, they don't need an audio source. We can also add an audio source. It's not a problem, but we won't do that. So. Let's go into the door or exit door, and let's go ahead and create a method that will play the audio. So let's go ahead and create it. So it's going to be a void. Of course. We'll call this play opening door as effects. And we'll make the opening capitalised because that's how we make the methods. And inside of here we're going to play the audio source dot delay clip at point, and we'll need a clip and a position. So let's serialize a field. And the serialized field will have a audio clip. Audio clip. And this audio clip we'll have the opening oh, nope, not capitalized opening door as f x. And we'll have to do the exact same end the Whereas it the door open, whereas the door open the door. So we'll have to do the same. Let's go ahead and do that. So we'll copy this and this. So copy that, put it right here. And we'll do the same for the serialized open door. So for the opening now, let's save all of that and let's go back into Unity. And let's go ahead and, and the sound effect for the door open. So let's add it inside of Unity. And if we play it, let's play. So it's a door that opens, nothing too special about it. Exit door. We should have. Okay. We don't have it yet entered or oh, I think it's because we have an error right here, so we'll need to make some adjustments in order for everything to work. So let's go ahead and save all, save all saves all of the non saved scripts. So enter door should have now an opening door. And we'll add the audio clip, apply all. And then the exit door will also add the Whereas it okay, there it is. And we'll apply. Now, where should we play it? Well, as I've told you, we're going to be using an event to play it. So in the entered or if we click on it, we see that we have our animator right here. If we click on animation, we can see the opening. And just as soon as the door opens, we're going to add an event which will give us an option to choose a function. And the only function that we have is deeply opening door as affects. Click on that and we'll do the same for the exit door. So open, oh, is there already? So open, y, o, we are using the same animator. Okay, that's very cool and very fast, very efficient. So if now when we click on play. Nope, no sound. No sound at all. Why is that? Oh, OK. Another very goofy mistake. So we'll need to add the opening as x to the camera main dot transform dot position. And let's copy this because it's a mouthful. And we'll paste it right here. So should have copied all of it. So opening door as effects and the camera transform domain the transform position. And now if we click on play, hopefully this is going to make an opening door sound. And so if we now, if we jump down into the door, we should hear another sound and coo. And if we go through the door, we don't hear any sounds yet. Because it's part of your challenge. And your challenge is going to be to complete all the other sound effects. So I'll show you the sound effects that we need to complete. Those are the sound effects that we haven't again. So we have the diamond pickup, the heart pickup that we've already done. We have the door opening, we've done already. We have enemy death, we have the player death, player attack. We've done player hit, which means whenever the player gets hit, we didn't do we have the jumping, We have the A-M-P explosion and the bomb burning. So let me give you a couple of events right here. So the explosion and the burning should be used. Well, you can use them either in events or you can use them, use them inside off-script. Both are very good. I've tried both. Maybe we'll do both. And for example, whereas if the enemy death can be used using play clip at point the players death can be used using play one-shot can be played with using play one shot and use your imagination, do whatever you want. Try both both methods. Both are great and I'll see you in a bit. Oh, OK. So let's see what we need to do. First thing, let's go and get all of our clips. So we have the burning mom VB bomb explosion, death door closed and the me dying. And the what else should we get? The getting it and the walking. So walking will be a bit of a harder way to add. So let's see the explosion. Coup. Okay, so what should we do now? And let's go ahead and add the bomb. So what should we do embalmed? First of all, let's apply all. And I think in bomb we have, as I've told you two ways, we can either add an audio source or we don't have to. But because we have two clips to play, let's go ahead and add an audio source. And we'll go into the script for the bond. And let's go ahead and add two serialized fields, which will be of course audio clips. And we're going to add the exploding as effects and the burning as effects. Let's save that. And where should we First of all, let's get the component o. Should we first need to create the components. So it's an audio source, audio source, and it's going to be my audio source. Please. I need my audio source. Audio source. We've called it my audio source to stay consistent with my animator, let's go ahead and assign it. So these are very basic steps that I've done multiple times. I hope you've done the challenge. I hope you enjoyed the challenge and not just watching me do everything. Not because I don't like it, but because I'd like for you to solve problems. Okay, so next thing, what should we do? Well, inside of explored bomb, when ever we actually explode the bomb. That's go ahead and use my audio source dot lay one shot. And we're going to add the exploding sound effect, Cu. And right here on trigger Enter, we should play the audio source dot L1 shot, and it's going to be the burning sound effect. So save that, need to go back into Unity and never forget to assign the appropriate sound effects. So bomb explosion and bomb explosion. One burning in the burning sound effect. Apply all. And let's go try the bond, but the bump is up there, so let's get our layer up there. Cou, click on play. Let's see what happens if we go near o K. Nice, very, very, very nice. What else do we have? Let's check out challenge. We have. So we've done enemy death. Let's see enemy death felt. So enemy death, whereas it, enemy dying. Let's hear the voice. Ok, very cool. That was my imitation. So let's go into the enemy. We will not add an audio source because we have only one sound effect plays or I don't think Paul needed. Let's see where's the enemy. Let's serialize a field. So serialized field, audio, clip. And it's going to be the timing as effects. And where should we play it while we should play it? I think we can play it right here. But for now, let's go ahead and add an event just to spice things up and have fun at it. So let's go down here and let's add something right before or underwrite here. So we'll call this the void, play, dying as effects. So it's the same, but we're just trying different things to have everything and more weapons in our arsenal. So play clip at bond, it's going to be the dying sound effect. And by the way, I think playing clip at Point is actually better right here for the pig because we are destroying the object. So we need to have a backup just in case maybe the enemy dies BY ought. I mean the game object of the enemy gets destroyed. Before we even get the chance to finish sound effects. So playing clip at Point is better in this case. So let's go ahead and camera main dot transform.py position. So let's go add the sound effects in the inspector. So we have the dying and we set the enemy dying. Apply all, save that. And let's get the player down here. We're moving the player around a lot. So put them right here, click on play. And now wait for the bigger Come and pool. Nope, nothing. Did we forget? Oh, we forgot to add the event. Silly me. So let's go into dying. And right here that's played the clip a bit. Where should we add the sound? Should it be at the beginning or right here, just as he falls to the ground. Let's do this. So at a function and where should it be layered? Player nine, sounder fact, CRC that I called the player dying sound effect. I did. So enemy dying sound effect. Seriously, there's a difference. So enemy dying, sand, fact, click on play. Let's see. The biggie comes our way and okay, that was me by the way. It doesn't do it twice. Okay, great. What else do we have? Let's see, layer getting hit, which is cool. Let's do that. So go back and to the player script. So as you can see, the steps are very basic. If you didn't do the challenge yet and you still have other sound effects to complete. Go ahead, pause the video right now and continue. I've given you a lot of examples. So pause the video and go do the challenge. Oh, okay, no worries about it. So let's see. Let's call this getting hit as affects. Save that. Let's see where do we get hit? A good way to double-click on it. And if we scroll down, we can see where this source right here. And let's see what should we do? What should we do? Think we can simply add it right here after, or we can add it up trigger. So my audio source, dot play one shot and it's getting hit, getting hit as f x. So these are not the most creative names that I can get them, but they will do for now. Getting it at that, save that up thigh that, and let's see. So the heads us. Okay. Coup. Not bad. So now is the getting it and attacked the same? Oh no. Okay. Okay, great. And next thing, so I know these are not the best sound effects. Maybe you don't like them, maybe you want to get other sound effects. I encourage you to go and look your own sound effects up. There are many resources you can find for free sound effects. Oh, okay, so what else do we have? Let's see. We have the bomb explosion and burning. We've done the door opening and closing. So let's do the closing. Let's go into Unity and let's see, we need to add, so exit door and we need to be at the door. So let's go ahead and do that. It's a bit cumbersome, but it's worth it. So closing door as effects. And where should we play? It should be played in an event. Yes, I think an event is good or we can play it right here just under the Start loading level when we trigger the closed-door. And we can do that actually. So let's go ahead and add an audio source, dot play clip at point and the closing doors sound effects. Now, you should not be doing both the event and the and using play clip at point. But we're just, well, you shouldn't be using both and an event and playing the audio clip from the code directly. But we're just doing this for the sake of understanding the scope of playing sounds for all our games. So you understand everything. And now closing door sound effect. And we'll play this add camera dot domain, dot, transform, dot position. Cool. Copy that. Or let's go back into the door and right here. And let's go ahead. And because we don't have any, let's say code that plays, we don't have anything that tells us that the door's closing inside of our code will need to create an actual method for that. So we'll play closing door as effects. And let's go ahead and add the audio source, not play clip at point closing. Okay. We don't have the closing gap. So closing door as effects. Copy that. Put it right here, and we'll put it for camera. The main dot transform dot position. Save all of that. That was hard. So go back into the door and let's add the door close. And let's go and apply that for we forget exit door, door close. Apply that, save all of that. Click on play. Okay, so two door opened up on its own. The door opens up and if we go through it, we should hear the closing due. Okay. Nice. Very cool. So what else do we have? Well, there is a bit of a challenge right here and I don't think I've put it, it's the walking sound. So let's go and check the walking sound. I drink give you as a challenge because it's a bit cumbersome. So let's see, where is it? The walking. So walking, let's play it. As you can see, it's a two-step we play the truck. Truck. Truck. Truck. Okay. So where do you think we should add it? So I've experimented with this a lot. And the way we're going to do that is using the event, which will be, where is it? This error right here, we can clear it up. It's something about animations. It's not that big of a deal. No worries. Whatever error doesn't break your game entirely is not that big of a North arrow. So let's go see whereas the animation, or where's the player? And let's see walking whereas the running, okay, so inside of running, we are going to add an event and that event will play the method that will create right now, which is called steps. So let's see how we're going to create steps. First thing, let's go into player and let's go ahead and add the walking as f x. Save that. Now, let's see where should we add. We should create a Steps method where we'll create it under the decline jump run and we'll add it on the run. Okay, so we'll call this method void steps as effects. And let's see what we should be adding right here. So first thing we're going to do is we're going to check if the player is moving horizontally. So bool, player moving horizontally on. Thirdly, that shorter takes two L's or just one. And we'll use the math F dot absolute value. We've already used it somewhere right here. I'm not sure. So absolute was simply write it. So my rigid body, D dot velocity dot x should be greater than math f dot epsilon. So this will check if we are moving and you'll see why just an n-bit. So if the player is moving horizontally, what should we do right here? Well, we should check if our player is actually touching the ground. So if player, i mean, my Box Collider 2D is touching layers. With a Layer Mask, dot get mask. It will be the ground and you're breaking a bit of rules here, not, not copying the string reference. No worries. It's easy enough so we'll add the audio source will play one-shot, okay, of the walking sound effect. But there is a twist because if we're not moving horizontally, we'll do something a bit weird right here. And you can find that in the my audio source, I mean, in the Audio Source, a documentation which is my audio source, dot stop. And the reason we're doing this is because we want the walking sound effects to only play if we are actually touching the ground. Because sometimes if we're in the air and we move left or right, it could play wrong. And the other thing we want, and by the way, the walking sound as you've heard, it's like kind of stepping on stone. So we need that. So we need our player to be on the ground. And another thing is we'll need to have, make sure that the player is actually moving horizontally. And if he's not moving, so it's his velocity is 0. We want to actually stop the audio playing immediately. We don't want the walking sound effects to continue playing, playing, even though our player has stopped moving. So let's see if that worked. We'll go into the player. Let's go into the sound effects and let's add the walking, walking sound effects to the sound, the fact, and apply that. And let's see if it works. Save that. Click on play. Now. Nope, nothing. Oh, we forgot to. Every time. Every time. So we need to make a mental note of that. Always remember to use the event that you've added Michel. So where is it? Where is it? Steps, steps, sound fat, click on play. And hopefully rational. Coop. So as you can see, we walk of query no, no, OK though. So there is a bit of a bug in our game, but at least the sound effect of walking works perfectly fine. Go rate, click on start. We start the game again. We should be behind the door. Every sound effect works perfectly. We go through the door to door closes, we can hinder it. We jump. We jumped. And everything works perfectly. Correct. So I hope you enjoyed the video. It's a very, very long video and that's why I had to take a couple of pauses in between. But I hope you enjoyed it. It was worth it. We've made our game a much better and cooler game and much better experience for the player. And I hope you enjoyed it and I'll see you in the next one. 49. Adding Hearts UI: Welcome back everyone to a brand new video. And as you can see right here, we don't have the lives anymore. Actually, we can even, let's go into the scene, let's go into the lives texts and we can actually turn it off. So let's click on play and see what we have done in this video. So now instead of a number, we have hearts right here at the top, which is very cool. And we've set the limits for picking up hot. So if we pick up by another heart, the number of hearts doesn't increase. Let's get head. And as you can see, when we get hit, we lose a life. And if we pick up the slot, we increase the heart, which is very cool and makes our game an actual game. We get hit once, we get hit twice and when we have one heart left, we cannot get hit anymore because we go to the main menu. So let's not waste any more time and that gets to the k. So let's start off by adding some sprites. And we're going to go into the resources and get the lifeboat. So drag the life bar and where should we put it? Let's put it in the pickups. So when pickups, we're going to have this life bar right here will make it 34. Now maybe we'll make it bigger, we'll apply that. And in any case, let's go ahead and see what we need to do. First thing we're going to do is we will go into the Canvas, right-click and add an image. Now inside of image, let's see where it is. Double click on the image. Okay, it's somewhere up here, right here. So we're going to put it for the lives. Let's get the lives text and let's simply put it under here, will not get rid of it yet. So let's click back on the image and let's change the image. So it needs a source which is a sprite. Let's put the life bar right there. As you can see, it's not very effective or cool right now. Will need to change that a bit. Right here. You can see that we can set it to native size. So let's do that. And now we have the image set up. Let's put it up a bit, and let's put the lives down a bit. We can change the size if you want. Let's make this a bit smaller, so make it just a little bit smaller. I think That's fine. Enough. Cool. So now what we need to do is we'll need some hearts to represent will keep this just to make sure that everything is working and then we'll get rid of it. So let's represent these with hearts on them. And we'll do that by adding three hots. So we'll add big heart one big hard to m, big heart three. And they all would be images. So let's call this the lifeboat image, life bar. Or life ops. Life bar image duplicate one time called this heart. And instead of the live bar will add the big hot. So now we have a big heart, set it to native size, and we'll make it smaller and ordered to fit inside of the heart. So let's make it smaller. Let's click on w, And let's make it also a bit smaller again. So it fits right into this heart right here. Let's duplicate that and put it right here. And let's duplicate again and put it right here. Now we have three hearts. Now what we need to do is we need to first of all, apply all to the game session. So we have the Hearts and will need to take these hearts and put them as a children. Ok. So it needs to open the prefab that's chil them to the bar image. Save that. And now we have everything set up. Next thing we'll need to do is because we only have three hearts royalty. We'll need to make sure that our player, whenever he picks up hearts, he never, he never goes over the three hearts. So let's do that in Visual Studio. Right here in games session. Let's see where we add hearts. So we add hurts right here. And we'll need to create an if condition. And this condition will tell us that if players lives is bigger than or equal to three, our player lives will be equal to three. Okay? So even if we pick up seven hearts, it will check to see if the player lives is bigger or bigger than or equal to three. It will simply put it back to through R3. Next thing we'll need to do is we need to find a way to remove and add these images. The heart's whenever we pick up or lose a life. And we'll do that using arrays. And we'll also use with arrays something called a for loop. Now, I'm sure if you are a bit up or you know, a bit of coding, you already know what for loops are, or you're familiar with the name. But in any case, we'll go over them and explain what they are because we still haven't and the scores. So what is a for loop? It's similar to a for each, but it repeats an event until a certain condition is met. So it's useful when counting or iterating through arrays. Let's see how the structure of a for loop looks like. The structure of a for loop is something like this. So we have the four, we have an integer i that we create right inside of the loop. And we have a certain limit that, and we increment the i plus plus N, We do something. So what does this mean? An integer i, which starts from 0, or it can start from something different than 0. It doesn't matter. Okay? So we have the i will, the for loop will continue to iterate and we'll do the something right here until. Or while the i is smaller than this certain limit and we will keep increasing the i once, twice, and three times. Usually the certain limit is the length of an array that we have. And we'll iterate through each and through every element inside of this array until we finish the array. So i will become greater than the certain limit and then we will go out from the for loop. I've of course left you with the resources of the documentation of a for loop in the resources. So it continues to execute the code inside until I reached the certain limit. And we'll see how we are going to use that. Actually you are going to use in a challenge, but not right now, click on Visual Studio, and right here we have the score text, the life texts. And let's serialize a field. And we'll make this field and image not just an image. It will be an array of images and it will be called the hearts. So now we have the heart and let's go into Unity. And we should, okay, so project. And in games session, we should have this heartless right here. And we'll simply click on those three. Okay, now, before we do that, go into game session and anchored at this little lock right here. And let's choose the hearts and drag them into the heart. And now we have heart, heart one and hard to apply all of that. Next thing we'll need to do is we need to create a method that will update the hearts every time we either add two lives or we take lives. So let's do that and take Clive's. Whenever we have the minus minus, we're going to update hearts. And when that's copy that update hearts. And whenever we add two lives, right here, we're going to update hearts. And now let's go ahead and create the update heart is going to be void and the update hearts. And what should we do inside of it? Well, it's going to be part of your challenge. Your challenge is to finish the update hearts method. We need to enable or disable our hearts based on how many player lives we have left. So I'll give you a hint. Use for loops to iterate through the array of hearts. I've already gave you that hint sort of and with an if condition that checks for how many lives we have left. So this is a bit of a challenging challenge. It's, it's what challenges are for. And because you are going to be your first time using a for loop and it's a bit tricky. It took me a bit of time to figure out how to disable and enable hurts. But I'm sure if you give it your full concentration and full attention, you can do it. So pause the video right now and go do teach Chaldean. Welcome back. So I hope you tried your best. Let's go ahead and try to update the hearts. So. Let's see, we need to create a for loop that checks for player lives. And the, if the player lives are certain number we need to enable or disable the hot. So let's go ahead and first thing, first, create a for loop. And what should we have inside of this for loop? Well, we'll follow the traditional way of for loops. And what is the limit? So, where should to, what's the limit that we should aim for an increment? So it's going to be i, it's going to be less than the heart's array dot the length of the hearts array. And we're going to increment by one every single time. So we'll look through the entire hearts array that we've created right here, which are our hearts that we've added in the inspector. Next thing, next thing we'll need to do is we need to check for the player lives. So if we have i, ok, let's move this. If we have i less than the number of player lives. Okay? We're going to make the heart at the position i dot i enabled equals true. So we'll keep enabling the hearts which will show an hour inspector or on our image. I mean, not the inspector on our image in the Canvas. They will be enabled as long if the i is smaller than the player lives, else, it will turn off the hearts. So it's, I, well, I thought enabled will be equal false. Okay, so let's see what happens right here. We have first of all, the for loop, and this for loop goes through all Vi Hart's inside of the array of images that we have. So, and it starts from 0 and it increments by one every time with the I plus plus. So we have the hearts I dot unable. And what this does if we go into Unity, we can see that if we choose one of the hearts, for example, the first one, we can actually disable it. And that means that the enable equals false. If we turn it on, that means the unable is equal to true. So what happens right here in the if condition? Let's start. For example, we have this i equals 0. We have the AI should be, the limit of the AI should be the heart's length and i increments every time by one. So let's say for example, we have the player lives is equal two to the i starts at 0. Is the 0 less than two? It is, that means it will enable the first heart as it will increment by one and then it will continue to do the loop. So is i less than one? It is, I mean, as I equals one, is it less than two, which is the number of player lives? It is. So it will increment and we'll add the second heart. And then i increments is, i becomes two, is two less than player lies with just two. No, it isn't. It's actually equal to two. That means we will use the else and the final heart will be enabled equals false, less tested out and see if it works. I hope it does. It's a bit confusing. Click on play. And that stopped the game right here. So we can punch, you, get through the door, we pick up, they don't increase. If we get hit, hopefully one of the hearts should disappear. And they do. And as you can see right here, we have two. Let's try that again. We get hit again. We have one more life that's pick up my life and see if they update. They do update. Very nice. So I hope you enjoyed the video side, but over a short video and as you can see, the, because we've docked the canvas under game session, it is persistent from level to level. So I hope you enjoyed the video. I hope you enjoy the entire section of this course and I'll see you in the next one.