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

Playback Speed

  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 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


    • 2.

      Section 1: How To Download Unity & Visual Studio


    • 3.

      How To Use This Course


    • 4.

      How To Work In Unity Interface


    • 5.

      Writing Your First Code In C#


    • 6.

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


    • 7.

      Setting Up The .gitignore File


    • 8.

      Print Using Debug.Log()


    • 9.

      Variables 101


    • 10.

      Responding To Player Input


    • 11.

      Adding Rigid Bodies & Colliders


    • 12.

      Adding Magic To Our Cube


    • 13.

      Using If, Else If, Else Statements


    • 14.

      Public Methods & Return Types


    • 15.

      Prefabs And Parent Child Relationships


    • 16.

      Section 3: Setting Up Our World - Game Design


    • 17.

      How To Slice Up Sprites In Unity


    • 18.

      Tile Maps In Unity


    • 19.

      Rule Tiles 101 (2D Extras)


    • 20.

      Adding Our First Animations


    • 21.

      Animation Transitions


    • 22.

      Adding 2D Collisions


    • 23.

      Section 4: Moving Our Conqueror Horizontally


    • 24.

      Flipping Our Players Sprite


    • 25.

      How To Trigger Animations From Code


    • 26.

      Adding The Ability To JUMP!


    • 27.

      Tweaking Jumping Using IsTouchingLayers()


    • 28.

      How To Prevent Wall Jumping


    • 29.

      How To Add Climbing Mechanics


    • 30.

      Tweaking Climbing Mechanics


    • 31.

      Cinemachine Follow Camera


    • 32.

      Cinemachine Confiner Extension


    • 33.

      State Driven Cameras


    • 34.

      Section 5: Adding Enemies And Bombs - Making Enemies


    • 35.

      Player Hit


    • 36.

      Drop The BOMB


    • 37.

      Exploding Our Conqueror


    • 38.

      Adding The Attack Ability (How To Use Arrays)


    • 39.

      Killing Off Our Enemies


    • 40.

      Section 6: Controlling Our Game - Adding Levels


    • 41.

      Exit Door


    • 42.

      Main Menu & Success Level


    • 43.

      Game Session


    • 44.

      Hearts and Diamonds Pickup


    • 45.

      Adding Sound Effects (SFX)


    • 46.

      Persistent Lives And Score


    • 47.

      Bonus Section: Level Enter


    • 48.

      Adding SFX To Everything


    • 49.

      Adding Hearts UI


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





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


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


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 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,, 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 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, 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 groun