Ultimate Guide to C# And Unity 3D: Learn to Code By Making A 3D Game (2021) | Michael Murr | Skillshare

Playback Speed


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

Ultimate Guide to C# And Unity 3D: Learn to Code By Making A 3D Game (2021)

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

41 Lessons (8h 43m)
    • 1. Why You Should Watch This Course

      4:33
    • 2. Download Unity & Visual Studio Step-by-Step

      5:28
    • 3. Unity & Visual Studio 101

      8:55
    • 4. Your First Code

      11:06
    • 5. SECTION 2: MAGIC SHAPES 3D Print To Console With Debug.Log()

      12:27
    • 6. Variables 101

      12:02
    • 7. Rigid Bodies And Colliders

      12:55
    • 8. Prefabs & Basic Input System

      18:12
    • 9. If-Else Statements

      13:13
    • 10. Arrays & Loops

      14:20
    • 11. Creating Chaos

      8:49
    • 12. Public Methods & Return Types

      12:12
    • 13. SECTION 3: CREATING OUR ROCKET SHIPIntroduction To Version Control

      13:30
    • 14. Shaping Our Rocket Ship

      22:07
    • 15. Basic Rocket Inputs

      12:18
    • 16. Flying Our Rocket Ship

      7:39
    • 17. Rotating Our Rocket Ship

      14:07
    • 18. Adding Audio

      13:55
    • 19. Solving Movement Bugs

      13:50
    • 20. Designers Inspector

      9:32
    • 21. SECTION 4: LEVEL DESIGN Using Tags On GameObjects

      18:34
    • 22. Level Design 101

      16:36
    • 23. Level Design Tuning

      10:56
    • 24. Making A Second Level

      7:51
    • 25. Prefabs In More Details

      6:02
    • 26. Level Loading & Scene Management

      12:46
    • 27. Using Coroutines

      13:31
    • 28. Level Debug Keys

      10:59
    • 29. Looping Through Levels

      9:59
    • 30. SECTION 5: ADVANCED ROCKET SHIP DESIGNAdding Multiple SFX

      12:39
    • 31. Particle Effects 101

      20:37
    • 32. Cinemachine Follow Camera

      12:05
    • 33. Adding A HealthBar (part 1)

      21:46
    • 34. Adding A HealthBar (part 2)

      12:11
    • 35. Adding Shaky Camera

      8:58
    • 36. SECTION 6: ADVANCED LEVEL DESIGN Animating Obstacles

      13:22
    • 37. Lighting Our Scenes

      12:38
    • 38. Making Game Moments

      9:58
    • 39. Turning UI On & Off

      14:51
    • 40. Creating Title Menu (part 1)

      21:58
    • 41. Creating Title Menu (part 2)

      13:07
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

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.

559

Students

--

Projects

About This Class

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

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.

The main project of this course if the Space Bound Rocket Ship 3D and It's the prefect project for students from any level. As it has a ton of options to play around with a discover the ins and outs of Unity Engine, at the same time providing opportunities at every turn to use basic C# coding and advanced C# coding.

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:

Is where we set everything up. I will take you step by step through the process of downloading Unity, installing it and integrating it with Visual studio. We also talk about how you can use this course and take full advantage of everything in it

Section 2 - Magic Shapes 3D - Basics of Unity and C#:

Is where we create the foundation of Unity and C#. If you are new to C3 and Unity and have zero experience this is the perfect place to start as we'll go into everything that we'll need for our future BIG project. You'll learn about the basics of C# such as variables, if statements and arrays while building a fun mini game in Unity to help you get started

Section 3 -  Creating Our Rocket:

We begin the process of creating our incredible rocket. We start of by shaping our rocket and you'll create your rocket you can make it whatever your heart desires. We'll learn to fly our rocket based on players Input. We'll also learn to add audio to our rocket and all of that while delving deeper into Unities system and understanding various concepts in C#

Section 4 - Level Design:

Is where we start creating our levels. Because every great rocket needs a great Space to fly in. We'll understand the basics of Game Design and how industries look at the basics before before creating levels. We'll understand scene management in Unity and C# and have a fully functioning at the end of the section

Section 5 - Advanced Rocket Ship Design:

This is where we take our rocket to the next level. We add a new dimension to our game with a follow cam. We'll learn about an incredible tool of unlimited creativity called Unity's particle system to help us create explosion effects and flames from our rocket. We'll add even more sound effects. And finally add a health bar to our rocket and have extra game mechanics

Section 6 - Advanced Level Design:

With our new rocket we need new spaces for it to fly in. We'll delve deeper into Unity Engine and learn about lighting our game to make some incredible scenery. We'll learn about animations and apply them to our obstacles to make them more dynamic. And finally we'll create a title Menu for our game with interactable buttons to start off our game 

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. Create a Flying Rocket Ship from basic 3D Shapes

  12. Learn physics based rotation

  13. Learn about Unities Particle System

  14. Create Explosion effects and flames from our Rocket Ship

  15. Learn the core of Game Design and what makes levels fun

  16. Create multiple levels in game and how to move through them

  17. Understand complex C# coding technics like "Coroutines

  18. Create Debug Keys that allow you to play test your levels fast

  19. Use Cinemachine a versatile Unity tool to add Follow Camera

  20. Add multiple audios to our Game and different ways to do it

  21. Create a Health Bar that dynamically changes when Rocket is hit

  22. Shake your camera to create impact forces

  23. Learn in detail every aspect of lighting in Unity

  24. Understand how to animate to make them rotate, move and translate objects in levels

  25. Create an interactable Title Menu with buttons and sliders

Meet Your Teacher

Teacher Profile Image

Michael Murr

Software Engineer :: Game Developer

Teacher

Hi there, my name is Michael Murr. I'm a software engineer from one the most highly esteemed universities in the middle east. 

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

Now a Software Engineer with more than 10 years of experience.

Over the years I've helped thousands of student create games, learn how to code and set their life up for opportunities in many fields that require a software programming skillset. And I will help you do the same.

I have a complete mastery of Python, C#, JAVA, C++ and my aim is to teach you all of these and more in a fun way.

I cannot wait to help you start on your journey and help you along every step.

I'll see you very soon!See full profile

Class Ratings

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

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

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

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

Transcripts

1. Why You Should Watch This Course: Game development as an art of unlimited potential and the creativity and every game developer needs three essential skills, programming ability, game engine and game design. I would love to teach you all three. And the best way to learn anything is by creating and doing it in a fun way. My name is Michael Moore, founder of WMD in depth and I want to share my knowledge of game development. Would you have developed a strategy to help you become the best team developer and the most fun way possible using Unity's engine, we are going to build our 3D game. Thousands of aspiring game developers have created real-world gain using the strategy. And I want you to do the same. I've learned that can be really difficult to know where to start when it comes to game development, because I've been there and what steps to take to go from complete beginner to absolute master, not only in game development, but also in learning how to code. And I can say with absolute confidence in the scores, makes it easy beginner with 0 coding experience to jump in and learn how to create incredible gains. We leave no stone unturned. We delve deeper than any other courses into every aspect of the Unity 3D, C-sharp, and game design. And the most amazing parties is we are doing all of this, the latest version of unity with the newest techniques and content and modern game development, I've helped thousands of people create real-world games, and I want you to be one of those people. So how are we going to do this? In Section one, we have the introduction and it's where we are going to set everything up, will download humanity and integrated with Visual Studio. We'll learn the interface of both tools and create our first code just so we can get overall initial fears. In section two, we begin building the foundations for our big project with a mini-project, magic shapes 3D. We'll learn the basics of sharp by understanding of variables are if statements are how arrays work, and all of this while creating a fun game in Unity and learning the basics there also. And if you already have unit installed and know how to use it, we can immediately jumped into section three, and that's where we'll begin building our rocket. We'll learn about creating materials, creating movement, adding audio to our rocket, and really making Elon Musk proud. When we have our rocket ready, we'll need a space for it to fly in. That's where section four comes in. And it's all about level design. Will talk about the basics of level design and what it takes to make fun levels and games. We'll learn how to create obstacles for our players and explore seen management and code that will enable us to move through the levels that we create. Section five as advanced rocket design. And it's where we take our rockets to. The next level will add new dimensions to working with a follow cap and the breathe more life and our rocket by creating particle effect, the more audio and adding a health bar with extra game mechanics. Finally, we'll move to Section six and elsewhere will delve deeper into novel design. We'll expand our knowledge of unity by learning how to manipulate lighting, create main menus, and move our obstacles to make our game more fun and interesting. So what should you expect by the end of this course, you'll become a master problem solver, will understand the fundamentals of C-sharp coding and learn how to program games, just like the ones you're seeing on the screen right now. You'll also have the chance to flex your game developer muscles because with every video there is a mini challenge for you to complete. And even if you can figure out how to do the challenge, I'll be there to complete it with you after we've tried, everything in, our game will be configurable. So you can tweak, play around and give the game and individual and special feel about it. So you'll be putting in your own creativity into it and really making it your own. I'm so excited to get started and I hope you are too. This is the perfect time to start learning how to code. So biv been with me and I will help you along every single step of your game development journey. 2. Download Unity & Visual Studio Step-by-Step: Welcome back everyone. So in this video we are simply going to be downloaded in the unity hub, 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 to unity hub and you should get this search result. So simply go and click on the download unity hub. It should be the first link which would be on the Unity 3D.com website. And it will take you to this page right here, and it will ask you to download unity hub. Now, what is unity hub? Well, unity hub is a place where we can add different versions of Unity. And we can also have all of all, all of our projects 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 and 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 installed, 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.2 one. So maybe you're from the future and you have a better version or a more, or a newer version. And an order to add a new version, you simply click right here on the app. So when you click on Add, it gives you a 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. Unity & Visual Studio 101: Okay, so welcome back to another video. Let's see what is unity. So unity is a cross-platform game engine developed by Unity Technologies, will 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, an 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. 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, 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 we'll not get much into that. On the right side of those, we have the layer visibility 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. 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 if you don't select the 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 seeing. The scene view can show either a 3D perspective or a 2D perspective depending on the type of project that you are using. You can also, right here click on the to the button and it will go 3D. So as you can see, we have this 3D view but we won't be needing, it, will simply go into the, to the mop. 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 something very important and that is the Visual Studio. So what is Visual Studio? Well, Visual Studio is id. And IDE is an Integrated Development environment. And what it does, it actually asked meaning Visual Studio will help us write the code used to manipulate game objects in 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. 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'll 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 are 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 right here, allows us to use the 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 class name, 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 this to 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 Common. So whenever you write code and add these two lines right here, it will comment things out and comments actually don't get executed and gold 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 this is called a method we'll start to execute. Next thing we have the update, and the update is called once per Frank. 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 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 him us go to the next video and we'll make our first coat and gets started. So I'll see you in the next video. 4. Your First Code: Welcome back my fellow game developers. And as you can see right here, we have a message and we're actually inside of Unity. We've created a game object. We've put a message inside of the console, and we've actually also created a couple of lines of code. So this will be your first code. It's very exciting. Let's not waste any more time and let's get started. Oh, okay, so let's get started. First of all, we need to open up our unity hub and inhere they tell us that you have no project, but no worries. We are going to change that in just a bit. First of all, click on the new right here, and this window will open up. And in here you can choose whether you want to make your project a 2D or a 3D project. And the other two are high definition rp, where you create a lot more graphics and universal render pipeline, which is similar to 3D, but has a bit of differences that we will not cover right now. Let's continue on. The first thing you need to do is you need to make sure that you have the proper location of created a folder inside of the D directory, which is unity projects. And there is where I saved all my Unity projects. And I also recommend that you do the same. Next thing you need to do is you need to name your project. We're going to name our project. Hello, World. Great. So now that you have your project name set up, you know the location and make sure you choose a 3D because our game will be in 3D, simply hit on Create. And now we are going to wait for our project to compile. I'm not gonna bore you with this. I am going to use magic of editing and I will see you when my project compiles. So I'll see you in a bit. Oh, okay, welcome back. So as you can see right now, we are in unity. And this is my layout. If you don't have the same layout as me, simply go to Les UPS, layouts out here appear and click on Default and make the screen bigger. And we should both have the same layout. Now, as you can see, we have something new right here, which is the console. And if you don't have the console, go to window, go to general, and go down and search for console. You should see it right here. Simply click on it. You'll have a window and you can dock it wherever you want. And currently docking it right here next to project. Great. Now, what will we be doing? First of all, we are going to create a script in order to see how Visual Studio and Unity engine actually communicate with each other. So let's go ahead and do that. Right-click on here. And our projects go to Create. And you will find here that you can actually create a C-sharp script. So click on that. And before we do anything, stop right now. Before we continue on when we need to make sure that we name our script properly, because the name of our script will be the name of our class. And we can actually change the name of our script later on or in the name of our class. But there will be a lot of errors. So to avoid them, whenever you create a script, made sure that you name it properly. So we're going to name our script. Hello, world. And when you're satisfied with the name of your script, hit Enter and wait for integrity to start compiling your C-sharp script. As you can see right here, you can have a glimpse of what your C-sharp script looks like. And it already has a couple of lines of code. Let's simply double-click on hello world and open it up. And our Visual Studio, O case. So now we have Visual Studio ready. And I've talked about a couple of things. I've talked about namespaces at, about the start and the update. I will not be going over them again. Because later on we will also delve even deeper into them when we start our first Magic game cube 3D. So let's start by first of all, printing something to the console. And the way we print things to the console, as we simply write in here, print. And immediately you can see that even without finishing the word print, Visual Studio or the front helps us out and tells us that you are kind of writing print. So let me help you out when you get to this point and you don't want to finish it, finish writing your own sentence, simply hit the tab button and Visual Studio continues automatically. So we need to open up these brackets and you can read under the, under the code right here that you, this logs messages to unities console. Perfect, so this is what we actually need. And you can see also the way that we need to add a message right here. And this message can be or should be a string. And what a string is, is it's a type of variable that we'll talk about later on. But all you need to understand that a string is something that we put between these two quotes right here. And it's a string of characters so we can write words and sentences inside. So first thing we're going to write, of course, is hello world with an exclamation mark. And you can see that here we have this squiggly red line. And what this means, it's an indication from Visual Studio telling us that, whoa, whoa, whoa, there is a problem here. And the problem, if we hover over it, that it is expecting this semicolon right here. So we add, and every line in c-sharp needs to have a semicolon at the end of it. Now we need to save our script before we go back to Unity. And whenever you haven't saved your script yet, you can see this little asterisks right here on the helloworld dot cs. And to save your script, simply click on Control as and it will be saved. When it saved their is no longer the small asteroids, correct? Now let's go back into Unity and wait for the unit to understand that we have done some changes. You can see that it's changed right here in the inspector. And now when we click on play, we should see something in the console, but that will not be the case that we demonstrate. So when we click on play, we're looking at our console, but there is nothing there. Why is that? Well, because we haven't attached R script to anything. So even though we've created our code and it's very well-written and should work perfectly fine. It's not attached to anything in our game scene or in our game. So let's change that by creating a game object, we can also attach it to the main camera or the direct light, but will not do that. We'll create our own game object. And the way we do that by right-clicking in the hierarchy. And let's go down and for now let's simply create an empty game object. So this is an empty game object. And here you can see the transform, which is the position, the rotation, and the scale of our object. So if we click on our game object, hit the W key. Now we can change the position of this game object up and down and left and right and all sorts of directions. And we can reset its position by going up here and hitting these three little the points right here and hitting the reset. So the transforms, position, rotation and scale will be reset to 0. And once great, now what we want to do is we want to attach this Hello World script to our game object. The way we do that is very simple. We can either drag the hello world into the hierarchy on our game object or we can drag it right here in the inspector if we have game object on it. So let's do this right here. And as you can see, a new component has been added to our game object. So now our game object, which is part of our scene, which works inside of our game, has this script attached to it. And this script that is attached to something in our world is telling it or telling became objects that you need to print out hello world to the console. So let's see if that works. Let's save our scene. Also, you can see we have an asterisk, Control S, collect on play. And now if you go to the console, you can see that it says Hello, world. Nice. So we can now rest assured that this actually works. And now that you have complete faith in the workings of the V scripts and Unity, it's time for your challenge. And your challenge is to print your own name. So instead of hello world, print your own name on the console. And you, what you need to do is you need to change the Hello World to hello and then add your name next to it. So I'll give you a couple of hands because the video, if you already know how to do this, pause the video right now and go do the challenge. If not, follow with me. So add your name inside of the three points that I have told you right here, saved Visual Studio, this is very important. Go to unity and click on play. Check your console and make sure that it works and that you can see your name inside of the concept. So pause the video right now and go do each challenge. Ow, kay, welcome back. So how did you get on with that? Let me do the challenge myself. So instead of hello world, I'm going to write my own name here and it's going to be hello Michael. So hello Michael with an exclamation marks. Let's do so. We save that. We go back in unity. And in here we can actually remove the clear on play. And now when we click on play, we have hello MIchael, and we can clear all of that. We can then go back and click on play again. And we can see Hello Michael. So this is your introduction to unity. This is a very important part. This is where we get over the fear of using code. This is where we get over the fear of using Visual Studio and a Unity engine, which are both very scary at first sight, but as you can see, they are things that we can use to create incredible gains. So I'll see you in the next video. 5. SECTION 2: MAGIC SHAPES 3D Print To Console With Debug.Log(): Welcome back my fellow game developers. And as you can see, we've already created a 3D scene with an object called shapes Palmer, and we've added a script to it, which is a shape spawner With explained what all the namespaces are, what start is, what update is. And we've actually printed got couple of lines right here in our console, but not just a message. We also printed a warning and we've printed also an error. So let's not waste any more time and let's get started. Oh, okay, so first thing we're going to do is we're going to create a new project. So open up your unity hub right here. Click on New. And here we can choose which kind of project we want to create. So it's going to be a 3D project, and it's going to be called the Magic game Q 3D. Very nice. So let's go ahead and create a, make sure that you have the proper location for it to save. And mine is in the D directory with inside of Unity project. So click on Create, and we are simply going to wait for this whole time. But because I have the ability to use magic of editing, I'm going to simply skip through this whole process and I'll see you in just a bit. Oh, okay, great. So now you should have the same view as I do whenever your project finishes compiling. If you don't have the same view, you can go right here onto the default and I mean into the layout and click on the default one. And this should give you the same layout that I have. Okay, great. Now, now that we have set up the interface, it's time to, first of all, create an object. So we go into our hierarchy right here under the, under the sample scene. And actually let's go ahead and change the sample scene and let's simply make it our level one. We won't have any other levels, but just to get into the habit of naming our scenes were Create will name this level one. So right-click in our hierarchy and go ahead and create an empty game object. And as you can see, it spawned in the middle of our scene right here. If it's not in the middle, you can see right here that is all zeros. You can actually reset its position. So even if it's some kind of different position than mine, you can simply reset it and it's going to be on the 00. Very nice. Now, this game object is going to be our shape spawner. It's where our shapes are going to be created. So we'll name this our shape spawn. Cool. So now we have a shape spawner in our scene. Next thing we need to do is we need to create a script for our shape spawners. So let's go ahead and do that. Right-click in the inside of the project. Go to Create and C-sharp script. And this SSH script is going to be called Shape spawner. Let's click on that and wait for it to compile. Here we have it ready to use. And before we forget, let's go ahead and add it to the shapes spawner and our hierarchy. And now if we click on our object, you can see that the script is attached right here under the transport. Very nice. Next thing we're going to do is we're going to simply open this up. And it should open up in Visual Studio and wait for it to open up. Oh, okay, great. So as you can see right here, we have a lot of code that is already present and let me just take you through it a little bit before we get started. So here we have these three lines which are losing system collection using system collections generic and the using the Unity engine and what these three lines are called R. These are namespaces and what namespaces allow us to do is they allow us to use a different functions from a specific entity. So for example, let's explain the Unity engine right here. This allows us to first of all use the start and update, which we'll get to in just a bit. And it will allow us to manipulate the behavior of certain objects which are present in our Unity engine right here. So for example, we can access D-shaped spawner, change its position. We can do lots of things because we are using the Unity engine namespace. Now, under Unity engine, you can see that it's a public. We'll go over what is public, it a class. And it has the name of shapes Palmer. Now this shape Spawner is the name of the script that we gave it. And that's why I always tell you that you need to make sure that whenever you name your script that it's named, the two are going to stick to because if you change the name of the script, the name of the class won't change and there will be lots of errors in the future. And Mano behavior is, as you can see right here, it's every unit is script, a base that you can use. So mana behavior allows you to use the start, the update, and other functions that we'll be using later on. So let's talk about the start. What is d start will distort is called on the frame when a script is enabled just before the update. So what does that all mean? If we go into unity, for example, and we click on play when we start. So now we've started the start method in the shape spawner will start. So it's the first thing that starts whenever we go into our game mode. Let's go out from here and back in Unity. So next thing we have is the update. And the update is called once per frame, as you can see right here in the comment. And it's used to implement any kind of game script. So if we want to move our objects, we use the update. If we, what? If we want to get input from a player? We use the update. If we want to change the position, rotation, maybe starts something. No, I don't want to update right now. If we want to do anything that involves movement and changing direction or behavior, we always use it an update because this function is called Every single. Frank, I went will demonstrate that in just a bit. But first thing, let's go ahead and use, let's print something to our console. And we're going to use something different than print. And it's actually the debug dot clock. So the way we do that is we simply write debug dot log. And if you're wondering how I'm actually auto completing these, I am simply writing debug dot and it gives me options. I write the L o and then I press on tab and it continues whatever option I've chosen. And inside of here we're going to write a message which is going to be, Hey, there, I'm using debug in start. So let's close that and always remember to add a semi-colon. And now if we go into our unity, we collect on play. We should see in the console right here that Hey there, I'm using debugging start. Very nice. And if you don't have the console, go into the window, go into the general and you should have the console right here ready for you to use. I've doctored next to project because this is a, my favorite place to dock the console. Now let's go ahead and see what happens if we use this line right here inside of the update. So let's copy that. Paste it in here, and we'll use the debug and silo update. Save that back into Unity. And let's see what happens when we click on play. And you can see that we have every single frame we are printing to the console. Hey, there, I'm using debug and update. Very nice. So these are the basics of the debulk. It's nothing special. It's exactly the same as the print, but I wanted to use the debug because, because it's a much more professional way of printing things to our console and we will be using it later on for while debugging. We will. This is used, for example, if we have a method and we're not sure if we're actually entering that method or function. We use the debugger to print something and that will enable us to understand if we have anything working. Now, another thing or another feature of debug, let's simply remove this right here because we won't be using it and update it. Another feature of Deepa debug that is very helpful is the debug dot log warning. So instead of simply printing a message, we can actually print a warning. So Hey there. This is a warning with an exclamation mark. Let's close that and let's see what happens when we click on play in unity. So we click on play. And as you can see, hey there, this is a warning and it's actually a different kind of symbol right here. If you can't see it, you should look right here on your right. And you can actually disable and enable if you can view errors or message or warnings. So the warnings are like they are a step above the normal messages that help us to understand that this should not be happening. Or for example, this or something is missing or something is not right. And last of all, we have something that is the debug dot log error. And this actually allows us to print an error. So hey there, this is an error. Cu so, oh, I'm not sure what that is. That's simply click on this and the X, save that. And Hey there, this is an error. And if we go into Unity, collect on play, we can see that this prints an error. An error means that we have something very fatal and we should make sure to change that and corrected and code of course. So let's go back from there. And let's see. So we have the debug dot blog, debug dot warning and the debug that error. And now it's time for your challenge. And your challenge is simply to be to add a couple of lines. So add one message that displays on the console telling the player to press a certain arrow. For example, add one warning message. It can be whatever you want and add one error message. So pause the video right now and go do the Challenger. Oh, okay, welcome back. So how did you get on with that? I hope you tried your best. Let's change this debug log right here. And let's tell the player to press the left arrow key to go left. And in the warning, let's go ahead and change that. Don't press right arrow key to go left. And in the end, the arrow, we should write. Pressing the right arrow key to go. Left is fatal with two exclamation marks. Oops, with two exclamation marks. So let's save that. Let's go back into Unity. Let's click on play. And inside of console we can see that press the left arrow key to go left. Don't press the right arrow key to go left. And pressing the right arrow key to go left is fatal. So I hope you enjoyed this very simple video. It's nothing new. We already printed something to the console before, but this is a more professional and robust way. So I'll see you in the next one. 6. Variables 101: Welcome back everyone to a brand new video. And this one we are going to learn all about variables. So as you can see right here, there is nothing that really catches the eye. It's simply numbers and words. But if we look deep down into our code, we can see that we've added three variables. One is float, one is integer, and one string. And we've actually integrated our variables inside of our debug dot blog, which is a very cool aspect of coating and extremely helpful and versatile. And it really takes us to the next level of coding and writings sharp. So I hope you enjoyed the video and Let's not waste any more time and get started. Oh, okay, so what are variables? Let me tell you all about variables. So let me put on my laser and now we're ready to go. So variables are like boxes. So let's say we have a box and this box has a name, and the name of this box is life's. So what do we do with the box? Well, we put things inside of it. So we put in, for example, a three inside of the box. So now we have a box that has a name of lives and it has an integer which is three inside of it. And this is exactly how variable works. So this is how we introduce variables inside of our code. We have the public, which is the accessibility. We have public and private variables. Public variables can be used anywhere in our code. Private variables are only used inside of the script or the class which are the same that we've created. Then we have the integer, and this is the type of variable that we have. So for example, right here, the integer, the variable is three, that means it's an integer. Then we have the name of our variable. And finally we have the data that we want to put in our variable. So let's talk about the different types of variables that we have. We have, we've talked about integer, now we talk about the float. So for example, you can have the velocity of a car. It's not, for example, ten miles per hour or 20 miles per hour. It can be sometimes 4.8 miles per hour or 6.7 miles per hours. So it's always, whenever we have a variable that can have a float, we used this float velocity equals 4.8. And whenever we create a float, we need to add the f at the end of it. I. Another thing that we need to keep in mind whenever we are naming our variables, that the first word of a variable is always with a minimized or a lowercase first character. So for example, velocity V is always in the lowercase. We'll show how sometimes you will see Apple uppercase. So this is an example of the uppercase. And it's a variable that is a Boolean. And a boolean can either be true or it can be false. This is very helpful. We will be using this boolean variable a lot in all projects. So keep this in mind. And as you can see right here, the naming convention. The first word, which is, is, is in the lowercase, while the second word, which is that is in the uppercase. So this Boolean, which is named is that is equals to true and it can be sometimes equal to false. And the last type of variable that we are going to talk about is the string variable. And string means a string of character, characters next to each other. So here we have a box with the name of my name and my name is Michael. So the string of characters which are ICH, et cetera, et cetera, are string together to create one variable which is of String type. So let's now try and implement variables in a good way in our code so we can see the effectiveness of variables. Let's go back into our Visual Studio, O k. So how are we going to use variables right here? Let's first of all, we remove the warning and error as will not be using them right now. And let's go ahead and create a variable appear. But what should this variable B? Before we do that, let us create a circumstance to use our variable. So let's say here we have the, press the left arrow key to go left. Let's say for example, we need to press the arrow key several times. So press the left arrow key five times to go. Laughed, very nice. So now if we save it and we go back in Unity, we click on play. We should get here. So let's press the left arrow key five times to go left. Okay, so let's say we want to change this. Let's say we need to press it seven times. We save that, we go back and unity and we see that we need to pass it seven times. But this is very easy, unconventional because we have 20 lines of code. What would you do if we had, let's say, 2 thousand lines of code? And you need to find this right here, this message debug dot log. And you need to find the precise place where there is a seven and you need to change it. Well, this is where variables comes in. So let's go ahead and create a variable. Let's say it's a private. So we can write private, we can write if in private and then hit the Tab. So it's private. It's an integer, and it's going to be called number of times. So as you can see, I've named this convention way, conventional way of naming variables. The first word is in a lowercase. Second World has the first flatter and the uppercase and the last word also for every subsequent work has the first letter in the uppercase. Anyways, now we can actually go ahead and put a seven and side of our number of times. And let's use it right here in our debug.org. So instead of the seven, we're going to add these two. Quotas right here, I'm not sure if they are called quotas are called them quotas. We add a plus and we write here number of times, and we add another plus. So let's save that. And let's change this to, for example, 236. We'll save that. So we go back into Unity. And now we have this five right here. We're collecting play. And now we need to press the left arrow key 236 times to go left. Very nice. And I did something in a previous video that I've noticed was too fast and I actually can clear this console. If you click clear on this right here, we click Clear, Everything is cleared from our console. And another very cool feature is that you can clear on play. So whenever you hit play again, everything in the console is cleared. Okay, and I saw this was a side-note. Cool. So now you can see the effectiveness of variables inside of our code. Let's go ahead and create another variable. We'll make this one public. And it's going to be a float variable. And what should our float variable b? Well, it should be, for example, the speed, the speed of and it's going to be, let's say 6.93. And let's see where we can add it. So press the left arrow key number of times. And as you can see right here, your instructor has just made a mistake and we did not add the f at the end of our variable. So let's go ahead and do that. One thing to keep in mind is that making mistakes is perfectly fine as long as you take responsibility for them and make sure you try to never make them again. Anyways, let's continue on. So press the left arrow key number of times to go left at the speed of, Let's say this is a, this is purely for example. And we'll add the speed of variable at the Android here and remove the quarter at that, save that. Let's go back into Unity and see if that works. Click on play and press the left arrow key 236 times to go left at the speed of 6.93. Very nice. So right now we can also change this immediately to whatever we want and directly changes it without us going in and changing string inside of the debug dot. And this is, the variables are extremely important and they are actually the most important part, I believe, in coating. They are used everywhere, in every conceivable, conceivable code that you can imagine. And that said, it's time for your challenge. And your challenge is going to be to create your own variables. So first of all, you need to create a variable of type string and use it in the debug log log message. You can even create another debugged O'Clock message if you want. And you need to change the string variable and check to see if it changes in the console. So pause the video right now and go do the challenge. Okay, welcome back. How did you grow that? I hope you didn't just stare at the screen a couple of seconds waiting for me. Anyways, let's go ahead and create a variable. It's going to be a string. So if we don't add anything behind the string, the variable will be public. And recall, we're going to call this string the arrow to press. And it's going to be the left arrow, or simply left. Or let's change it actually to write. And let's save that. And now right here, so we're going to press V at two quarters at a plus, and it's going to be V arrow to press. Ok. Nice. So let's see if that work and always remember to save the way, you know, if you haven't saved yet, you need to check up here. And you can see that it has a little star next to it. This means that the script hasn't been saved in order to save simply cold or press Control S. And everything should be saved on your script and go back into Unity. And let's click on play and see what happens. So we need to press the right arrow. Okay, nice. So let's change that into the up arrow. Save that again, go back into Unity. And of course we have the clear on play if we remove the clear on place. So maybe this is a better option. So we remove column, click on play, and we have the press up arrow key 236 times the speed of 6.93. Very nice. And I don't know if you've noticed maybe some of you that are sharp. I noticed that in the script we have this right here in the inspector. So what is this value? Well, we can actually change this value. For example, click on play and devalue and here will also change, which is a very helpful tool. And you're going to need that we're going to talk about later on in our project. So I hope you enjoyed the video and I'll see you in the next one. 7. Rigid Bodies And Colliders: Welcome back, my fellow game developers. In this video, we've added a platform. We've added a cube with a rigid body and box colliders that we are going to talk about. And when we collect on play, r cube actually falls down and bounces on our platform. So this is a very fun video. It's one of the most exciting one. Let's not waste any more time and let's get started. Oh, okay, so first step is to create a cube. So let's go ahead and create a queue. Let's right-click and our hierarchy right here, go to 3D object and create a queue. So now we have a cube, and as I've told you before that go ahead and reset its position. And if it was too fast for you, this is the transform. These are the three buttons that we need to click, and here we have an option to reset the transport. So now it is on the position 0, rotation of 0 and the scale is 111. That's move it up a bit right here so we can see clearly. And if we click on the Game view, we can see that we have a cube and our game view. Let's change this from three aspects to 16 by nine, and this simply helps us to maintain a good ratio. So let's go ahead, let's go back and seen. And as you can see right here, we have a lot of things attached to our cube and the inspector. So let's talk about them a little bit. First of all, we have the mesh, and this mesh is what determines the ops. So cube smash is what determines the shape that we have. So for example, we can choose a capsule, a cylinder, or a sphere, a quad, a plane, everything, whatever we want, but for now we'll keep it as a cube. Next thing, we have the mesh renderer, and this is actually where we can tweak how r cube looks. So we can change this from the default material to a different default sprite frame. Not sure what that is. That's the, that's making it a black hole. And if the sun and camera are bothering you, you can actually turn up the gizmos, or you can simply make the gizmos a lot smaller so they don't bother us. It's up here on the gizmos. Okay, cool. So now we have our black dark cubelets changed back to its default material. But was it well, default material, it doesn't matter. And you also have the lighting probes and additional settings that you can go in-depth. And finally, we have this box collider around our cube. Now what is this box collider? But before we talk about Box Collider, trust me, we'll talk about Box Collider. Let's first talk about rigid bodies. Now, what are rigid bodies? Now? If we click on play, we can see that we simply have a cube and a small message that we should remove. Anyways, we have a cube root here, but nothing happens to it. It's simply a game object and it doesn't have any life in it. So how do we add life to our cube? We need to add something called a rigid body. Now what is this rigid body and how do we add it? It simply right here in the Add component. If we click on it, we can go ahead and search for rigid body. And we have two types of rigid body. We have Rigid Body 2D and we have the rigid body without anything, which is 43 d, and we are working in 3D. So let's go ahead and add a rigid body. Now, if we click on play, we can see that r cube starts falling down. Why is that? Well, let me explain with a couple of slides. So what is a rigid body? It is, it gives us control of an object's position through physics simulation. Rigid body object will be pulled downward by gravity without adding any code. And we can also apply our own forces on them. So back in Unity is a very simple explanation of rigid body. I've loved you the documentation in Unity. Or you can simply go ahead and Google search for unity or rigid body unity and you will get a link to the documentation you can read all about rigid body. But as you can see right now, our rigid body adds mass. It adds drag, it adds angular drag, and it adds gravity. We can also make it kinematic. There are many things that we can change about our game object when we have a rigid body attached to it and actually mix everything in our game much more natural, and it actually adds a physical element. It makes our game work with the physics of unities engine and now r cube and we click on Play, simply falls down. Now another option that we have is we can simply turn off the Use Gravity. And now if we click on play, our object doesn't fall down. So cool, that's very nice. Clear on Play, clear that, save all of that. And what should we be doing next? Well, we should be explaining a bit about box colliders. So let's click on this right here, which is the Edit bounding volume. If we click on it, we can see that there is a green square on each side of our cube. And this makes it a green cube. We can actually change this so we can increase its size. And this is actually what allows us to interact with other game objects that have box colliders on them. So let me talk about Box colliders and habit. So what is a Box Collider or a collider? And our case it's a box collider, but because it's around the box. So it makes it possible for objects to interact and collide, hence the collider with one another. And we'll use it to catch objects that have a rigid body and are falling because of gravity or any other reason for them to fall. So let's go back and see what our box collider actually does. But before we do that, well actually you are going to find out how a Box Collider works because catching our cube falling is part of your challenge. And your challenge is to catch the falling cube. So find a way to stop our cue from falling into the abyss by ever Simon the whatever down and Unity is. That's the Airbus, I call it the abbess. And I'll give you a couple of hints because this is a bit of a tough challenge. First of all, you need to create another cube and size it to platform size. So you'll need to create a platform under our cube. You'll need to uncheck using gravity or remove the component. And you'll need to add a collider or make sure that your platform has a collider on it. So pause the video right now and go do the challenge. Welcome back everyone. So I hope you did the challenge and it wasn't too hot. We are simply going to duplicate our cube and we'll name this v platform plat form. And we'll move it down just a little bit, put it on the 0 position. And in order to make it bigger, we can actually play around with this scale. So let's increase the axis scale and make it to when t5 will increase the y scale. Should we increase device K? Nope, we don't need to increase the y scale. And let's go ahead and increase the scale. So now we have a platform, but an hour game. It kind of looks good. Our cube false. But what happens? And actually nothing happens. Why is that? Well, because gravity is turned off on the cube and the platform. So let's go ahead and turn gravity back on on the cube. Click on play. And what happens? Well, as you can see, they are both falling into the abyss of unity. Why is that? Well, because our platform, even though it's not being used by gravity, other forces are also affecting our rigid body. Now, there are two ways to go about it. There is the kinematic, but this leads to weird behavior because let's go ahead and make the platform kinematic. Be click on play. R cube falls, nothing happens, but if we add more cubes, the platform starts rotating. So the best way is to simply remove the rigid body component from our platform. And another thing that I wanted to talk about. So let's put the z of r cube back to 0. The game view is good. It looks good, but it's not as good as we want. So we want to change the position of our camera. And if you click on camera, you can see how the game view right here on this little box looks like. So we want to change it. We want the position to be, for example, up here. And we can start moving out camera up and down and making sure that it works. But there is a, another fancier way of doing this. If we choose the way we want to look at our game scene, for example, I want this one. We click on camera. We can actually go up here and to the game object and down we can see that we have the option to move to view or Align With View. So let's click on Align With View. And you can see down here that actually our view is now, well, the view that we have in our scene that we chose is actually the view and our main game. So this is a very helpful way to change the position of our cameras very fast. Can also use it to change other position. I mean, you can also use it on other game objects, but I found that camera is the correspond to do this was with. So let's go back to camera. Now if we click on play, this will be our view. And again, it's not very nice. Let's change it. For example, put it up here, and maybe move the box up here. But actually let's change the mesh right here and make it white just so we can differentiate between r cube and the platform. It's falling gone. So now RQ falls down and it falls on the platform. Very nice. So one more thing that I wanted to add, just for fun, let's go ahead into our project. Let's right-click and we can actually create, what should we create? Well, we can actually create a material and this material will call this the cube material. And we can actually add the script material to all cube up here. And we have the option, we have a lot of options. You can go and check all of them, but the most important one that we need is the color. So we can change the color of our cube and make it maybe a red, orangey red, or keep it red, red. And we can also create a, another material. So go ahead and create a material. And let me show you again. So we hit on the right-click go to create. We have a lot of options and one of them is the material right here. So we created them a material, platform, material and will add it to the platform. And let's change the color to green. So now we have a green platform. Or actually, I think we are going to keep our platform a bit. Whitish gray white fish, which is better because we are going to be adding other components, other cubes and spheres and cylinders. H will have their own color will keep this standard. Anyways. In other thing, the fun part of this video is going to be adding a physics material. So down here we have the physics material or physics material to D, We choose the physics material. And this will be the plat for physics. Now this is not the most important part, but we'll need it. I'll show you why. We can change right here the dynamic friction. We can change the static friction. But what we're most interested in is the bounciness. So let's make the bounciness one, and let's drag it on our platform. So if we click on platform and look on the box collider, we can see that our material is now the platform physics that we've created. And now when we click on play and our box false, it actually starts bouncing. Very cool. So I hope you enjoyed this video and I'll see you in the next one. 8. Prefabs & Basic Input System: Welcome back, my favorite game developers. In this video, we are going to learn about two things. First, learn about prefabs. So this cube right here and the sphere and this platform are all prefabs. And other thing we're going to learn is how to use the input of a player in order to change things in our game view. So now if we click on the game view, if we press the space button or Spacebar, we instantiate a cube. We can instantiate as many as we want. And if we press the left mouse button, we can actually also instantiate spheres that rolled around and interact with the world around us and also fall from the edge into the abyss. So this is very fun. This is very cool video. It requires a bit of attention and trust, so let's not waste any more time and let's get started. Oh, okay, so before we get started with player input, let's first of all create a prefab. And before we create a prefab, let's talk about what a prefab is. So let's go into our laser. Thank you. And to our slides. And now let's talk about the prefect. So what is a prefab and unity? It's a very important concept and maybe you've heard about before. Let me explain. You, explained to you what they prefer bys and the most simple way possible. So it's a previously fabricated object. Very easy. So it would say previously fabricated object. What is a prefab? It's a template for a certain game object. The prefab system allows you to store an object with all its properties. So you can go to the next one. You can actually take a game object that has, for example, a rigid body with a mass of 15. And you can Prefab it. So you can create other game objects like this cube that have a mass of whatever I just said, the same mass. And you can produce it over and over and over. So what do we use it for? 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 in different scenes much easier. Now the last part we'll see later on, we will understand why this is very important. But for now, because we have a single scene, we won't know how this works, but it is very important. So let's go ahead and create a prefab. So the prefab is a simple concept, but actually creating a prefab is very, very complicated. In order to create a prefab, you need to click on cube. For example, if you want to prefab the cube and you need to drag it into assets. And that's it. This is how you create a prefab. It's one of the most simple thing that, things that you can do. So how do you know it's a prefab. You actually see that the cube run out in the hierarchy is in the blue color. And you can also prefabbed the platform. And you can also prefab this shock shapes bomb. You can prefab the main camera. You can prefer the directional light, you can prefer whatever you want. So now that we have a Cuban or prefab, we can actually go ahead and add another cube. And another cube. Another cube. So now as you can see, we have many cubes and are seen. They are under the ground, but at least they are cubes and are seen and they are all red and they all have the same components in the inspector. So why are prefab so cool? Because let's take this cube for example. If we increase the axis scale, we actually have an option right here that is override. And what this does, it actually allows us to apply the changes to all other transport, I mean, all other prefabs from the same origin or cubes. If we click on apply, all the other cubes also increased in scale in the x direction. And this doesn't have to be the original one. So we can choose, for example, the cube to, we can increase the scale in the z direction. And if we look up, we can apply that. Now, all of the cubes that are linked to the prefab also change the zoom scale. Very nice. So let's delete all of that and let's take our cube back to normal size, so 111 and save all of that. So now you understand why and what our prefabs and the simplest way possible. Next thing we're going to do is we're going to use this prefab and ordered to spawn shapes into our world using our shapes Palmer. So let's go ahead and apply all of that to bring back r cubed and normal. And let's go into our code. So right here, as you can see, we have many variables. We have the debug, And for now we don't need the debug. We can either delete all of this or we can simply add two comments which make this, makes this a comment and it will not work. So this is no longer a code that is executed. It's simply a comment. And for now, let's go ahead and delete all of our variables because they were only examples. But we are going to create a variable. And this will be a very special variable that you'll see later on. Now, what is our goal? Our goal is to instantiate cubes, our cube spawner or shapes Palmer, using a certain key, which is the spacebar. So what do we mean by using a space bar or a key? That means that we need to input something into our unity. And there are several ways that we can do that, but one of the best ones are using something called input. Now, I initially wanted to just go along and create all the code. But my goal in this course is to actually teach you skills that will allow you to go out into the wild, wild west of game development and actually have the skills too. Go through the problems alone because this is a course I'm not sure, eight or ten hours. And it's not going to teach you everything about everything you need to learn how to actually solve the problems, not just watch someone solved the problems for you. So let me take you through the step-by-step way. I usually solve my problems. So I need the input. What do I do? I go to Google, I write input unity, and I find this documentation right here. So it's about the inputs. I read the description just a bit. I understand that it's an interface into the input system. So this allows us to go into the input system. I read down a bit, I see that use on mobile devices it has accelerometers. Not worry about that. And this is how we use it at sea. If input get button, fire, whatever. It's an example, I go down and down and actually start looking at the static properties. What are all of those? I looked down, I read a couple, I see what I can use. And finally, I used IC, the static method. This is what I need. I need methods to in order to change things. And as I read through, I can see that there is an option right here that is the get key down and I read more, it returns true during framed user starts pressing down the key identified by name. And I look at it, I see that it's actually what I need. Now, this is, this process is much harder. I already know what I want to use, but I'm just giving you an example of how this almost works. Usually it takes five to ten minutes. But anyways, I use this gets key down. I opened the gate key down and look at it. The description tells me that it returns true during the frame to user starts pressing the key. Now maybe you're just a start. You're just starting in coding and you don't know what returns, what does even return mean? What is true? It's a boolean, but we don't know how it works. Well, thankfully, we have an example right here. So we go ahead and copy this example. We go back into Unity. And if we look more closely, we can see that it was inside of the update. Ok, cool. So I put it right here, Paste it inside of the update, save all of that. Now I have an input button using the space. So and it actually also prints something to our console, which is the Space key was pressed. So let's try that. Maybe it's all a myth. Maybe it doesn't work. We try it in Unity. We click on play, we click on the spacebar and whoa, it actually works, or the Space key was pressed. Very nice. So what is the next step? The next step. And don't worry about the if condition and what return is true. Everything will be explained in thorough detail in a couple of videos. Now what is the next step? Step? The next step is to actually instantiate the cube using this space bar. Now, before we move on, this is a string reference and we hear don't like string reference a lot. We tried to find a way to avoid them. And the best way to avoid, avoid them is using the get key down and using actually something called the key code. And this key code allows us to choose a key on our keyboard, which is the space. We can choose many different key codes. For example, the m, v be the V, anything you heart desires. Next thing we have to do is we need a reference to our cube or shape. So let's do that. Now we need to create a variable and it's going to be a special kind of variable. It is going to be a variable of type that we are going to make ourselves. Before we do that, let's go into Unity. Let's go into the cube and we'll add a component right here. And this will be a shape. Now, we don't have anything called a shape. We're actually going to create a new script. And we'll create a new script. And the script script will have a name of shape. And we're going to create it. We wait a bit. And now our cube has a script that is called the shape. Let's go ahead and apply that. So now all of our cubes that we create have this shape right here. And now what we can do is we can actually go back into the shapes Palmer. And we can actually go ahead and create a public shape and create a variable that is my q. So this is a very, very special variable. And it actually reference, references any object that has the shape script on it. And let's see how that works. So now we've made it public. And as you can remember, anything that is public is actually available right here in the Inspector. But before we go, we need to save that. And if we click on these ships, palmer, We can see that now we also have an option right here to add a shape into our Inspector. And we're actually going to take this cube that we have in our hierarchy and we are going to drag it right here, Qu. So now we have a reference to a cube shape. And what is even better, a better way of doing it is actually going and taking the prefab and dragging it into the shape spawner. And this will be very, you will know why, because when we delete the shape are the cube from our hierarchy, we still have in shaped spawner the cube right hip. Cool. So now we've created a special variable that is our shape with edited and our Inspector, we have a way of using the spacebar. The last step is to actually instantiate the shape whenever we press the space. And let's go back and let's imagine that we have no idea what's happening. So we simply want to instantiate some kind of object in our world. So we go ahead into Google and we write instantiate unity, and we get this one. So this method right here. So we can actually use this and it returns the object or the instantiated, the clone. So we can actually give US this public static instantiate and give it the Object that we want to instantiate and it actually creates a clone and adds it to our world. Very nice. Let's see the example. What does it have? It has a lot of things, but we can see that we can actually use only a single parameter to make it work. So let's go ahead and do that. So instantiate, we open up the brackets. And what do we want to instantiate? Well, it's going to be the Mike Hugh. Why does this keep happening? So it's going to be the my cube. We close it with a semicolon, and now we are ready to make things work. Click on play. And let's see what happens when we press the space bar. So we just added a queue. We click it again and again and again and again and again. And we can create how many cubes we want until RPC crashes. And if you look at the hierarchy on the left, you can see that it's actually a clone and not the original prefab. It's a clone of the cube that we have as our prefab, just like Unity documentation set. So now that we are more trusting of the Unity documentation, let's go ahead and do a challenge. So your challenge is going to be in to instantiate others shape. So creating another shape and Prefab it using another button on your keyboard to instantiate the shape. And small extra challenge for all you savvy people out there. Use the mouse button to instantiate. Ooh, very nice. So pause the video right now and go do the challenge. Oh, okay, welcome back. So let's go ahead into our unity. And right here let's right-click 3D object and we'll create a sphere, will reset its position and put it up here. Let's go ahead and add the Cube material to our sphere. For now, maybe we'll change it later on. But for now this looks good enough researchers, but just position again and put it up here. So now if we go into the shapes spawner, we can see that it takes a cube. We want to add a Shapes field. Before we do that, we need to add the shape to our sphere. So now our sphere is a shape and we create a prefab out of it. And we go into the shapes Bonner, I mean, in the script, the shape spawner. And we're going to create a public shape, my sphere. We save that, go back into Unity. Now we have an option to add our sphere and we add our sphere shape. Remember to have the script on the sphere or else this will not work. We delete this fear from our scene. And now what we need to do is we need to use some kind of key and order to instantiate it. So we'll copy this because we don't know what if statements are for now. And sort of the space bar we are going to instantiate using the mouse animals you can use 0 or one or any other option. And instead, instead of the my queue, we're going to use my sphere. So let's save that. And most 0, if I'm not mistaken, is the left-most button or the right one. Let's check and see. So back in Unity, we click on play. Everything should be in place. If we click the spacebar IQ, a cube instantiates, if we click the left-most button, a sphere instantiates. And the funny thing that we forgot to add a rigid body to it. So backend sphere, we go to the component, I mean the prefab, we add a component and it's going to be a rigid body and everything should be set. It uses gravity. Very nice. We save all of that. We go back into the game mode, and now we create a cube. We instantiate a sphere and lots and lots and lots of spheres. So now we have spheres rolling around and we have cubes and spheres and cubes and spheres, which is, which are all read a small tip if you want to get into it, you can actually add another material to the sphere in order to differentiate between them. So I hope you enjoyed the video and I'll see you in the next one. 9. If-Else Statements: Welcome back everyone to a brand new video. And in this video we are going to be learning about if conditions, and we're also going to be using our conditions to change the color of our shapes. Alright, right now as you can see, the platform stilted. And it's for a very good reason. Let's take just a little bit up. And when we click on play, R cube is read until it becomes green and until it becomes yellow. And all of that is possible using if conditions. Let me show you another thing that is very cool that we've done in this video, if we put the platform on the other side, we click on play. It's red, it's green and it's blue. So this is a very fun video and let's not waste any more time and gets started. Oh, okay, so if conditions and if statements, they are very crucial part of coating in any language that you want to delve into. But before we start explaining what if conditions are, let me tell you why we will be using them in our code. So let's say for example, we have this cube right here. Let's reset its transform. So it's in the middle. And let's say we have this cube, for example, at a certain height on the y axis and its, for example, 9.83. And what we want is that we want to change the color of our cube if it falls below a certain height. So let's say for example, if r cubed gets below 3, we want the color of our cube to change from red into a color, for example, blue or yellow or anything. So we want to change our cubes colour if it falls below a certain, a certain threshold. This is where we start using something called the if condition. So let's explain the structure of the if-statements. And by the way, they are sometimes called if statements or if conditions, it doesn't matter. You can call them whatever we want. But anyways, this is the structure of an if statement. So you have to ask a question. If some condition that needs to be true is true, we execute the code that is inside these two brackets. So if we have some condition, just like we did in the previous video where we took the condition of somebody pressing a certain button, for example, the spacebar or the mouse button. If someone presses that button, then the code inside of these brackets will be executed. Now, another thing that we have in the if statements is the elsif. So let's say this condition right here doesn't get executed and we are looking for a different condition or some other condition. So maybe you are looking, maybe it's either the space but space bar or the, for example, unbutton. So if the first condition is not met, the code inside of you is not executed. The if statement looks below. So else, if some other condition that is true, if it is true, then we execute the code that is inside these brackets. So. This is how the if statement structure works. But let's say that both of these conditions are not true. So this one is false, this one's false. What happens then? Well, we can either go out from our if statements and just continue executing whatever code is below it. Or we also have another option which is the else. So this else doesn't take any condition only works if both conditions that we've added right here are both false. We can add as many else if statements, but we can only add one single else statement at the end, which will execute by default if all other conditions are not met and are all false. Okay, great, so now that you understand the structure of the if statement, let's go back into Unity and see how we're going to use it. Well, we are going to of course create a if structure, but what are we actually targeting in order to change the color of our cube? Well, we're taught we're targeting our material because as you saw in the cube right here, we can change the color using the material that we have on our on our cube. So let's go back to that. And where is this material? As you remember, we took this material and dragged it over to our cube. Where is it actually an hour inspector and how do we get access to it? Well, if you look right here on the Mesh Renderer, you can see that we have an option which is the materials and other materials we have the size and the element 0. And this element 0 is actually our queue material. And if you click on it, it's highlighted right here in the assets. So you can clearly see that it's the Cube material. So what do we need? Well, we need to get a reference to our Mesh Renderer. So Mesh Renderer is the component on our cube. And from the mesh renderer we are going to get access to the material on it. Volcanoes. So let's go ahead and do that. And where are we going to do that? Well, because we are changing the color of our cube and the, all the conditions are on the cube. We're actually going to use it inside of shape. So let's open up shape. And as you can see already, it has a couple of code, which is the start and update. So let's get started. First thing we need, as I've said, is a reference to the material. So let's go ahead and create a variable which is of type material. And we're going to call it the shape material that we have. So next thing we need to do is we need to actually instantiate it or give it the reference. Now, as you remember previously, we could use, we get, got the reference using a public variable. So we named this public and we go into the inspector and we actually drag the whatever we want a reference to, just like we did in shape. But now we are going to use a different method, which is much better. So whenever you have a component. So let's go back into Unity. So if you look on cubed, we can see that we have the cube right here, and it has D-shaped script. And also it has another component attached with just the mesh renderer that has the material. So. Instead of creating a public variable to get access to a component that is already on our Cube game object, we can actually go on a another route and a much more professional, and let's call it a better way of accessing the components. So the way we do that inside of, inside of start, we're going to write shape material. And it's going to be using a method that is called the get component. And if we hover over it, we can see that it returns the component of type, type. So it returns a component that is the type that we are going to determine. Of course, if the game object has one attached. So we have the Mesh Renderer attached to our game object so we can get access to it. So we click on that. We open up these two natural operators, let's call them. And inside of here we're going to write mesh renderer, mesh renderer. And we close it off with this one. But as you can see, we still have an error. Why is that? Well, because we still haven't gotten the material. We've just access the Mesh Renderer. In order to access the material, we click on thought and it immediately tells us that we can get the material because Visual Studio is that helpful. Okay, great. So now we have access to our material. Next, what should we be doing? Well, inside of update, we are going to create a condition to check for the position of our cube, every single frame. And if the position of our cube on the y axis gets below the three, we are going to change its color. So we create an if statement inside of here. The condition is going to be, first of all, the transform dot position dot y. And if the transform dot position that y is less than three, well we are going to execute a certain code is D-shaped Material dot color. So we've accessed the color of our material would be equal to color dot Green. Okay? So let's talk about the condition right here again. So it's the transform, go back in Unity. It's the transform, its position. So inside of the transformed me went into the position. And finally we want to the y axis, which is the y right here on the three Cu. And we've made sure that if it's less than three, so whenever the transformed position dot y gets less than three, we take our shape material that we've created right here. We take the color, so we access the color and we change the color to a color green. So this is very simple. We simply have a class that a scholar dot Green and we have access to the green. So save that script, go back into Unity. Let's go up a bit, move it up a bit. So it's about the 18 and we click on play. And R cube falls, it's shred and when it gets below a certain threshold, it turns into the green. And if you're wondering how I maximize my view, how my game view so big, you can actually click on Maximize on Play right here. So. Now that you understand how the if conditions work, how we've acts, the material. It's time for your challenge. And your challenge is going to be to add a, another if condition. So create a another condition for the shape going over a certain x value. So you need to check for the position of a cube or the shape or anything over a certain x value on the x axis. I'll give you a small hint, which is to tilt the plot for a bit around this axis just to make our shapes slide down. If your cube is not sliding, so you can move it in the x direction. Okay, great. So pause the video right now and go to the challenge. Okay, welcome back. How did you get on with that? So let's now check for or create an if condition for the position of our cube on the x-direction. So back in here, we can check, for example, if our transfer dot position dot x is less than minus three, so it gets below minus three. We are going to change the shape, Material dot color, and it's going to be equal to color dot blue, Nas. So let's save that. Let's go back into Unity. And as I've told you in the handout, let's take this and rotate it just a little bit around the z axis. So r cube slides down. Take r cube a bit higher, click on play. And now our cube falls, it turns into green, and then it slides down and it turns into a blue color. Very nice. So this at least works. We need to put our platform, maybe it just a little bit more to make sure that our cube slides well. And Let's check that out again. So R cube is read, it falls, it turns into green and it turns into the blue color and keeps falling into the abyss. Very nice. Now, some of you may have tried to add a, another if else statement. If you haven't, let's go ahead an added together. So else, if Transform dot position dot x is greater than three, we are going to change the shape, material, color, and to the color yellow. So now transform position dot x is greater than three, which will change the shape's color and to the yellow color back in unity with the platform in the other direction. And now when we click on play, R cube is read, it falls down green and it turns into the yellow. So as you can see. So we have this shape color turning into blue if it's less than three, or the position of our game object is less than three, it turns into yellow whenever its position is greater than three. And I hope you did the challenge. I hope you enjoyed the challenge and I'll see you in the next video. 10. Arrays & Loops: Welcome back, my fellow game developers. In this video, we are going to build learning all about loops and arrays because these two components, encoding go hand in hand. So what have we done in this video? We'll actually, when we click on play and we press the space bar, only the space bar, we have these three shapes that instantiate, which are a cylinder, the sphere, and r cube. And if we press the spacebar multiple times, as you can see, the world has gone crazy on us. So this is a very fun video and let's not waste any more time and gets Dr. Oh, okay, so arrays, there are bugger to teach and they are a bug or to learn. But arrays are very important to anyone who's looking to become serious in coding. So let's talk about arrays. What is an array? A laser? What is, what are arrays? While arrays allow you to store multiple objects of the same type in a single variable. So just like we have variables, we have arrays, but the difference between them is that it's a set of variable. So you have many variables of the same type under a single name, and we call this name and array. So this is what an array looks like. It's very similar to a variable as it has a type. It can also have accessibility, so it can be public or private. Of course, it has a type, it has a name, so number of enemies is the name. And if you've noticed that each the type, instead of simply being an integer or INT, it also has these brackets next to it, which indicates that this is an array. And finally, we have the values right here, so it's not a single value, but it's multiple values together inside of the array that we have. And one also very important thing to note about arrays is the way that they are numbered. So the first element in an array is actually at the index of 0. So we start with the four at index 0, then six at one, then 11 on the second, on index number 271, on index number three and so on. So this is very important to remember that the indexes and arrays start at 0. Now, what is a full loop? Well, for loops are Act or any other loop go hand in hand with arrays. So loops can execute a block of code a number of times. Loops are handy if you want to run the same code over and over again, each time with a different value. So let's talk about the structure of a for loop. This is the basic structure of a for loop, just like we have the if condition. We have the for loop, but it's of course very different. It does have a condition inside of it, but it's different. So for example, we start with the initial condition. So we start with an integer that is equal to 0. We then set the limit of this integer so we need to keep going up or adding one. Each time this i plus plus means that we're adding one each time until it gets to a certain limit. And every time we increase the high ones, we do stuff which is the code that is inside of our brackets. So we start at 0, we execute the code. We increase the 0 to one. We execute the code may increase the 02 to the one to two. We do the code until we reach a certain limit that we've determined. So it continues to execute the code inside until I reached the certain limit that we have established. So how are we going to use arrays and loops and do all of that inside of our game and make it fair. Well, the way we're going to do that is we're actually going to be instantiating multiple objects inside of our game. Now, we already have a cube and a sphere, and each of them have their own buttons to press in order to activate them or instantiate them. But now we are going to create a way for us to instantiate both of them inside one, go using arrays and loops. Okay, so first thing we need is we need to create an array. So let's go into these shapes spawner, and open up Visual Studio. Okay, great. So let's go ahead and instead of my sphere and my cube, let's delete those. And instead of the shape being a regular variable, we're going to make it a array. And to make it an array, we simply add these two brackets next to it. And we're going to name our array, the shape prefabs. And we're going to keep our array public. Now that we have our shape prefabs ready, we can go back and now we have arrows right here. That's okay, don't worry about it. Or actually let's go ahead and comment this out for now. We'll be changing them on later on. So save the script, oops, saved script contrasts and go back into Unity. Now when we click on the Shapes spawner, we can see that we have this drop-down right here, and this is actually the array that we've created and we can actually give it a size. Now, there are two ways of going about this. We can either add a size right here, so we can, for example, write two and we get to places for our shapes or we can keep it at 0. And a nifty trick that Unity has is we can actually click on this sphere. Or before we do that, click back on shape spawner and make sure you have this little lock icon locked. So this way whenever we click on other elements in our project, the inspector doesn't change. So click on sphere, hold Control, click on cube and Jack, both of them in 2D shape, not decides in 2D shape prefabs and they will automatically be added to the array. Very nice. So next thing we're going to do is we're going to create a loop in order to instantiate all the shapes that we have in our array back in our code. What we are looking to do is we want to create a loop that will help us with a single press of a button to instantiate both pre-fabs. The way we do that is we are actually going to get rid of the mouse. Button. And inside of this if condition, let me delete this right here. We are going to create a for loop. So we create, we write four. We put the initial condition, which is going to be the i equals 0, the limit that we want. So the number of times that we want to iterate, this will be the number of the shapes that we have inside of our array up here. Why is that? Well, as I've told you, our goal is to instantiate all the shapes that we have inside of our array. And the way to do that is to loop through each element of the array. So it's going to be the shapes prefab, and a nifty way to get the length of the array is to simply type in length next to it. We close off using the i plus plus. This will increase the I once every iteration. So click on tab right here, so at all aligned together. And in here we are going to instantiate. So n. Where is it instantiate? And in here we are going to write the shape prefabs. We're going to open up the brackets and n Here we will give the index of the shape that we want to get from the array. And the way we do that is by simply clicking on right here. So let's save that. Now, back into the platform that's put the rotation back to 0. And what I want is to actually change the angle of our camera. And I also want to change the position of our cube and sphere. So let's put in the cube, let's put on the sphere. And let's change the position of the cube up here. And it's actually not overriding. Let's go into the cube. And a nifty way of doing it is simply by clicking on the three bonds right here, copying the position, going into the cube, a prefab, and pasting the position. So you have the base position right here. So now the cube will always speciate at this position. And the sphere will also, well if the sphere is already in a good position. So delete both of those. Color can play. And now we instantiate cubes and spheres on top of each other. Very nice. Now, I want to draw the camera out of it, so we'll put it up here. We'll go to camera game object and will align with the view. So now when we click on play, let's check the view, make sure that everything looks cool and it does very nice. So Let's talk about the for loop again before you go into your challenge because some of you may be familiar with loops and it's the first time, so we'll go over it just a little bit more. First of all, we have the if condition, which checks if we actually input the key that we need, which is the spacebar. If this condition is met, we go into the code that is inside of the if condition. And the code is a for loop. So the way this for loop works is. We take an initial condition. So the initial condition is at i equals 0, we have a certain limit, that is the length of our array which is shaped prefabs. And each iteration we increase the i by one. So we start off with i equals 0. So an example in our case, we start off with i equals 0. We execute the code that is inside of here. So it's T-shapes 0 and it gets at, gets the first element inside of our cube. I mean inside of our shape prefabs, which is the cube. Then we increase it by one. We have i equal to one, and we execute the code that is inside of here. It instantiates D-shaped prefabs at index number one, which is our sphere. So this means that we've instantiated a cube and a sphere inside of this for loop, it's immediate, it's very fast and it does it instantaneously. And when we get to one, we check, is i still less than the prefab length? If it is, we stop the array, we stuffed the loop and we go out from our code execution. If it's not, if we have, for example, ten shapes and I still at the index two, then we keep on instantiating and looping through our shape prefabs until we get to the last element in our array. So now that arrays and loops are understood, it's time for your challenge. And your challenge is to add another shape to our gain. So create another shape to be added to the array and make sure that they don't instantiate on top of each other. So pause the video right now and go do the challenge. Oh, okay, welcome back. So how did you get around with that? Let's go ahead and create a 3D object, which is going to be a cylinder. And cylinder is actually going to have the Cube material on it. So it's all going to be read. And we're going to reset its position just to know where the 0 is and where should we put it? Well, if we add a cube, we add a sphere. And we'll put the cylinder behind this fear right here, right next to our shapes. So now we have these three shapes. And before we forget, we add a component which is the rigid body. And we have everything set up except for the shape script. So we add a shape script and now our cube is a shape. Very nice. Last step, we create a prefab from the cylinder and we delete all of these in our scene, we go to the shape spawner and we can actually drag the cylinder and put it inside of the shapes prefer. So now our shapes prefab has three elements. We actually, and the beauty of this is that we don't need to change anything. The only thing that changes inside of our code is D-shaped prefabs length. So now instead of simply going to i equals one, this will go into i equals two and it will check is two less than the shape length? Well, it is because the shapes length is three. And if it gets to three, this condition is no longer viable because r equals three is no longer less than. This is very crucial to understand. It's, it can be like this. It can be less than or equals, but this is strictly less than T-shapes prefab length. So save that, go back into Unity, collect on play, and let's see what happens when we start instantiating multiple shapes. And as you can see, we have cylinders flying around, we have balls flying around. We have cubes everywhere, and each of them are in different colors. So I hope you enjoyed the video. I hope you understood everything about arrays. If you still have doubts about how they work, feel free to go and search for them a little bit and play around with them in unity to make sure that you have a firm grasp on loops and arrays. So I'll see you in the next one. 11. Creating Chaos: Welcome back everyone to a brand new video. And maybe you've gotten a bit accustomed to me. And every time I make an introduction, I talked about what we're going to do just to get you excited. But actually in this video, I'm simply going to let the gameplay do the talking for me. So chaos was promised and chaos was delivered. I hope you enjoyed the video and I'll see you in just a bit. O k. So creating chaos, this is probably my favorite video. Well, actually, what I mean by creating chaos is adding forces to our objects. So now, if you look at our cubes and spheres, whenever we instantiate them, they simply fall down you from the force of gravity that is acting on them. And acting on them because we've added the rigid body component. But this rigid body component can actually do other more interesting stuff. Not just use the force of gravity, but it also can have a force that is other than gravity that can be applied to it in order to move objects around. And adding the force will be possible using a method that is called the ad for. So let me take you to the documentation and let's check out what that force is actually. So you can see that it has a couple of parameters. So you have the vector three fourths, and the vector three is actually the Y axis and Z axis. We have the force mode, but I don't think we'll be needing it for now. So the only thing that we need to focus on, it is applied to a ridged body, as you can see right here. And it takes in a vector three. Let's read just a little bit on the description size. It's good habit to always read a bit on the description and maybe check out the example. So first thing first, forces applied continuously along the direction of the force factor that we've chosen. So it applies a force on the object in the direction of the force vector that we choose to add. And a very nice detail right here that you need to take notice of is that it adds a force to the rigid body. So only when you have a rigid body on the game object, you can add a force to it. So let's do that. First thing is we need to go into our Visual Studio and will need to go into the shape. Actually, I see that we have a brief comments here. I don't think we'll be needing this anymore. You already know how to use the debug o'clock. So save that back in shapes now or shape. Now, first thing we need is we need a reference to our rigid body. So let's go ahead and do that. So let's create a variable which is our rigid body, and we'll call it my rigid. Body. So now we have a reference to our, I mean, we've just created a variable. And in here we're going to add a reference to our rigid body. And because the rigid body of a shape is already present on the game object, we can go ahead and get the component directly. So rigid body. And that's all we need. Very nice. Now let's add some forces using a couple of arrows. So, and here we are going to create an if condition. You already know how to use the input. So input, if we write it correctly, so input dot get C0. And instead of getting kicked down, we're going to use the get C0, which will keep on pressing. Well, let me show you again the description before one. So there is no confusion. It returns true while. So doesn't return true as soon as we press or, or the frame that we've pressed it, it returns true while the user holds down the key. And this is our goal because when adding forces we want the object to keep having this force adds to him as long as we press a certain key button. So input dot get q0 dot key and key code. We are going to be using the left arrow. Left arrow we have in here. And inside of it we're going to use my rigid-body dot at force. And it's going to be using the vector three dot left. Okay, cool. So let's save that and let's go into Unity and see what happens when we click on play. Have our gain. We click on play, we press the left arrow. And as you can see, our cylinders and box and sphere all move in the z direction. So let's go ahead and try and add a lot of these and create chaos. Guru. As you can see, all of them fly off into the abyss. That is the unit is depth. So now that you understand how we can add forces to our rigid bodies, it's time for your challenge. Let me put on the laser finished D-shaped movement. What do I mean by finished D-shaped movement? Well, create a code for the shapes to move in the upward direction. And create code for the shape to move in the right direction. And if you want an extra challenge for yourself, you can also create an other directions too. So to the right, maybe down, maybe, I don't know, get creative. It's just for fun. So pause the video right now and go do your challenge. Oh, okay, welcome back. So now we need to add a key code for the up arrow and the right arrow. So let's copy that. Let's paste this and paste this again. So instead of left, we'll add the right arrow. Instead of the vector left. We're going to add it to the right. And in here instead of the left arrow, we're going to use the up arrow. And instead of the factor three dot left, we're going to use the vectors three dot up. Let's save all of that. And let's see what happens in unity right now. So I promised to chaos, and here, chaos comes your way. So click on space. If we press the right arrow, we move to the right. If we press the left to move to the left when we press upwards, whoa, everything floats around. Okay. Are you ready, guys? This is the moment. Let's enjoy what we've just created. So we, everything moves around, slides around. Everything is, well actually you know what, it's not that fun because they are actually very slow. And if you have the same problem as me, you'd like to change. You'd like to make them a little bit faster. So the way we do that is actually we are going to multiply these vectors by a force that will add right here. So let's go ahead and create a variable. It's going to be the float, it's going to be of type float and it's going to be how are called force magnitude. Magnitude. Not sure if that's how magnitude is written. But it will do for now, will make it 5F or because it's a float, let's go ahead and make it five-point eight. Why not? And any here next to the vector dot left, we're going to multiply it by the force magnitude that we've just created. We'll copy this, will multiply the right and the top. Let's save that and see if anything changes. Maybe this won't be enough, but we'll check. So we create two shapes and remove them. Okay, so this looks promising. Let's create many shapes and let's start moving all of them. As you can see, this is really nice so we can actually create shapes. We can move them upwards, down, okay, so downwards we don't have it yet, but it would be really cool. And as you can see, chaos has been achieved. So I hope you enjoyed this video. This is one of the most fun videos. Honestly, I say this about every video, but this really is one of the most fun videos. And I hope you enjoyed it and I'll see you in the next one. 12. Public Methods & Return Types: Welcome back, my fellow game developers. In this video, we are going to learn all about public methods. So as you can see right now, our shapes flyaway extremely fast because we've actually created a method that is the force increases. And it's actually, as you can see right here, it's a method that we've created inside of ship spawner that cause a increase force method that is on shape, which is a public method with a parameter. So we are going to learn all of that in this video. So let's not waste any more time and let's get started. Okay, so, uh, methods and functions, they are used interchangeably. You can either use the word method, you can either use the word function. Now there is a difference between them. But honestly, I never saw anybody that was mad if you use them in a wrong way. Anyways, called them wherever you want, we'll use them freely as we want. Let's talk about methods and functions. So this is the structure of a typical method that you see, just like with our variables. The methods also have accessibility by now, if it's private, it can only be used inside of the class. And if it's public, you can use it from other classes outside of your script. There is also the return type. It can be either integer, it can be float, it can be whatever you want, but if we use the void, it means that it does not return anything. We also have the method's name. So usually whenever we want to name our method, it should be named after what the method does. So for example, if our methods, our method adds velocity, we'll name it adding velocity. And as you can see, there is a small difference between the naming convention between variables and methods. The first letter is always uppercase. And finally, we have the parameters. And the parameters is actually a variable that we send into our method to be used in order to change things. Or for example, we can say that we are adding velocity. We want, for example, to add five. So we add a parameter right here which is going to be a float, for example. And it's going to be called velocity to be added. And inside of the method, we're going to add this parameter right here to whatever we want inside of the muscle. Great. So before we move on and let's go ahead into our shapes. Boehner or I mean, the shape right here. And let's go ahead and create a couple of methods before we move on to the challenge. Now as you can see right here and update, we have two types of codes. If you look very closely, you have the movement of our shapes and you have conditions on our shapes. And whenever we are creating, you'll see this later on. We always want update to be very, very neat. And. Very simple. So it must be very simple because update is where we always look at everything that's happening around. And if now our update is actually very clumsy and has lots of code and it's really unnecessary. We can actually choose or highlight all of the conditions or if statements that are related to the movement, right-click on it. And here we can actually quick action and refracting. So we click on that and we can actually extract a message. So when we click on that, all of our if conditions are now in a private method. And as long as you keep it like this, we can change the name. So let's change the name to the or. Let's make it more precise. Shape movement. Click on Enter, and now we've just created a method for shape Movement. Another way to do this, we can actually go ahead and create a private void. Ok, this is not how private is written. So private void, What should we color? What should we name this method? It should be color based on position. So colors based on position, tried to always find the short-term name for your methods. But for now me, we'll settle for this. So we'll control x if you want to know how I got all of that, control V. And inside of update we are going to call the Whereas it color color. Whereas the method name color based on position, that's copy that. Put it in here. And let's not forget the brackets at the end. And because our methods don't take any parameters, we are not going to be sending any of them. Okay, great. So now you got a little bit of a taste of how messages look and how they are created. And it's actually very early, but I trust that you have the strength to do it because it's time for your challenge. And your challenge is going to be to create your own method. So create a simple method in shape to increase the force magnitude. And with a parameter. This means that your method inside of shapes should have a parameter and make sure that the method is public so we can call it from the spawner. So and also that early, I know you may be still unsure what a method is and how it works, but I have complete trust in you that you can do this challenge. So pause the video right now and go do the challenge. Ok, welcome back. So let's go ahead and create a method that will increase our force magnitude. So first thing first, it's a public will, it will not return anything. And we are going to increase force. And it will take a parameter which will be a float. And we're going to call this the added force. Okay, great. And what will this actually be doing while we are going to make get the force magnitude variable that we have up here. And we're actually going to add a or add V parameter, which is the adult force. Now if you've never seen this operator right here, which is the plus equals, what this means is that it's equal to the force magnitude plus the added four. So. Effectively, it takes whatever force magnitude we have. It's, it adds the force and then it puts it back inside the force magnitude. So this keeps increasing as we add or called the increased force. And using the plus equals is a much faster and actually cooler way of coding saves us a lot of space and saves us a bit of confusion. Next thing we're going to do, we need to make sure that this one is public or seal serialized field? We'll learn about serialized fields later on. And now what we need to do is we'll need to create a method inside of spawner. And order two, call the increased force method in shape on every single object that we have. So let's do that first thing first, Now in here and update if you're feeling savvy, you can also extract S1. So let's go ahead and do that actually. So let's extract the method and we'll call this the in stan, xi, yj torr. Ok. I'm pretty sure that's not how you wrote instantiated. And we're going to create our own method in here. And it's going to be a private, it's going to be void because we don't want anything to return. And it's going to be the force increase, her force increases. And inside of this method, we are going to get an input. And the input is going to be v. Get key down with the key code of f, which is very simple. Let me write this again. So f. And what should we do whenever our player presses the button? Well, we're going to create a loop with the initial being at 0. And the limit is going to be, of course, the shape prefabs dot length. And we're going to increase it by one with every iteration and each shape prefab that we have, we are going to call the method of the increase force. And we, if we just finish right now and press the semicolon, save that, we can see that there is an error. And if we hover over it, it says that there is no argument given. If you look close, you learned right here, you can see that it needs to have a parameter. So let's go ahead and add a parameter to that. We'll create a variable which room? It's going to be the force plus. We'll call it. And up here will create a float of force plus, and it's going to be, what should it be? 4.84.8 of such a lucky number? Maybe I'm the true. Anyways, we go through each shape prefab, prefab, inside of the shape prefabs. And each of the shape prefabs has the shape script on it which has the public void increase force on it. So every time we press ups, so every time we press the F key, we are going to look through each shape that we have. And we're going to increase the force on that shape before we go, make sure to call the force increases. Force increase her from the update to make sure that we always check for any input. Great, save that shapes, save back in unity. And let's see if that works. So we click on play. We instantiate. Oh, okay, sorry for that. It's a little trick that I've made. And in here, instead of get keydown, let's make it the get. I mean, instead of the get key, let's make it the get key down. Okay, now, let's try that again. We start the play. We instantiate a couple of shapes. We moved them and they have a bit of force on them. We instantiate again and again. And let's click on F a couple of times and see what happens. So we've collected, we move them and it's actually not changing. We instantiate again. The ones that have been instantiated, again have a much stronger force on them. So click on after a couple of times more, instantiate. And as soon as we press the up arrow, this should fly away very fast. Okay, that works. Could, let's try to go a little bit crazy and up-arrow. Everything goes away. Today, fall back. I don't think so. We create again, we move them. And as you can see, it's as if some superhero just flew by and flew everything away. So you just understood how public method works and how we can call methods from other scripts. And this is actually an extremely useful tool whenever it comes to coding and creating games. So I hope you enjoyed the video and I'll see you in the next one. 13. SECTION 3: CREATING OUR ROCKET SHIPIntroduction To Version Control: Welcome back, my fellow game developers. In this video, we are going to be talking about version control. What it is, what should we, what are the tools that we're going to use to make our version control how we create repositories. And we're actually going to go ahead and create our initial commit with all the files that we need. We'll also learn about what Git ignore is, what the files that we need to ignore in order to create our repositories and all around, build a solid foundation from which we can take off with our rock chip. That was a bad joke. Let's not waste any more time and let's get started. Version control. It's hard to learn. It's even harder to teach, but I cannot tell you how important it 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. Means it helps us to take risky steps now 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 is you need to go ahead and download source tree. Simply write source tree or go to source three, app.com or write source tree download on Google. And you should come up to this page right here. You can either download for Windows, and it's also available for your Mac OS. When you finish downloading, you, you should have this installation file right here. Simply double-click on it and start the installation. And when you arrive, you should arrive at this point right here, where you have source three installed. So simply click on Agree right here. And then it should take you to the next window, which is either to create an account. So you either use an existing account or you can go to my app lysine 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 and 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 the scores. So simply click, I don't want any more curious. Okay, so when you finish installing source tree and everything that it requires, you should get this window right here. And if you don't see it and if you see a kind of a different window, make sure to click on the Create right here or open a new tab, click on Create and you should get this interface. So what are all of these? This is where we create our repository. So first of all, we have the destination path. And here we are going to find the project that we are going to create. We're going to give it a name. It's going to get its own name and inherit we can choose which type of repository we want to make. Of course we'll keep it at the get. But first thing we need to do is we need to actually create our project. So let's go ahead and open up Unity hub. And in here, let's go ahead and create a new project, which is our main big project. Make sure that you know the destination, which is unity projects for me, for you at my front, make sure, make sure that you choose 3D because our project is 3D. And let's go ahead and create a project which will be named space bound rocket ship 3D. So collect onCreate and let's wait for it to be created. And I will, I will be using the magic of editing in order to speed up the process. So I'll see you when it's finished. Oh, okay, welcome back. So I hope your project is also finished creating itself. Now we can actually start to create our game, but before we do that, we want to create the repository. So the way we do that, now that we have our project set up, we can go into the source tree right here, and we can click on Browse. And when we do that, we need to go and find out inside of our Unity projects are project which is space bound rock chip 3D. And when you select this folder, it will give it automatic name, which is the space bound rock chip. And this will create a small folder inside of our destination or the destination of our project, which will keep track of every change that we make inside of our project. So let's go ahead and click on create. Make sure that you have unchecked the Create repository on account. So click on Create, collect the Yes right here. And now we have created our repository. Now, as you can see right now, there are a lot of scary things on the screen, but don't worry, these are all very simple things. In here are the files that we are going to add to our repository. As you can see if you look closely, most of them are the library. And in, whenever we are creating repositories for unity, the library folder folder is actually something that we do not need. Library is a folder that is, even if you delete it from your file, from your project, you can still open up your project and the library will be recreated on its own. So we don't want to save the library. It's not essential. There are other folders that we do not need also, but for now, let's go ahead and ignore the library files. The way we ignore these is we actually right-click on one of the library files. And in here you can see that we have the option to ignore so that a small window will open up right here. Simply click on, Ignore everything beneath library. So make sure you click on this one right here, which is ignore everything beneath library. When you've done that, click on okay. And if you move up, you can see that we have a new folder right here, which is the dot git ignore file. And it's actually a very simple file. It's a text file that you can open up using the notepad. And this is where we keep all the contents of the files that we do not need to save in order to create a repository and unity. Now, why are we actually doing this? First of all, because these are not important, important folders for our repository. Second of all, they take up a lot of space and we need to save as much space as we possibly can. So this is why we need to create this dot git ignore file that we'll ignore some of the files that we do not need for our version control. Now, the library is not the only folder that we need to ignore. There are other folders that we need to also ignore. And thankfully, there are people out there that took the time and figured out all the files that we do not need. And to find this, we need to go into Google. So I'm already here, but go to Google, simply type in git, ignore unity, and you should come up to the first search which is on the GitHub. And in here you can find this file should be placed at the root of your Unity project directory. So in here, these are all the folders and files that we do not need in order to create repositories and versions or version control of our project. So let's go ahead. Click on raw right here. You should go to this page. Click anywhere you want. Click on Control a, so you select everything or simply select everything manually. Copy that. So Control C or right-click and copy, go back into source tree and inside of get ignores, double-click on the gitignore used in Notepad or any file that you want. And place all of the dot git ignore files right here inside of the notepad. Save that. And now you can see that the gitignore file right here is much bigger and all of these files we do not require, and this saves up space, and this saves a lot of time for us. So great now that we have everything set up, Now it's time to create our commit. So how do we create our commit? First of all, we stage our files. Now sometimes we don't need all of our files, but we will be staging all of our files for now. So as you can see right here, these are the files that will be remembered as this current version of our project. To commit those, you need to click on Commit. We are already on the page of committing, and in here you should name your commit. And how do you name your commit? Well, you can name it anything you want. It doesn't matter. You can call it whatever you want. But usually when ever we are creating repositories, you want to make sure that you know what you have in this version of your project. So you need to name it accordingly. And from habit, and as a habit that most programmers and advanced programmers use is the first commit is going to always be called The initial commit. Now you don't need to name it like that. I like to name it like that. I always like to create my first commit and call it initial commit. So now that we've created our initial commit, we've named it. Simply click on Commit right here. And now you can see that we have in here something called the master under branches. And if you click on master, you can see that we have our initial commit. And now whenever we create a new repository, or actually whenever we create a new version of our project, we will be saving it right here and we will see how we are slowly progressing through our project. So now that we have all of that figured out, it's time for your challenge. And your challenge is going to be to create your repository. So first step is you need to go ahead and download and install source tree. If you haven't already. You need to create your project and community hub, which is the space bound rock chip. You need to create a repository for it and source tree, ignore library files. Copy, copy, copy the dot ignore file that you should find on GitHub, and then create your initial commit. So if you haven't followed along with me or if you are a bit lagging, you still have a download source tree. Don't worry, take your time. Go ahead and download source tree. Create your project, create a repository, and ignore the files used, the dot ignore file and create an initial commit. Now some of you might be thinking right now, well, why do I actually need to go through all of these steps? Well, because young grasshopper, this is extremely important. First of all, it will help us a lot in our game development. Second of all, it is an amazing skill to learn. If anyone sees you and you, and asks you, do you know version control? And you tell them, Yes, they will be amazed because this is a skill that professional programmers and big tech companies used to create their project. So pause the video right now. Don't be lazy and go ahead and create your repository. 14. Shaping Our Rocket Ship: Welcome back my fellow game developers. And as you can see, I've just created the latest version of the Falcon nine from SpaceX. Now, Elon Musk will be contacting me any day right now and telling me that your design is much better and more aerodynamic than our design that we are going to be sending to Mars. But I'm I'm busy. I'm not sure I'm going to reply to a skull, but anyways, we've built a rocket. And this rocket, as you can see right here in the hierarchy, has a body, it has a nose, and it has four legs on each side. And each part of our rocket has its own material with a new kind of shader that we've added. And you are going to be building your own rocket in this video. So it's a very fun video, is the start of our big giant project, which is the space bound rocket ship. And let's not waste any more time. And let's get started. Ow, kay, let's start building our rocket. But before we do that, we need to have something for our rocket to be lending on. So we right-click in the hierarchy right here, and we're going to create a cube. We're going to reset its position. We already know how to do that. We set the transformed position. And this is actually going to be our terrain in the middle of our game. So let's double-click on cameras, see the way it's looking. Okay, so it's looking in that direction. Let's create it to rain will simply increase the scale on the x and increase the scale on the y. So, okay, I think that's enough and will increase also the scale on the zed axis. So it's 60 by 20, Venice and the z axis is also by 20. So we've scaled it up. And let's make the scale on the x. Bought 60. Okay, nice. Let's put it up. And so now we have our terrain and we'll name this hour simply terrain. Terrain. Next thing we need is we need a platform. So let's go ahead and create a, another 3D object which will be a cube. This will be our platform. And this platform will also need to be reset to 00. And let's make this minus ten so it exactly on the 0 at its top and will move, will move this up a bit so we can change it. That's reduced the gizmo so they don't get in the way and will increase the exhibit. So we'll make it around five and will increase the z to make it around five. And d y will be 0.2. So now we have a landing platform. Very nice. And let's put it to 0.01 so you can see that half of it or all of it, it's exactly on the 0 on our scale, so we needed to be exactly on 0. Now, in order to differentiate between them, let's go ahead and create a material really fast just to make it green. And we'll call this the A landing pad or let's call it for now the platform material. And simply going to be a green color. So just to differentiate between the platform. Okay, that didn't change. Let's try that again. Okay, nice. So now we have a green platform and the terrain. Let's duplicate that. So this is the platform and we'll call this the terrain material. So terrain. And we'll change the color to be a bit orangeish and we'll add it to our plot. I mean, our terrain, very nice. So now we have a place to build our rock. Cool. Next thing we need to do is we need to actually find or imagine the design that we want our rocket to half. Now, I personally want to create the fat than mine. So let me show you what that is. If you know Elon Musk, if you know SpaceX, I am a huge fan and I really always wanted to make my own rocket. So this is a perfect opportunity. And now we can create these to one of them is the heavy Falcon. One of them is the Falcon nine. Honestly, I feel that we don't need to go that deep into the Falcon Heavy because it has many sides to it and it's going to be hard to balance. But if you really want to go deep into creating your own rocket, I really encourage you to go and do that, but I personally will look into creating something similar to the Falcon nine. Maybe not the same proportions, maybe a bit of different columns, but the design will look similar. So let's go ahead and try to do exactly that. Back in unity, we are going to right-click on the hierarchy and create an empty game object. And this empty game object will reset its position 200. And we're going to name this our rocket ship. So this is the essence of our game, the rocket ship and the space bound will see later on, it should be in the background. Okay, cool. So now we have a rocket ship. What does a rocket ship need? First of all, well, it needs a body. So let's go ahead and create a body for it. So it's going to be a cylinder. Let's reset the cylinders position. And let's put in here, I'm gonna make a bit of changes to our cylinder of course. So let's see. So first thing first we are going to maybe increase the scale in the y. So let's make it a bit taller. Let's look at that. By the way, I'm going to, whenever I finished this rocket, I'm going to put it in the resources so you can use the same rocket, or you can simply go along with me as I'm creating my rocket right here. But my advice to you is to create your own rocket because we are going to be doing a lot of things with our rocket throughout the scores. So it's really nice if you have your own design and you put, you put in your own creativity into the game to feel much nicer when you start rotating and moving our rocket through our levels. Anyways. Let's continue on. Feel free to do whatever you want. On the x. We're going to make it about 0.8 and in the xhat will make it about 0.8. So it's a bit of a thinner cylinder. So it looks, I think that looks kind of good. Maybe increase this to 2.5. oops, 2.5. please. Starting to look a bit too tall to keep it up to. Okay, cool. So now we have the body that's changed the name to the rocket ops. Rocket or simply body. Let's make this the body. Okay. Now before we move on, we need to add the body to the rocket ship as a child. And whenever we put an object under another object, basically we are building more on parent and child relationships later on. So now we have the parent as a rocket ship, as you can see, its position. And if we look on the body, this is its pushes position right here. Whenever we move the rocket ship of game object, you can see that the body moves with it. So let's reset its position down here, and we'll keep the body on right here at 0. Okay, great. Next thing we need to do is we need to create the nose for our rocket. And I'm looking to make something that is a capsule. So where's our capsule? Reset its position, and this is going to go on top of our rocket right here. So let's see, is that good enough or should we change it a little bit? Maybe decrease the scale to 0.8 on the x and z. Let's look at nana. I don't like it back to one. So make the X1, the x1. And you know what? Actually, that looks pretty well. So of course we are going to change the colors later on. Later on, let's look back at our diagram. And it sort of does look like a capsule. Now it is a bit more pointy and that's for aerodynamic reasons. And under here it's a bit more going down, but it's pretty close. It's pretty close. I think. Honestly, we don't need to be rocket engineers. It's all about the gameplay, but design is also very important. We are going to decrease the x a little bit, so we make it 0.7. on the x and on the x_hat. And nice. So I think this is what we are looking for. Let's show this into the rocket ship. Okay, now, so the capsule, which is our nose, is that how you write knows, I'm not even sure. So now we have the nose and the body. Next thing we need is we need to have a couple of legs to support our rocket. So let's go ahead and create a cylinder right here. Again, 3d. Create cylinder and we'll reset its position. And here we have a small cylinder. So what should we be doing with the cylinder? Well, what I'm looking for is to actually, oops, is to actually make four little legs right here on the rocket. And if the shadows are bothering you, just like the bothering me, you can go into the direct light and here you have the real-time shadows as one. You can decrease it to about 0.4 or if it's not bothering you, keep it at one honestly item, I feel it's very bottling and Stuart's my perception of 3D. Anyways, we want force more legs on each side of our rocket. So let's go ahead and decrease on the x scale will make it 0.3. And these at scale will also be 0.3 and they are still too big. Let's make 0.01. 0.01. okay, that looks thin enough or 0.15. now, by the way, I'm winging it, so I'm not sure how this design is going to look at the end. Okay? Nope, 15. So this is how basically you design a rocket. Maybe I'll spit it up, will decrease the, why. Let's go ahead and add a bit of rotation. So whenever you want to rotate, you need to look at the axis that we have. So up here you can see that we have the zed axis as the blue, we have the X axis as the red, and we have the y axis as the green. So we want to rotate our object around this axis right here, which is d xat Cu. So you understand that you go into the transform rotation and you rotate your axis around the xhat. So we put it down here. Let's see how that whoops. Let's see how that leg looks like. So I think it's kind of nice. Very nice. So let's have a better look at it. We need to make sure that it's barely inside of our rocket for maximum authenticity. Okay, maybe put up a bit, maybe rotate it a little bit more. Maybe let's see how that looks. And actually, let's keep this at 0.01. 0.01. and nice. So this is the leg of our rocket. And is it good enough? Okay, cool. So I'm happy with it. Maybe a bit more rotation later on. But anyways, let's continue on. Now we also need to chart this rocket and we'll name this the leg. Right? So this means it's the leg on the right side of our rocket. Next thing we need is we need to create the lag on the left. And before we add in another cylinder and start to change the position rotation and everything. It's actually much simpler than that. So we duplicate the lag on the right, and it's going to be the lag on the left. And oops, let's change that again. So like left. And now all we need to do is we need to change the positions a bit. As we know, the position around the x 0.5 three to make it on the other side exactly the same, we simply put a minus behind it and we change the rotation from thirty-three point seventy four to minus 33.74. So now we have a leg on the left side of our rocket, which is perfectly balanced with our right leg. But now, as you can see, our rocket only has two legs and it's probably going to fall off whenever we put a rigid body on it and whenever gravity starts affecting it. So we need to add two more legs on the front and on the back. So let's duplicate the leg left. And this is going to be the leg luxury, but like it's going to be, let's keep it at like and now we need to take the position of x, copy it, and put it on v, z. And we are going to make the exposition 0. So now our leg is directly in front of our rocket, so this will be the leg front. And the rotation on the z should be copied to which one? Well, I think let's try maybe sometimes when not sure. Okay, so it's not divine. It's the x and we'll put the x_ 20. And as you can see, we need to make it on the other side so we remove the minus end. We have a leg on the front. Very nice. And finally, we need to add the lag on the back, duplicate the leg front, naming the leg back. And of course we are going to change these Z, two plus Z and the rotation around the x to the minus x. And now we have four beautiful legs around our rocket. And actually our rocket looks pretty cool. So next thing we're going to do is we're going to add some materials to our rocket differentiate because now it looks a bit bland. We need to add a bit of material, materials to our nose. I think I'll make the nodes black, very dark black. And the legs will also be all dark black and the cylinder should be white as much as we can. So let's look at this. Okay, so maybe the nodes on the Falcon nine isn't black, but I would like to make it black so it looks much more static. Maybe Elon Musk would look at my rocket and say, well, maybe Michael was right, maybe I should make the nose black anyways, By the way, I think the nose is white for thermodynamic reasons, whenever the rocket leaves out of the atmosphere and it gets hot. Anyways, enough physics for today, let's go back and create a material for our rockets. So we're going to create a material right here. And this is going to be the body Matt. So body material. So now, as you can see, even whenever we choose the white color right here, the rocket never goes full white. And that's because of the shader that we have on our body material. So we need to change it from Standard and choose the specular reflected. So this will make our rocket the right white color that we want. And if you're not sure what the specular and reflective or well, shaders are actually. They can be a course on their own and know that it's a very good shader and it makes the rocket wide, so we'll keep it at that. Okay, great. So we keep it white. Now we're going to duplicate the body material. And we're going to change the body materials, materials named to the nose and legs material. And the nose and legs material will be added to the nose and we'll change the color to black. So we'll make this completely black. And as you can see, it's transparent. We need to reduce core, okay? And we'll make the color of the spectral also black. And we have the reflection color, which should be completely black also. So as you can see, it's super dark. It's so dark we can barely see anything. We can increase or reduce the shininess. We can change the specular color just a little bit to make it shiny. So we put it on white up here and maybe increase the shininess just a little bit so our rocket doesn't look that dark. Okay, noise. So now we have, I kind of put the nose on our rocket, very cool, or are on our rocket. And let's add the same color to the legs. So we add this one and this one. And let's go ahead and add to all of our legs. And we have a pretty nice rocket. So the only thing missing, of course, is the Space X logo right here, but I'm not even sure if that's legal. Anyways, maybe we'll add it later on. But this is basically our rocket and it looks pretty cool if you ask me. So let's save that. And let's go ahead and prefab our rocket. And before we go, I want to start off project on a good note. So a very good thing to do is that we need to create folders. So we'll create a folder for the materials. And lets select all the materials and put it inside of the materials. And we're going to create a folder for the prefabs. And we'll put the rocket ship inside of the prefab. So this rocket, I'm really liking it, honestly, it looks really nice. So we save that. We have our rocket and we need to make sure that everything moves and rotates to gather. So we move, we rotate our rocket. And if you look closely, the rotation is a bit weird, as if it's not rotating around its center. Isn't that weird? It is weird and we are going to look into that a couple of videos. So I hope you enjoyed this video and before we go, I will issue you a challenge. And your challenge is going to be to create your own rocket. So find the design you want for your rocket. Create that design using primitive shapes. That means the cylinder is the cube, the whatever you want, go wild, Put on your creativity gaps and do what ever you want. The rocket is not, will not be affected. Whatever it is, just make sure or tried to make it a, how should I call it symmetric? So you need to have symmetry in your rocket and to create your own material and play around with the colors, make it unique to your own taste. And most important part of the challenge is to have fun, because at the end of the day, you are creating a rocket that shoe are going to be using and you are going to be flying it around. So pause the video right now or wait for divinity to end and go do your own ROC. How see you in the next one? Hey, Michael here from the future. One more thing before we go is, and that is to go into the source tree. And as you can see, we have new onstage files. And if we staged them and look at them, you can see that these are all the things that we've created after the initial commit. So these are the materials, the body material, the Prefabs folder that we've created inside of assets. You can look at all of these things. The changes that we've made to the sample seen lighting where we decreased the shadows, the rocket ship prefab that we made, the nose, the cylinder, and the terrain, all of that we've created. So we staged them. So as you can see, we stage, all right here, all of the files or staged, we click on Commit and we named this creating or no, shaping our rocket ship. Okay, nice. We click on Commit. We wait for it to commit. We click on the master, and now we have the initial commit with these shaping our rocket chip. Very nice. So make sure to use the source tree. It's very important and I'll see you in the next video. 15. Basic Rocket Inputs: Welcome back, my fellow game developers. As you can see, our rocket ship now has a rigid body and it has a script attached with, when we click on play, the rocket should fall. It does. And if we press the space bar, we get flying a free press the a and d, we get turning left and turning right. So let's not waste any more time and let's get started. Oh, okay, so before we start adding a bit of input, let me just talk a little bit about what parent and child relationships are. So I've done it right here. As you can see, these are all children of the rocket ship. Now you might be wondering, why do we even need children and parents? Well, because of obviously survival of the human species. But other than that in unity, these are very important elements because as you can see right now, the nose, let me click on denotes the body and the nose and the legs are all separate game objects. So as a consequence, you might think that each of them will move on its own accord. And if you want to move the left leg and the right leg anti-nodes antibody, we need to add every single game object, its own script. And that is a daunting task. So the better way of doing this is to simply create an object which is our rocket ship, which will be the parent. And add all of these little game objects which are connected to the same principle or concept. For example, the body is part of the rocket ship, the nose is part of the rocket ship. We add all of these elements to our parent rocket ship and N, our parent rocket ship, we can simply add in this video, for example, we'll add a rigid body to the rocket ship. So when, when this rigid body is applied to the parent rocket ship, all other little children right here will also be affected by gravity. And as if we've added a rigid body to each and every one of them. So this is a huge advantage of having parent and children relationship. And we can also add a single script, as we'll do in just a bit to the rocket ship. So all other children will also have this same mechanic and we'll move in unison with the main object, which is the rocket ship. So now you can see that whenever we moved the rocket ship, we're not checking on the leg. We can also move the nose, for example. And if we check, check on the rocket ship, you can see that even its center of gravity changes. So this is very important now when we move the rocket ship, you can see how they move together. And not only move, they also rotate together. So let's try it around these other axis. So they rotate together and they also scale together. So you can see that the nose, even though it's not connected to the rocket ship, still moves with our rockets. So let's control zed, all of that controls that means that. And do all that. And let's actually start with the video. So what are we going to do? Well, we are going to be adding input to our rocket. We've already done input in the previous section, but we'll just refresh our memory a little bit and, and gauge where our understanding of C-sharp is at the moment. So first thing first, we are going to add a rigid body to our rocket ship as promised. So let's go ahead and search for a rigid body in the components. And now our rocket ship has a rigid body. And let's test this rigid body. We even didn't even start on the game mode. So let's center our camera and a way that will enable us to see everything. So I'll think, I'll put it up here. Oh, okay. This is a good angle. We click on Main Camera, we go to the game object and we align with the view. So you can see right here on the right down side, the main camera looks like this. So when we click on play, this rocket should be falling. And it is very nice. Oh, okay, great. So our rocket now has a rigid body and it is affected by gravity. Before we move on, let's have a little bit of fun. So let's remove this left leg, but unity won't let us because we need to go out on the prefab. To remove the prefab from our rocket ship, we can simply right-click on rocket ship. And you can actually access the prefab and use the unpacked completely. When we unpack it, we can actually go ahead and delete this. Don't worry, we still have our rocket and our prefects. That's the use of prefab. So we click on play. And let's see how our rocket behaves. And as you can see, because it doesn't have any leg on its sloughed. It falls down to the ground. Okay. And a fun let's put back the left leg. Nope, it's not letting me. We'll delete the rocket ship And we'll add another one because we already have it in our prefab. So this is the magic of prefab. And let's not forget the rigid body on the rocket ship. Okay, great, so let's save that. And actually let's go ahead and apply this change to our current truck. But before we do that, let me show you. So if we click on the prefab rocket right here and our assets, you can see that it only has a transform and doesn't have a rigid body yet. The rocket ship in our scene does have a rigid body, but it has a small blue line right here, right next to it. And to change that, we simply apply all. So we click on overwrite. You should have a button that is apply all. And now if you go into the Prefabs and the rocket ship in our assets, you can see that it magically get's a rigid body. So whenever you make a drastic change to a game object, that is a prefab and you want to keep that change in your preferred. Whenever you create a game object, again, make sure to apply all and override it. Oh, okay, great. So now it's time to add a bit of behavior to our rocket. So we want to create a script that will enable us to use and puts on the rocket. And whenever you want to create a script on a certain object or a log of objects, for example, the bodies and knows and the leg. You always use the topmost for the parent to add that behavior and script. So we'll add a component, we'll call it the rocket. Ship. And we're going to create a new script right here. So rocket ship makes sure that you have the right name. You can name it whatever you want. Just make sure that it's the name that you want because later on changing it will be a pain in the behind. Ok, so we'll wait for unity to compile script. And now we have a script and it's also yellow, blue. So we need to apply all of that later on, or we can simply apply it right now. So let's go ahead and do that. We've applied it. Now the script is present on the prefab whenever we create a rocket. It will also have that rocket ship script on it. Just wanted to make that click. So let's create a folder. We'll name this the scripts, and we'll add the rocket ship into the scripts. We double-click, double-click inside of the scripts and we open up our rocket ship script. And any second now will have some code. Okay, great. Now you are already familiar with inputs, so I'm not going to go into details over them. We are going to first of all create an if condition. You already know if conditions. And by the way, if you don't know what's happening or what I'm even talking about. Make sure that you go back to the section two where we talk about all the basics of unity and C-Sharp. Okay? So input dot get key. And we're going to access a key code, which is going to be the spacebar. And this space part is actually going to allow us to fly. So before we do anything, we're simply going to print flying whenever we hit the spacebar inside of update. So let's save that. And let's see if that works. Back in Unity. Makes sure that you have your console right here. If you don't, it's an window general and you should find it right here when you click it. So console, let's see what happens and save the scene. Let's click on play. Our rocket falls, we press the space bar and we have a flying, a lot of flying. And that is because it's called in the, in the update. There are a lot frames. So even when you try to press the spacebar very fast, whoops, let me back in the game. Press Space-bar very fast. As you can see, that almost 30 presses. Anyways, this is clearly an indication of everything working extremely fine. So now it's time for your challenge. And your challenge is to finish the rotations. So you'll need to finish the conditions for rotating the rocket left and right. Just as we've created conditions on the inputs for the flying, you are going to create the conditions for the inputs for the rotating left and right for now. So as you, when you finish the inputs, you need to extract the lines of code in two separate methods and keep update clean. So as you can see, the challenges are getting harder. So make sure that you are paying extreme attention to everything happening. Pause the video right now and go do the Challenger. Oh, OK, welcome back. So I really hope that you have done the challenge easily because we have already covered all of this. So let's copy the stratosphere. It's perfectly fine to copy. Just make sure that the key code in here will be the a button. And this will print turning left. And when we had the D bottom, so D, we are going to be turning right. Actually, this should be rotating right. So turning right, turning left. And finally, let's, before we do anything crazy, let's see if that works. Click on play. And if you don't want to see many lines, you can simply click on collapse that way the messages that are similar to each other will be collapsed into a single line. So we click on the space bar, right? Click on the space bar and we have a flying. We click on the a button, we have turning left. And if we click on the right, we have turning right. I mean, on the D, we have turning right. Excellent job everyone. Before we go, let's go into the update and let's extract all of this. So, oops, let's extract all of this. What's the matter with you, please? So extract all of this quick and what should we name it? Well, we're going to name this v. Oops, the rocket movement. So now we have inside of the rocket movement that flies, turns, rotates our ship and does everything will come, will actually delve into the forces and rotations in the next video. And of course, before we go, we need to go into our source tree. And we need to stage all of our work. So we stage all we commit and what should we call this? Well, we're going to call this the adding basic inputs. M boots. Okay, great, so adding basic inputs. So now if we go into the master, we can see that we made an initial commit. We were shaping our rocket ship And now we added basic inputs. Very nice. I hope you enjoyed the video and I'll see you in the next one. 16. Flying Our Rocket Ship: Welcome back everyone to a brand new video. And as promised, when we click on play, we can turn left. Well, of course, from the console we turn right from the console, but if we hit the Spacebar, we actually start flying. So this is a very exciting video. We are going to add a different kind of force, not exactly the one that we've learned before. O, we'll have come back little rocket. And we're going to learn about adjusting the mass of a rigid body and all sorts of exciting and fun stuff. So let's not waste any more time and let's get started. Oh, okay, so flying our rocket, what do I mean by flying our rocket? While we're going to be adding a force to our rocket in the direction of the actual, actual rocket ship and it will move upwards for now. So first thing first, we need a reference to our rigid body and you already know how to do that. So let's go ahead and do it. So we'll create a rigid body. We are going to call it my rigid body. And inside of the start we are going to get my rigid body and it's going to be equal to the get component, rigid body. And that's it. Now we have access to our rigid body. Next thing we're gonna do is we're going to be adding a force, but not just any force. We are going to be adding a relative force. Why are we adding a relative force, not a normal force? Well, let me take you to the documentation so I can explain it better too. So ridged body dot add relative force. We've learned before that adding a force will move our object in the direction of the vector that we give it. But the problem with our rocket is that sometimes, So let me go to the rocket sometimes for example, let's say our rocket is rotated in this direction. So we want to add a force upwards, right? Well, if we start adding a force upwards, you can see that it basically looks very stupid. What we want is we want the force to be added in the direction. Whoops, wait a second. We want the force to be added in the direction of the rocket or the direction in which the rocket is facing. So when we rotate our object, we want the, the force to be added in that direction. And if we rotate the object in the other direction, so oop, we rotate the object in that direction. You want the force to be added, ok, please. And that direction, so our rocket moves in the direction of which it was rotated in, and that is where ad, relative force comes in. So back in the documentation, in the description you can read it. It adds a forced the rigid body relative to its coordinate system. That means it adds the force relative to the way our coordinate system is facing. So we'll be using the Add relative force back and Visual Studio. And here you can see that because we've extracted our method. And it doesn't have any variables in it. It created a static now will not be bothering with what static is because we will not be using written scores, but feel free to go and search for it on wrong. It's very important. It's not that hard. It's maybe it will take you a maximum of two or three minutes. Anyways, inside of flying, let's delete the printing. And now we're going to use my rigid body dot add relative force. Ok, that rigid body was completely wrong. So my rigid body, not sure why the queue was added at the end. And we're going to add a relative force. And this relative force, as you've seen in the documentation, takes a vector three and we're going to add the vector three and it's going to be in the up direction. Okay, great, so let's save that and let's go back into Unity and see if anything works. So we click on play. And now if we press the space bar, we should start flowing upwards. And we are, we have liftoff, Houston. We are on our way to Mars. So nice. Before we go, let me, actually, I want to add more control over our rigid body or over our force. So we'll create a float appear. And it's going to be the main thrust. And this main thrust will have a value of two f. And we'll multiply it by the main thrust. Let's save that. Let's go back to Unity. And let's see if that works. And now we have liftoff. So as you can see, I feel that we need a little bit more force or, or if we want our rocket to move faster, we can actually reduce the mass on our rigid body. So let's reduce the mass, mass to 1.18. And hopefully this won't fly out immediately. Okay, so as you can see, it's much easier. Whereas our rocket, as you can see, it's coming down back to Earth. Very nice. So you can either change the mass or if we keep the mass on the one, we can go back here and maybe make the main thrust like, I don't know, maybe 50. So save that back into Unity. Click on play, and let's see how that looks like. So it also is extremely fast. So this takes us directly to our challenge laser. So adjust your roasting, calibrate the main thrust of your rocket to get a speed that suits your play style, I don't need to take too much time on that. Simply find a nice point of your main thruster cube like will be calibrating it also later on. But for now, you need to flex your game developer muscle and calibrate the game to your own play style and adjust the mass of the rocket if you feel it requires. So pause the video right now and go do the challenge. Ok, welcome back. So I feel 50 is too much. Let's make it ten or 100, that's making them. So we click on play and our rocket and see how the movement goes. Okay, I kind of like it, it's not bird then is not bad, maybe just a little bit less. So we make it eight. Save that back in Unity, collect on play. And 88 actually does the trick, and it looks pretty cool. So hope you enjoyed this video. And before we go, as always, we are going to commit of all of our changes. So where are our changes? Click on Commit. And here we only make changes to the script. But that's enough. So we stage the script and we're going to call this, what should we call this? Flying our rocket. So I'm going to be naming it. I think always as the title of the video is feel free to name your commits, whatever you want. So final rocket with have our convinced right here, and I'll see you in the next one. 17. Rotating Our Rocket Ship: Welcome back, my fellow game developers. In this video, we are actually having a proper rocket. So now when we press the space bar, we get liftoff Houston. And when we rotate, we actually rotate our rocket. And as you can see, we have finally find, found a good use for our ad relative speed. So now our rocket moves around and goes out of view. God knows where, whereas it oh, rocket. Okay, so, oh, there it is. A rocket. How are you? So let's not waste any more time and let's get started. This is the most pathetic rocket diversity. Ow, kay, so rotating our rocket ship, how are we going to do that? First thing first, we need to choose the vector around which we are going to be rotating our rocket. So now we have three options. We can either rotate it around the x-axis. If we rotate about the z axis, nope, that's not what we want. And we already have a lot of errors, so now we can rotate around the y and it's also not helpful. And we can rotate around this, that while nice, this is the x we want to rotate it around. But as you can see, there is something weird and I've alluded to that in a previous video, but now it's time to address the problem. So now if we choose to rotate around z, you can see that our rocket isn't actually rotating around itself. It's rotating around some weird place or some center. Maybe it's the bottom of our rocket. Well, the reason for that is when we click on the rocket ship, you can see that actually the position of the rocket ship is right here in the center and you think that it should rotate, it should be rotated there, but it doesn't. It actually rotates around something called a pivot point. And that point isn't visible right now unless we go up here where we have the center and we click on Center, and now we get the pivot. So, oh, what is that? Well, if we start rotating, it's obvious that our rocket ship is rotating around the pivot and not the center of our rocket. Okay, so now that we've learned that it's time to fix that, and how do we fix that? Well, we need to put down the position of our rocket to the y equals 0. And let's go down and see how that looks. Okay, so now our Y is on 0. Next thing we're going to do is we're going to take all of our rocket objects. So select the first one and then hold down shift and select the last one. And then we're going to move our rocket down until we get to the 0 almost. So you can see it's kind of, it's yellow, so it's not very visible, but you need to make sure that you put it almost at 0. Now we choose our rocket ship and we move it up. And while you're doing this, makes sure that you are in pivot mode. This is crucial. You need to be Pivot mode when you choose all of the other objects. Now, if we click on Center and we click on pivot, it's almost the same. That's good enough. So let's try the rotation now around the zed axis. Choose this ad rotate, and it looks kind of cool. So this is perfect. It's working perfectly fine. Now it's time for so some coding, okay, now that we have everything established, first of all, we're going to write the script of rotating to the left direction, which is right here inside of the a. Now with print. Now, what should we be doing? Well, we need access to our transport and transform. We can actually use a method that is called the rotate. And now we need to choose the vector around which we are going to be rotating our transform. Philip, back right here, we can see that we are actually going to be rotating around zone that was established previously. But we don't have a vector zed right here. So we're going to use the next best thing, which is the vector three dot forward. And the vector forward is actually the xhat vector. Because when you look at unity, we can, let's imagine we're looking at directly in the face right now. And the vector forward is wherever vector that goes towards the screen. So forwards towards the screen, that means it's the z axis right here. Very nice. Next thing we need to do is we need to add a rotation on the whenever we present it D, so it's to the right. And we want to go the other direction. So we need to choose the minus vector threefold. Let's save that. So we've added simply, we've added a minus behind the vector three forward. Let's go into Unity and see if that works. So we no longer, we shouldn't be printing to our console. Window up. Okay, great. Now we rotate and we rotate perfectly fine. Did you see that? So let's try that again with you. And as you can see, we have a working relative force while our rocket still kind of crazy going around everywhere. Well rocket comeback and it has disappeared somewhere down there. By rocket. You can still see it. But anyways, everything works fine. The problem is, is that our movement is very dependent on the frame rate of our game. So if some of you out there play video games, as I'm sure most of you do, you know a thing or two about frame rates. So it's the frames per second, which usually is bad on a bad computer and good on a good computer. So we need to check what these are. And here, when we click on play, up here you can see that we have an option for stats. And when we click stats, we can see that based on our graphics, we have 2002, maybe 3 thousand frames per second. Now, maybe yours is a bit different, Mine is a bit different. It doesn't matter. The problem with this is that when we add many game objects, our frame rate drops. So the update for the pack on update, which is update, is called once per frame, our frame rate drops, our rocket movement will be very different. And this is a huge problem because when we're, when we'll start building, levels will have rotating objects around us, will have lights, will have, will have post-processing, will have a lot of things that are working together and that will of course drop our frame rate. And if our frame rate drops a lot, our game will start lagging. And the fundamentals of our game, which are flying, thrusting, and rotating, will be affected by the frame rate. And that is a very bad game design. A concept we need to change that. We need to have separation between the frame rate and the speed of our rotation or rocket. And that is where something called Time.deltaTime comes in. So let me explain what is time to cut the time. It's the time since the last frame was completed. So that gives us the time between the previous and current frame. Why do we need it? Well, it's used when you want the movement to be the same speed no matter the frame rate. And it makes our game run independent of frame rate and computer hardware. So whatever hardware, your player, or anyone who's looking to play your game has, your movement or your game will be independent from the frame rate. And that is very important. So now we know what is delta time as the time between the frames. We know why we are going to use it, but how are we going to use it? Well, back in unity, and here we are going to simply multiply our vector forward by time dot delta time. And what this does and why it's separates, because we now have the time between each frame and we're multiplying it to our vector. So it doesn't matter what the frame rate is, no matter how it fluctuates, the time between each frame rate will be the same. So our vector four will be the same, but we'll multiply it with this one. And we're going to also be multiplying it up here. But the problem with this, and it's a very slight problem that you'll see when we start playing, is that now if we try to rotate, we don't actually have any rotation. Well, we do have a rotation, but it's so small and insignificant that we don't even notice it. And why is that? Well, because our Time.deltaTime is very small as you saw. There are 2 thousand frames per seconds, so the time between each frame is very, very, very miniscule. So what we need to do is we need to create a, just like we created a variable for the main thrust. We are going to create a variable for the float rotation thrust. And let's simply put it as five. Just for now, just check F. That is enough. And let's go ahead and multiply this by V rotations. Rust, copy that and multiply it by the rotation thrust. So let's save that. And let's try it out in unity. So we click on play. Is that enough? And as you can see, it's a bit better, but we still need more. So let's go ahead and make it 50. Cool, 50. Let's try it out. So we click on play, and now we move up and we rotate it a little bit better. I feel that we need to go all in on this and let's make it 100. Okay, that's not actually all n, but let's see if that's enough. So again, him VOIP, we rotate, we still need a bit more. And I think this is the perfect time to issue you a challenge. So your challenge is going to be to adjust your rockets rotation. Understand how rotation mechanics are working. So go back and look how our rocket is actually moving around the forward axis, which is the zed axis. Adjust your rocket ship pivot point. It doesn't have to be right in the middle, just like I did. It can vary a bit, depends how you want your rocket to feel. Play around with the pivot point, see how it works, and finally, adjust the rotations to your liking. So check how you want to make your rotation, how fast you want to be. Maybe 100 is enough for you. Maybe it's not. I don't know, it's your game. So pause the video right now and go do the challenge. Okay, welcome back. So 100 is not cutting it. 500, opps, 500 now when we click on play, O K. So finally, finally we have a rocket that is moving properly, but as you can see, it's not actually moving properly. We have weird rotations around weird angles, and if we hold down space, our rocket goes flying everywhere, but no worries, we'll be fixing all of that later on before we go, we need to do two things. First of all, we need to multiply the main thrust by the time, delta time. And a good habit is that we can actually go ahead and create right here a float that is going to be our rotation speed. And the rotation speed will be equal to Time.deltaTime times rotation thrust. So because we're using a two times right here, we can now simply use the rotation speed variable to change everything we have and look, our code looks much cleaner. You can do the same here with the main thrust and Time.deltaTime. But because we're using Get ones, I don't feel that it's very necessary. So save all of that. We need to adjust, of course, the main thrust, let's simply put it to one hundred, ten hundred and space. Okay, it's a bit slow, as you can see. Let's make it 2 thousand. Back in Unity. Click on play. 2 thousand is actually good enough for now, so great. Before we forget, go into the source tree, click on the uncommitted changes. Sometimes they don't show up, no worries. You can always click on Commit and they will pop up right here. Stage all rotated. My rocket ship. Okay. I'm not sure why. I'm even capitalizing each and every single word. Let's keep it like that comment. And we have it inside of our master. Okay, great. So I hope you enjoyed the video and I'll see you in the next one. 18. Adding Audio: Welcome back, my fellow game developers. In this video, we are going to be learning about audio sources, will be learning about how to play audio clips. We'll be learning about a website. That's very cool. We are going to be learning about rock chips and how to add sound effects to our game. So now when we start thrusting or flying or pressing the space bar, not only does our rocket moves up, it also x equals sound whenever and when we released the spacebar, the sound goes away. Let's do that again. Very nice. So let's not waste any more time, and let's get started. O kay, adding audio. Very nice. First thing I want to talk about is where are we actually going to listen to our audio? Because if we have nobody listening, we can play anything. So we click on the main Cameron and here, the main camera, you can see it has a component which is the camera where you can play around with a lot of things. And there's also an audio listener right here. And this audio listener listens to any sound that is made inside of our game. Okay, great. Now, how are we going to actually play some audio? So before we do that, what do you do you wanna play? Well, we want to play the sound of our rocket thrusting. So when we click on Play, currently, we don't have any sound, but we want to actually have a sound whenever we click on plane. And that is used, or that is possible using something called an audio source. So let me take you to the audio source up here. Audio Source. So in the description you can read that it's a representation of audio sources in 3D. So you can attach an audio source to a game object for playing back sounds in the 3D environment, you can keep reading aloud around and you can see that it plays sounds. You also need to have the audio listener and it needs it can be attached to various things, but the best way to do it, the best thing to do is to attach the audio listener to the camera. Normally it's attached to the camera. You can play a single audio clip using the Play Pause and Stop. So we can use these three options right here to play pause and stop. You can also adjust the volume. You can seek through it using the time and you can play multiple sounds using something called the play one shot. Or you can use the static position, which means that you can choose at which position you want to play the audio at, play clip and on-point. Now, now it's not relevant, but keep these two methods in mind. So play one shot and play clip at point, these will be very crucial as we go on through our videos. So let's go down here and let's see what play and pause and stop actually does. So play, plays the clip. Okay, that's enough. Stop, stops playing the clip. So it really takes a genius to figure out all of that. Let's go to the play. So audio source dot play and see what it does. So at place the clip, what clips, what, what, what is the clip that they keep talking about? So let's go ahead and see what clip they're talking about. Here in rocket. We go ahead and add a Or do you source collect on the audio source? And here you can see that it takes an audio clip and that is the clip that everybody keeps mentioning and talking about. You can adjust the priority. So what sound, what sound plays before? This is not that important. You can adjust the volume, the pitch, the stereo pan. If you're good at music, feel free to play around with all of these. You can also, there are multiple things that you can adjust. But for me, for a guy that simply wants to add a couple of sounds, it doesn't bother me that much. Now, where should we go to get our sound effects? Well, there are two places. First of all, you can go into the resources and use the audio clip that I've provided. You simply click on it and drag it into your assets. Or let's click on it and listen to it. I hope you can. So as you can see, this is the clip that's going to be playing wherever we press the spacebar and start flying. Or you can go to this website right here, which is open game art.com. There are many websites where you can find sound effects for games, but this is my favorite. It's completely free. Of course, if you want to use it in one of your games, you need to make sure which license you're using, and you can choose any kind of song you want. There are also 3D or 2D order is music, sound effects, textures, documentations. There are plenty of things here on this website. And sound effect is where I actually get my sound effects. I get them here from open game art.org. So make sure you go and check it out if you want to get your own sound effects. And I, I actually encourage you to go and find your own sound effects because this is your game. So great. Now that we have our sound effect and we have our audio source, the only thing left is to go into the rock chip, find the Audio Source. And let's go ahead and drag the full, the audio source of the ship flying sound effect and put it right here in audio clip. And let's apply all of that. Cool. So now we have an audio source with an audio clip, and the only thing left to do is to play it whenever we press the space bar. But if you look carefully, click on play, some of you may have experienced it. We are not pressing anything and the sound is already playing. And that is because of something right here called the play on awake. So this place, as soon as we start the game, so will simply uncheck this box. We'll apply that. And now when we click on play, there is no sound, complete silence. Okay, great. Back in our code. Now we should get first of all, a reference. So audio source, we get a reference, so its my audio source. And right here we're going to get the component because it's present on our rocket ships or get component or dual source. I'm not sure why, but getting the components is actually very satisfying. It's easy, it's fast. And anyways, we now need to play the. Audio source and where are we going to play it? Well, we are going to play it inside of the, the condition of pressing the space bar. So whenever we press the space bar right here, we are going to immediately start playing our audio clip. So we'll call my audio source dot play. And this should work. So we save that. Well, actually, I have a little secret. Its won't be playing very well, but we'll do it anyway because we need to learn from our mistakes or click on play. We don't have any sound when we start pressing the space bar. Do you? Can you hear that? So whenever we click on play, we have two problems. First of all, we stopped pressing anything and it took time for our ship stopped making any noise. Is the other problem is that we have this kind of a, what should I call it 14. And we don't like that. We don't want that at all. The problem with it is, what's that sound? Well, you saw in the console how whenever we press the space bar, we actually have a lot of space bars pressed. So it takes in 20 or 30 times and this is a problem for us. And why is it a problem? Well, because the sound is overlaying on top of each other. So we press the space bar for the first time and we process it. We think that we've pressed at once. But in the frame, because we are planed based on the frame rate, it's pressing multiple times in a second, and that leads to the f sound that's starting in the beginning. And then when we release the spacebar and started to play normally as the last audio clip starts playing. How do we fix that? Well, there is a nifty trick that we're going to use. And we're actually going to create an if condition. We're going to open that if condition and we are going to write my audio source dot is playing. And if we hover over it, we can see that is the clip playing right now. So it's s, It asks, asks the question, Is the clip playing right now? So is playing. And if is playing equals false, that means it's not playing. Then we are going to today our audio source or audio clip that is on our audio source. So, but as you can see, there is a small, teeny, tiny problem. And we actually need to add two equals. And this will check if is playing, is playing. But there is not way. And if anybody there is good at coding, sees you doing this method. They will patch on the back and really recognize you as a real o colder. So instead of using equals, equals false to check if it's false, you can remove this and add an exclamation mark right behind my audio source but is playing. And this, what this means is that it Directly checks if the current statement after the exclamation mark is false. If it is, the if condition works. Okay, great. So now we check if it is playing. So if playing is true, so we are playing the audio source, we negate that using the exclamation mark. And then we either don't enter or enter. So if we are playing an undue source, this entire line or entire condition will be false. Therefore, we will not play it again and we'll simply thrust our rocket. The is playing is false. That means there is no audio clip playing. We, this entire condition will be true. That means we can start playing something and our audio source hope that makes sense. So let's save that. Let's go back into Unity and see if all of that works. Collect on play. And now when we start thrusting, we have perfectly good sound. Very nice. But there's still a problem. As you can see, we don't stop the audio whenever we stop thrusting. And that is a challenge for you. So your challenge is to stop the audio playing when we stop thrusting, thrusting, audio should stop. When we released the spacebar, the audio should stop. So this is basically like a small hand that I gave that I gave you. So I've already gave you a small hint at the beginning of the video when I showed you the documentation. So go back to the documentation, read a little bit about audio source and what type of methods we can use to manipulate the audio clips on it. And you will have the answer to the challenge. So pause the video right now and go do the challenge. O kay, welcome back. So how did you get around with that? We are going to be using something that's called my audio source dot stop. So we're going to stop whenever we stop hitting the space bar. And this is where the else condition comes in. So if we are not pressing, oops, so if, whoa, okay, so if we're not pressing the space bar, we are simply going to call my audio source and we're going to stop playing. Cu. So let's save that and let's see if that works. We click on play. And now we thrust. Can you hear that we actually stop our music from playing? Very nice, not art music actually our sound effect from playing. So we hit the Space, we have sound. We released the space. There is no sound. So it works. Great. For the last thing we need to do is we need to create a folder. So we're going to name this deed as effects, meaning sound effect. And we'll put the ship sound effect inside of this folder. Save all of that, go and commit your changes. So uncommitted changes, there is a lot actually. And we are going to commit all of that. And we'll name this commit adding as effects to our rocket ship. And it's all capitalised nature. Why comment that? And now we have it in our masters. I'm very excited for the upcoming videos. I hope you enjoyed this video and I'll see you on the next one. 19. Solving Movement Bugs: Welcome back, my fellow game developers. As you can see, we've created an obstacle, we've created a landing pad, and when we click on play, we have fixed all of our movement issues. So now our rocket is gone. Okay, it's back. So now our rocket No longer does weird movements at flies. Okay, that is a word movement that will fix later on, but at least it stays in the same plane as we wanted, and it does not go into space and into different direction. We can always control it right here. We can go from our launching pad to our landing pad and we can actually land our rocket. We have full control over the rotation of our rocket. And it's a small step for humans and the huge step for humanity. Or is that not the quote, I think something different. Oh, okay, let's get started. The first thing we need to do is we need to go to our code. And rocket movement is actually getting a bit messy. So let's extract this right here, which are the rotating, Oh my God, we're going to extract this. So quick action and refactoring, we're going to extract a method. And it's going to be rho, dating hoops, rotating our rocket or simply rotating, rotating or rotation. It doesn't matter so rotating. And as you can see, because we've created the rotation speed right here, and it's used down in these conditions. It actually created a parameter. Now, if you, you can do two things right here, you can either copy it or delete it from here and copy it right here and remove the parameter. Or you can keep it this way. It really doesn't matter. Let's keep it. It's kind of cool and it's a good lesson for us later on. Next thing we need to do is we need to extract this right here. And we're going to call this method extract method, and it's going to be called the rusting. So now we have two Austen and rotating. So let's move here. Let's put a space between them so we can differentiate between it. Now, honestly, I don't like this right here. It's kind of in the wrong place at the wrong time. But let's keep it, let's keep it, it's good. So now you know how parameters work, but you have a better grasp of how parameters work. But next time whenever you are coding your thing and you're already professional and you know what you're doing. This not recommended. We'll keep it as a reminder of how we are learning step-by-step and every time we watch a new video, okay, the next thing we need to do is we need to go into Unity and we'll create a landing pad and some kind of obstacle. So the way we create a landing pad, let's take our platform and we're going to duplicate it. And by the way, are used to duplicate a couple of videos ago and I didn't tell you how. It's fairly simple. You simply click on the thing that you want to duplicate, you hold control and you press on D, And now you have a second platform. So this is going to be our landing pad. So let's change the name. So landing, oops, landing pad. And this is going to be our Launching pad. And let's create a material for our landing pad. So we'll duplicate the platform material and we're going to name this v. Oops, vi landing material. And this one is going to be called the op note, by the way, no, sorry, sorry. This should be the launching material because we'll keep it right here on this one. And this is going to be the landing material. And let's remove the one at the end of this one, and we'll change the color to blue. So now the landing pad is blue. Next thing we need to do also will need to prefab. So let's prefab the launching pad and landing pad. And let's go ahead and prefab the terrain. What else should we prefer for now? Nothing. Let's create a 3D object. A 3D object, please. It's a cubed, will reset its position. Let's put it up here. Let's increase the x a little bit. And these a lot and the y just a little bit. And this is going to be our obstacle. So it doesn't look like an obstacle. No, it doesn't. But for now, this will do, this will be our obstacle. And we're going to create a material for it also. So we duplicate. This is our, oops, nope, not this one. Find the one that has a one at the end of it because that's the copy. And we're going to name this obstacle ups, ductile material and it's going to be reddish, red ish. So obstacle material, now we have an obstacle, we have a landing pad and we can click on play and see what's wrong with our movement. So if we move, if we hit the rock, the obstacle, for example, we can see that now our rotation is weird, so our rocket is looking at us and it's not actually facing the way we want it. We want to keep it in this plane. So that means we want to keep it in this plane. So our rocket shouldn't be moving right here in this plane. It shouldn't be going left and right and falling off and doing whatever it's doing right now. So we need to try and freeze the rotation around a certain axes. So let's do that. In order to fix our vacuum rotation, we need to use a special function on our rigid body, which is called the freeze rotation. I'm not gonna go too deep into that. It's fairly easy. So we go and we find the rotation or the rotating. And in here, before we start rotating, we're going to call my rigid body dot freeze rotation. And it's going to be equal to true. So before we start rotating, it's going to be true. And my rigid body, when we stop rotating, is going to actually be freeze rotation and it's going to be equal to false. So what does this actually do? Well, before we start rotating, we are going to freeze our rocket position. When we stop rotating, we are going to continue to rotate our position. Let me show you how that works in our game. So we click on play. We move up, we rotate our rocket and as you can see, it stops rotating Now we can rotate it back so as you can. Okay. Now it's falling a bit, but no worries. This help her. Okay, whoa, bye-bye rocket. So it's a small adjustment to our rockets rotation, but it's not enough. We still have a lot of things wrong with our rocket. And one of these things is that it keeps going back and forth. So to fix that, we are going to be using something called the late update. So let me show you what late update is in the unity documentations. So this is what peak called The late update. And as you can see in the description, until late update is called every frame. And late update is called after all the update from functions have been culled. Now, why are we using late update? Because we want after every single update. So when we finish rotating here and update, whereas an update, we check for the rocket movement, okay. We do a thrusting maybe or a rotating. So we rotate. Okay. When we finish rotating, the frame ends and then another frame starts. But during the frame that we rotate, our rocket goes a bit haywire and it goes all over the place. That's why we need to reset the rotation or the angles of a rocket at the end of every single update. So it doesn't stray away from the path. Let me show you what I mean. And we're going to create a private void, late update. Ok, so now we have the late update syrup and what we're going to, and this is going to be a bit scary. But fear not. We're going to use something called Local. You learn angles and local use Euler angles. I'm not sure how that spelt. So local are actually a vector three. And that vector three is actually the angles or its steep. How should I say it? It's the way Unity measures angles and its engine. Don't be afraid. It's nothing too scary. It's simply going to be 00 y 00 because we want to keep the angle of our rocket in the 0, in the x axis, 0, in the y axis, 0, but in the zed axis, we want to keep it the same as the transform dot local Euler angles dot z. Ok, so to new very scary concepts, let's go over them a little bit. First of all, delayed update, it's called whenever the update here finishes. Why are we using late update? Well, because we are rotating, rotating our rocket inside of Update. And every time we finish update, we want to reset the angles. And we are recently these angles using the late update every single frame, this keeps our rocket from going crazy. And how are we recent thing? Well, we're using the local util angles. These are the way Unity measures angles in its engine. So we go to the transform, we take the angles and we create a new vector three. And inside that vector three, we set the rotation around x 0. We said the rotation around y to 0. And we said, well actually, we're not setting the rotation, we're setting the angle. So that's very crucial to understand. I'm saying rotation because it's easier to get, but we're setting the angle on x to 0, the angle online to 0. And then we are keeping what ever the local rural angle angle was already on. These are the same as it is. Okay. So I hope that all of that makes sense for me. Move on. I actually thought I should show you what the freeze rotation is. So it controls whether physics will change the rotation of the object. If freeze rotation is enabled, the rotation is not modified by the physics simulations. So that means if we, for example, get, let me show you, so I should have showed you before, but anyways, if you can try it out. So if our rocket falls like this and we leave it there, okay, the rocket will no longer voltage on its own because of the a residual rotation that was present on our rocket, if that makes sense. Okay, so a lot of new concepts, but the main idea is that when we click on plates should run exactly in the plane that we wanted. So it should no longer be affected. Okay, comeback rocket. So it no longer should be affected when it hits an obstacle. And as you can see, it's no longer wacky. It's no longer crazy, but it's still a bit, Nope, it's still a bit weird. So let's so let's try and do one more thing. We have one more trick up our sleeves. If we go to the rock chip, we go to the rigid body. We go to the constraints here, we have a way to freeze our rotations. So let's go ahead and freeze the rotation around the rotation around the x and the rotation around the y. And we'll freeze to position around the set because we don't want our rocket going in this direction. We want to keep it on this plane right here. So reset deposition. Keep, make sure that you freeze rotation around x, y, and freeze deposition around that. Apply all of that and this trick should fix every single problem that we have an rotations. Let's see. And I think I'm trying all my, my best in order to make something go wrong, but it's not. We have fixed. We have finally fixed, whereas the rocket we have finally fixed our problem. And now our rockets movement is perfect. And now it's time for your no, actually in this video, you are free from challenges. Enjoy your freedom, and I'll see you in the next video. 20. Designers Inspector: Welcome back, my fellow game developers. In this video, we are going to turn from normal game creators into game designers. And we are doing that by creating serialized fields who scary. And here we have the main thrust. As you can see, we are now able to change the main thrust from the inspector on the script and the rotation thrust from the inspector on the script. So we can change it on the fly while, while we are playing our game. So let's say we don't like the 2 thousand. We want to make it 300 thousand. Now we click on play and our rocket is never coming back unless we stop the game. Ok, so let's not waste any more time and let's get started. Welcome back my fellow game developers. Before we start, we need to what is it? Commit everything of that we did in the previous video, I forgot to do that. Tsunami. Let's commit everything. Hope you didn't forget, that would make me really proud. And we shall call this the fixed, fixed, fixed. A couple of movement of bugs. So comment that. And now we're ready to start our video. So what are we going to do? Well, we want to have the ability to change the rotation speed at will. And going back to the script every time can be really cumbersome. So as you can see, I've showed you a couple of challenges of fixing the rotation, fixing the main thrust. And every time we need to go back to our code, go to the top of our code, change the rotation right here. And it's very hard and very cumbersome. And not only is it hard and very time-consuming and not efficient, it's also bad game design. Why is that? Well, because you, for example, let's say you are creating a big giant game. So for example, you're making assassins, agreed? Okay, maybe you don't know the game, but imagine a big game that has a lot of things going on in it. So from running speed to jumping speed to building different weapons and so on and so forth. And you are a programmer and you get to a point where, you know, you don't have that feel for the game. You know how to create all of these things, but you don't know how you want to make them feel or you don't. Or for example, let's say you and three others are working on different things and you don't know how their mechanics are working compared to yours. Well, that is the part of the designer, designer of the game. Okay. Comes in, he has no idea how to code. He has no idea if he opens up the code, he's a startled, he doesn't understand what's going on. What is float, what our methods is, doesn't have a clue what's happening. What he'd knows, know is how to make a game feel really good. And he knows how to change things right here in the unity. So we need to find a way to give the designer access to our variables. And the way we do that. Actually through two ways. One of them you already know, and that is making our, For example here public. So when we make this main thrust public, we go back into Unity. And we can see on the script that we can immediately start changing the main thrust, but this is very bad coding habits. Let me tell you why. If we have this public and we're working on some big project, we can actually change the main thrust from different scripts, and that's not what we want. What we want is we want to keep this variable, which is the main thrust inside of our script, which is the rocket ship. But we also want it to be, we want to be able to change it and our inspector, and there is something that gives us exactly that. And that is something called the serialized field. So here I've created a small table just to understand how serialized field and public and private differentiate. So private, if you have a private variable, it's available it's available from other classes? No. Is it visible in the inspector? No. Is it not visible in this specter? Yes, it is. So if it's public, it's available in other classes. It's visible in the Inspector, but it's not it's not not visible in the inspector. So, so basically we can see it in the inspector that lust is not good anyways and serialized field is not available or not available in other classes yet, it is visible in the inspector. So this is a very big plus. What this means is that the serialized field can be a, whenever we put a valuable, making it a serialized field, we can adjust it from the inspector yet other classes don't have access to it and they cannot ruin our variable. So let's go ahead and create a serialized field right here from the main thrust. And it's super easy. You open up these two brackets just like we do for arrays. And you type in inside serialized field, and that's it. So now we can go back into Unity. We can see that we have the, still the main thrust when we click on play. Look how cool this is. So let's say, for example, our main thrust, okay, it's like this. It's good, it's not bad. How about to increase it? How about we need to make it 10 thousand? Okay, so now our main thrust is much stronger. So let's wait for it to comeback. Where are you? Okay, it's gone forever. Let's try this again. So let's say it's too much. Let's make it, for example, 300. It's too much main thrust, we need to keep it down. So now it doesn't even move. So we increase it to 500 and it barely moves. Okay, so now I understand it needs 3 thousand, okay, so now our movement is good. So as you can see, this is where the designer works. He takes this game, he looks at the main thrust. He understands that the main thrust, thrust is the speed of our rockets. So he needs to tweak it a bit to make it work. He has no idea what the code looks like. Well, maybe he does, but he doesn't understand really how the code works. And before I go, I want to issue you a challenge to do the same for rotating. So make the rotation thrust a serialized field. Make sure it's feasible and the inspector and adjusted from the inspector in Unity directly. So it's very easy at say varies challenge. Pause the video right now and go to the challenge. Oh, okay, welcome back. So we go into our code and we immediately create a serialized field from the rotation thrust, we go back into Unity, and now we have rotation thrust right here. We can adjust very easily. So let's try that. Let's, for example, say that our rotation trust is not enough. We need to be 11000. Click on play a changes to 11000, and now our rotation is very fast, so, okay, it's not very good. We need to make it smaller, but you get the idea. That's, that's exactly what we want out of our, again. Before we go, I want to make one more small adjustment. So let's get out of here. That's make the 600. Let's save that. And one more thing I want to add to our rocket ship is a bit of drag because right now as you can see, but this drag does is whenever we move our rocket, ok. So it feels kind of gaming and has a couple of collision problems. But anyways, it feels kind of gaming. So we don't have proper movement. We, It still feels a bit weird and we will change that is actually by increasing the drag just a little bit. And let's make it for example, 0.05. and now let's see how that looks on our rocket. We can see that it actually adds a bit of drag to our rotation and really makes it much realistic. It's no longer like a blocky game, that rocket that simply goes around and flies to this point than to this point, it actually has drag. So as you can see, the movement is much better. So I hope you enjoyed this video and I'll see you in the next one. Hey Michael here from the future. Once again, I'm here to first of all put the drag to 0.05. and to apply it to our rocket. And finally, I'm here to commit all of my changes because I always forget to do that. And here we are going to name this, adding serialized fields. Okay, great, commit that. And now I'm, I really will see you in the next video. 21. SECTION 4: LEVEL DESIGN Using Tags On GameObjects: Welcome back, my fellow game developers. In this video, as you can see, we haven't changed everything that much. We only added a small sphere right here that has a name under few and it has a Tech. And we've also added a tag to the landing pad which is punished. And we've added a tag to the launching pad, which is friendly. So when we click on play and we hit the landing pad, we get I'm okay if we had the launching pad or the landing pad. Okay. So that's the Launchpad. This is the landing pad. When we had the landing pad, we get success. Ok, and the EBIT of collision, if we hit the terrain, we get dead. If we hit the obstacle right here, we get that. And if we hit this little sphere right here, we get fuel has been added. Very nice. So this is a very fun video. We are starting with the basics of creating levels. This is the first step and it's very exciting. So let's not waste any more time and let's get started. O k. So now we have a obstacle, we have our terrain, we have our landing pad and we have our launching pad. But as you can see, currently, we have no way of distinguishing between them when we collide. So right now the terrain is the same as the landing pad, as the launching pad. They are all basically the same to our rocket and we need to change them. Was that well, because we want to actually move through levels. So when we get, for example, to the landing pad, we want to go to the next level. If we collide with an obstacle, we want to get destroyed. If we fall on the terrain, we also want to get destroyed. Maybe we want to add a fuel mechanic later on, for example. So whenever we hit an obstacle or a cube or a game object that represents the fuel we want to add fuel to our rocket. So we need a way to distinguish between the different kinds of game objects in our world. And a very good way to do that is by using something called tags. So let's see what tags or if we click right here on launching pad or any other game object. And our hierarchy, we can see up here under the name that there is something called the tag. And right next to it, it says that this launching pad is on tact. Now what we can do is we can actually add a tag to it. So here are a couple of tags that we can add. Let's go to our landing pad. And this is the part that we are striving to get to at the end of our level. So let's see what should we take our landing pad. I think that finish is a really good tag for organic, but so we'll do that and we're going to apply that to all prefer. So now our landing pad, whereas it prefabs are landing pad, is now tagged as finished. So now we can, in our code, looks through the tag and check for the finished tag if we ever collide with the landing pad. Another thing we can do is we can actually not only assign a tag, we can actually also add a tax. Or if you click on Add Tag, we see that currently the tags, this is empty. We also have something called the sorting layers. And the layers and sorting layers are, we're not going to use sorting layers and layers and discourse, but sorting layers are a way to render things in front of each other. And these layers right here are similar tags, but they are used in a bit of a different way. For now, tags will be sufficient for us. So let's go ahead and create a new texts. So to create a new tag, we simply click on the plus right here. And we're going to call this tag the friendly tag. So what friendly tag is, is whenever we hit an obstacle or a game object that has a friendly tag on it, we are not going to have anything. We're simply going to continue on playing our game. So back on the launching pad, go to the tag and you can see right here that the tags that we've added is now part of the list of tags available. So we click on friendly and now our launching pad is very friendly. Okay, great. So next, what should we be doing? Well, we want a way to get the collision of our rocket. So whenever we collide with something, we want to get a reference to it so we need to understand, Okay, so we've collided with the launching pad, which is friendly. We collided with an obstacle which is deadly because whatever. And we need to base our code or create behavior based on the thing that we collided with. And there is a very helpful function in unity for that. And it's called the on collision enter. So let me show you. So on collision enter, if you read the description, we can see right here that OnCollisionEnter is called when this collider, or the collider that's used on the code. So in our example, if you use the OnCollisionEnter on our rocket, this collider or rigid body will be the one on the rocket, has begun touching another rigid body slash collider. So what this does is whenever we collide, so our rocket, let's go back in unity. If our rocket right here collides with this object, for example, the OnCollisionEnter as soon as we enter the collider. So our collider right here, if we look on the rocket, look at the body, we have the capsule collider right here. It's not very visible. So if we click on this one, we can see the green line right here. So this is the collider on our rockets body. And we also have a collider around the nose. And we actually have a collider around everything. So as you can see, the green line is the colliders edges. And we also have colliders on the legs. And we have colliders are around the cylinder of our rocket. And if we click on the obstacle right here, we can also see that we have this green line right here, which represents the collider. We also have one on our Green launching pad and we have one on the terrain. We also have one on the landing pad. So all of our game objects have colliders, and this ONE collide on collision enter triggers whenever our collider on the rocket body enters another or touches, or begins, has begun touching another collider. So how are we going to use that in our code? And let's go ahead and open up our scriptwriting York chipped and Visual Studio and create the on collision enter. And second now. Okay, great, so we'll put the OnCollisionEnter under update. And we're simply going to write on collision enter and it's going to finish it for us. So as you can see right here, this OnCollisionEnter takes in a parameter. And what this parameter is, is it actually represents the Other collider that we've collided with. So, and here, if our rocket ship collides with the, let's say this obstacle right here, the red one, the red obstacle, the collision will be the object that collided with. And we can use this collision to check for the text are available on it and see whether this collider is a friendly Collider or say fuel Collider, or it's a death collider. So first thing first, let's see if actually this on collision enter works. We are simply going to use the debug log and we're going to print just collided mate, just collide with mate. So we'll save that and back in Unity. Let's move our rocket back to its original position, whereas our rocket ship. So let's take it back right here. And let's play our game. So as soon as we collide, we've collided with the landing pad, we get an OnCollisionEnter. Let's remove the collapse so we can clearly see it. So we move. When we collide with an obstacle, we also get a collision. We just collide and mate. If we touch the terrain, we also get a collision. And when we touch the landing pad, I mean rBST landing pad, we also get a message in our console. Great, so this means that the on collision enter works. So now we need a way to check for the collisions or the collide, the thing that we've collided with, we need to check for its stack to see if it's working or not. So the way we do that is by actually using something called the collision dot game object dot tag. But before we do that, we need to talk about something called the switch case. So let me explain what switch statement or switch case is. So it's similar to if statements as in a way that it allows for conditional code execution. So let me show you the switch statement structure. Just like the if condition, we have something called the switch. And inside of here we have the case switch. So this is like the if statement with its condition. And based on that condition, we are going to execute. Some cope. So for example, let's say it's the first case. So we have a case of one. This could be a string and our case is going to be the tag. And if it, if it is the case one, we're going to execute some code and then we are going to break, break, meaning we're going to go out from our switch statement. But let's say the first case and it's not what we want. Let's say the first case was differently and we didn't collide with frankly, we collided with the finished tag. Well, then we have a second case, and that case is true. Well, we're going to execute some code and then we are going to break. But let's say it's neither the first case, neither the second case, neither the third case and it's some different collider somewhere. I'm not sure what it is. While there is an option for the default case. And this is just like the, just like in the if statements we have the else. This is very similar to the US. By using default, we execute the last quote that we have and we break out of it. Okay, great, so Let's go ahead and try to implement that in our OnCollisionEnter. And the case that we're going to have will be the collisions game object Tech. Let's go back into our code. Okay, so now that we know that this works, we no longer need the debug log log. And what we are going to do is we're going to create a switch statement. And inside of here, the case switch that we are going to have will be the collision. So it's the collision, the thing that we've collided with, which is here, the parameter that is sent. We're going to use dot. We're going to access the game object of the collision that we've lived with, and we're going to access the tag on it. Okay, great, so for now, everything seems to be very logical and smooth. So let's continue on. Next thing we're going to do is we're going to use the space. So in case we have a friendly rent Lee, and make sure that whenever you use string references, which is right here, we're using the case friendly of a tag that has the friendly on it. Make sure to go back and are 100% sure. Let's go to the landing, but not the launching pad. So it's frankly makes sure the Chu write it correctly. So it's r, e, and D. So it's exactly what it is or else this will not be working. Well. What do we want to do while we're simply going to print? Okay? Or I'm oh, okay, great. And under it we are going to be per raking. Okay, good. So now when we collide with a friendly, we should get, I'm okay. But let's also add another one, which is going to be the case for finish. And when we finish, we are going to be printing success with an exclamation mark and under it we're going to break also. So let's save that. Now we have a case for frontally and we have a case for the finishing. Let's go back into Unity and see if that works. Let's move our rocket up a bit so it doesn't collide immediately with the landing pad. And now we click on play. Now we can see that our console is completely blank. When we hit the landing pad, we should get or the launching pad we should get. I'm okay. And we do a very nice that's collapsed that so now we have, I am okay. And if we had the terrain, there is nothing because we didn't create a case for it. And now when we had the landing pad, we should get success. And we do and we get success whenever we hit the landing pad. Very nice. So now that you understand how Switch statements work and you know how to create tags, it's time for your challenge and your challenge is to finish the collision logic. Create a new tag for fuel, create a cube or a sphere or whatever you want. It just needs to be a game object that you can collide with and target with fuel. At the case for the fuel tag and our switch statement, and add a default case for our obstacle. So pause the video right now and go to the challenge. Okay, welcome back. So how did you get around with that? Let's go ahead and create a 3D game object right here. We're going to make a sphere and we're going to reset its position. So it's going to be here. We're going to put it up here next to our rockets, so it's not very far. And let's go ahead and add a small material to it. So materials, what should we add? Well, I think this one will do just fine for now, or that's the body material. So it's a white sphere. And with this white sphere, we are going to add a tag. And this tag is going to be called the few. So now we have a fuel tag and it doesn't add itself automatically. We need to go back to this fear and we'll need to tag it as few. So now we have a fuel tank that's added to a sphere in our world. And let's change these fears name too, because few, so few. Next thing we need to do is we need to go back into our code. And in here we're going to create a Case D, which is going to be the fuel. And make sure that you write fuel correctly. And in here we're going to print simply, fuel has been added. Volcanoes, and never forget the break at the end. Save all of that, go back into Unity. And let's click on play and see if that works. So on the console we get IM, okay, when we touch this fear, when we touch the sphere, are raving touching this fear. Okay, so we're not touching the sphere. Why is that? Is it in the same plane? Okay, it's not. Let's put our rocket on the zed equals 0 or fufu. No, not for, not 49 on the 0. Okay, great. Let's go back. If you had the same problem, make sure that your rocket is on the zed equals 0. So they are on the same plane as our rocket moves in the same plane. Now we need to touch this and we have the fuel has been added. Very nice. So we've created a brand new tag and used it and our switch case. Next thing, well, the last thing that we need to do is we need to add a default case. And this default case will be for our obstacle. So if we are not touching a fuel, if we're not touching a landing pad, and if we're not touching a launching pad, we should get destroyed. Very nice. So let's write default and we're simply going to print right here debt. So if we touch anything besides the break, so if we touch anything besides the friendly finish or fuel tag, we are going to be debt. Let's go back into Unity. So if we touch the terrain, that means we fall or we touch this obstacle right here, we are toast. So Patashnik, bad, I'm okay. But when we touch our obstacle book, we are that if we touched THE rain, we are also a debt. Very nice. So this is a very fun video and it's the introduction to our level design because after this, we are going to be creating many obstacles around which are rocket should be manipulated to get from the launching pad to the landing pad. And before we go, Of course we need to, I'm almost tearing you. We need to create a repo. So let's go ahead and do that. Oh, okay, so as you can see, we have a couple of onstage files that stage all of them. And we're going to call this adding tags to game objects. Hope, jackets, okay, great, commit all of that. And it's always fun to look back at masters and look how far we've come in our project. Ok, very nice. I hope you enjoyed this video and I'll see you in the next one. 22. Level Design 101: Welcome back, my fellow game developers. In this video, as you can see, we have a amazing space background right here and we have our rocket inside of a level. So when we play our game, we have to move through these obstacles to get to our landing pad. So now our player has a motivation to get to the other, okay, to get to the landing pad and he needs to make sure that he doesn't die along the way, just like I did right now. So let's not waste any more time and let's get started. Oh, okay, so level design and more importantly, game design, we, and our goal in this. Okay, so let's go back to C. So our goal in this video is to create our first level. But before we do that, I want to just take a moment and talk about the principles of game design. So I want to not only show you how to create levels and so on, I want to actually teach you how you can make your own, use your own creativity to make levels. And there are a couple of principles to follow. So laser, first of all, you need your core features. And what are these core features while they are the most important things in your game? So what are the most important things in our current game? So the most important thing, of course, is our rocket flying. So first thing first, whenever you start designing a game or thinking of a game, you need to make sure that your core features are the most important thing and they are the most polished aspect of your game. You need to make sure that you're flying mechanics, you're rotating mechanics. Rotation mechanics. You are thrusting, how the rocket fields well it flies, the drag on it, It's mass. Everything should be your core. Attention should be on those things. If you start creating levels and adding fuel and other things, and your core features, your core mechanics are bad, the game will not be good. There's no way you can make your game good. Then we have the second most important things, and these are the things around your core features. So this can be, for example, your rocket shape. That's one of the second-most important feature. It could be the level that you have. And you always need to remember that your second most important features, which are around the core features, should always be feeding into your core features. So they should be enhancing your core features, not the other way around. You never start designing levels and then make your rocket move butter? No, you need to make your rocket move the best way that you can possibly make it. And then you start creating things around, making your rocket look better, making your level look better, adding fun stuff. And then finally we have the third most important and those are the feature that's, let's call them For example, the UI. So maybe you want to add live. Lives to your rocket. You want to add the fuel mechanic, for example, is the third most important feed. These are things that also enhance your core features. They make your game more fun to play. But for example, let's say you have anything, any game. Again, we talk about the Let's talk about The Grand Theft Auto. So of course you've played The Grand Theft Auto. What the game be as good as, as if the driving mechanics wherein top-notch, if everything in the game was the same except for the driving. Driving was very bad in Grand Theft Auto. Do you think that the game would have that much praise and that good? Of course not. The city, the environment, the characters all feed into the core feature of the game, which is the driving mechanics. So thats how you need to be thinking whenever you are designing a day. So the next thing that you need to do whenever you want to design a game is to create a game sketch. So this game sketch is very rudimentary, but it gets the job done because it's a simple concept that we, okay, it's very bad, I admit, but this will actually helps us imagine how the game is going to look. So this right here, the red blocks that I have made professionally, of course, using the latest software and getting those are just shapes, google Slides. And these are actually our obstacles. And this is what the rocket should not be touching. So this is our rocket. It has a bit of fuel, and by the way, this, of course, is not up to scale, so the rocket of course doesn't fit right here. But anyways, we have V rocket, we have a launching pad, and we need to take this flying rocket without hitting any of the obstacles. And we need to get it to the landing pad to proceed to the next level. And here we have this block and it looks like it has a amature, but those black lines orbit, do they represent a movement of our block? So this is something that it's the second or maybe the third feature that we have. It's removing obstacles. Not only obstacles, they are moving obstacles and we'll be adding moving obstacles later on and our gain. So this is the super basic sketch. I recommend you create a sketch. It will really help you visualize how you want to be designing and creating your game. So the core features are flying. The second most important features, or the core features are the flying, rotating, and getting from point a to point B. The second most important features are the obstacles that we need to move around in a fun way. And the third most important feature will be maybe the moving obstacles, adding a bit of health, adding UI, adding particle effects that we'll be doing later on in our videos, and so on and so forth. So let's go back into Unity, and let's go ahead and create a lovey for ourselves. So first thing first we are going to put the launching pad. Let's put down the rocket just a little bit so it's in the middle. Let's reset its position. And we have it exactly. Let's reset to 0 also. So now we can move our rocket and launching pad. Right here. And our goal is to get to the landing pad, which should be right here. Let's delete this fuel for now. We'll use it maybe later on, maybe not who knows? Anyways, let's get back and let's see you. How are we going to create our level? I think it's going to be a super simple level. So let's increase in the x-direction, let's decrease in the y direction. Now, I already have something in mind. And you know what, let's keep this at one. And if we click ops, now when we hit, we choose the rotation. Let's rotate this a little bit. And actually, let's make the Zelda a bit smaller. So we rotate our obstacle right here. Let's put it under the rocket, and let's go ahead and increase the x again. So we have this sort of obstacle right here, and we'll move the launching pad, okay? Actually, I want to make it a bit shorter, smaller, so this is what it should be looking like. Okay, great. And the landing pad, let's see how this looks. Okay, so this is very rudimentary. This, this is the most basic thing that you can create and I'm just showing you what we are looking to do. Duplicate this again. If we had the R, we can actually scale it down faster. And we had E in order to access the rotation. So we rotate w to access the position. So we put this down. Okay, so please don't judge my level of design right now. I'm doing this very fast. So we have this sort of block that will not allow us to cheat. So we'll put this up here just a little bit. So okay, looks extremely bad. Okay, so again, duplicate, I'm duplicating these using the Control D. We add a rotation and we close off our level. So let's put this in here, okay, rotate this. And all of this is without rehearsal, and I'm doing it on the fly. I have a faint idea of what I want to do, but I'm not sure how I was going to make this. Ok. Sometimes you need to make sure that you duplicate this one again and move it down. And we'll rotate it again. So now we have something, is this a level? So we put this down. What else can we add? This, duplicate this one again. We'll rotate it and make it a safe way to put a safe place to put our landing pad like this. And let's go ahead and shrink it down a bit. So let's make it smaller. And voila, I think this is enough. Let's move this up a bit. Okay. So make sure that you are choosing the correct thing. Oh my god, this looks very bad. So. Move this up a bit. We move the landing pad to be on this horizontal plane. And how should we be putting it? Okay, so let's move this z to 0. So what aligns? And we'll move this up a bit and the rotation should be 0. So we move this down. Okay, so now we have this connected. We put the landing pad down a bit so it's Yep, it is exactly on it. And let's move this platform. A tear. So this is the wall. This will not allow us to cheat. This is just 40 declarations. So we'll keep it there for declarations apparently. And now we have a level, a very bad level, but it does create a fun way to play our game. Now what let's take this back that's increased the height. And let's put set to 0. And let's move a little bit here so we have a good look of our level. And let's hit the increased size and move it up a bit. Our world. So it looks kind of kind of good. Nope. But anyways, as you can see, we have this game moment, if you want to call it, which is fairly visible. So the game, the object is to get from point a to point B and without getting destroyed. Very nice. So the last thing we need to do if we go into the game objects, we can see that we barely see our rocket. We need to adjust our cameras so we choose an angle that we want. We choose the main camera game object and we align with the view. Now when we click on play, we have our console down here, but I'm okay. We move our rocket. So we move it and we need to get it to the landing pad to have this success. But we also get that, no worries, at least we got some kind of success. So our game is working. We have our first level. Very nice. I'm very excited. So now it's time for your challenge. And your challenge is going to be to create your own level. So find an interesting level design you want your player to experience. Mine was trying to move up or end horizontally to get to the landing pad. Use the obstacles to create a path through which the rocket has to move and make it a bit, just a little bit hot. So as you can see, I got pretty easily. But after all, I'm a very good space bound rocket ship 3D player. But anyways, make it just a little bit hard so the player finds it actually interesting. So pause the video right now and go create your own level. Welcome back everyone. So I hope you tried your best to create a fun level. Now, I already have my level right here. And I've thought of doing something to make our scene and our level much, much cooler. So. There is something called the Skybox. The Skybox is currently the blue sky that you can see with the sun right here and the grey down ground area on the traverse cold, we can actually change the Skybox. I want to create some kind of skybox that reflect the space. So we are in space, we are using a rocket, so we're definitely in space. To create a space background, let's simply go into the Unity Store. And up here you can actually search for the space skybox and use free assets, or you can actually buy some assets. Here we have a lot of options and my favorite one currently will be currently using is this galaxy box two. So we click on galaxy box two and we can see that it's a free acid. And you can actually add it to my assets right here. So click on Add to my assets and you will get this package right here on the Unity Store. Now when you go back to Unity and you can click on window, go to package manager. I've already got it right here. And in here. Let's maximize this a little bit so you can go and find the undermine assets. You can find the galaxy Skybox that should download it. And you simply need to click on the Import button right here and wait for them to import. So you have all these options right here. Simply click on Import and wait for the importing package to finish importing. I'll see you in just a bit when this loading finishes. Oh, ok, welcome back. So the importing has finished. If we go into the galaxy box two assets right here, now we have a new folder. We go into the resources and we go and to our skybox. So we have a lot of options. Now, there's, there's a very simple way to add sky boxes. We simply click on this box that we want and we drag it and to our world. Nice. So now when we play our game, we have a Skybox in our background. How cool is that we now actually feel like a real game that we've created. Very nice. Now, honestly, I'm not liking the Skybox a lot. Why? Well, because it's very dark. Let's try a different one. I had one that oh, this one. I like this one a lot or nice. So this one has a bit more bright. We can actually see where the nodes of our rocket is. Now the camera angle isn't that favorable? But anyways, we can see that we have a legit level that looks really nice as a background, as a designed, it's not that good. The obstacles are positioned very well. I think we need to, we need to make a bit of adjustment. But as a example, as a first level, it will do. So. I hope you enjoyed this video. I hope you did the challenge and had fun creating your level. And I'll see you in the next one. 23. Level Design Tuning: Welcome back, my favorite game developers. As you can see, I have completely went crazy with my level design. So now I have about ten rockets right here. And the goal is to get all of them through this little gap we're And to this landing platform. So let's see how that's going to work. By the way, they are all scaled down, so they move up and we move all of them to the other side. There's one still stuck there, and now they are all on the other side. So the goal of this video is just to show you that sometimes if you want to create new ideas, you don't actually need to add more code and more features and add-ons and whatever that sometimes may hurt you. So in this video, I'm going to give you a couple of tips on how to make your game more fun using what you already have. So I hope you'll enjoy it. That's not wasting more time and let's get started. Okay, so what I want to talk about in this video is that sometimes people think that whenever you try to make a game more fun, you need to add stuff to it. So people think that we maybe need to add more health. Maybe we need to add more platforms, maybe we need to add more obstacles. In this video, I want to show you just how sometimes only just tweaking a bit of what you already have in your game can make your game much better and much more fun. So before we do that, first of all, I want to address the lighting issue because first of all, I don't like this lighting. The backdrop of our obstacles are very dark. And to fix all of that, we go into the window, you can go into rendering. And here you have something called the lighting. So when you click on that, you can actually, if you, if you have the auto-generate, generate on, turn it off and then generate the lighting for this currency. So when you click on that, wait for the light to generate. And now we go out of lighting. You can see that our lighting is actually much, much better and you can tweak it from the directional light right here, we have something called the strength of the shadow and we have the intensity that we can increase or decrease. So UPS, I'll keep that at 0.8, which looks pretty nice for our current state. Okay, great, so what, what can we actually tweak in our game to make it more fun? So let me put this up a bit right here, and let me move this up just a little bit. So we have a bit of room. I already have a couple of things that I thought of that I wanted to share with you, just so you get a small idea of how these things might impact your game. So first thing first, we can actually go into our rocket ship. And here we have control over our main thrust and our rotation thrust. So what you can do, for example, if you have some kind of level where maybe you are on a very dense planet, you can, for example, decrease the main thrust to, let's say 800. So let's say the main thrust is now 800 and our player. Needs more thrust and much more precision if it actually flies in order to get to the second level, this can be really implemented correctly. A very nice feature to add. Another thing that you can change is maybe, let's put that back to 2 thousand. Maybe you are on a planet where there is no gravity. So the thrusting is very strong. So the thrust is, let's say 5 thousand. And now you're player needs to be very careful when adding thrust. So as you can see, it's very fast. You need to be careful. You need to adjust on the fly. And as you can see, we've just died. This adds a better element and we need to fix the collisions. This adds a much more fun element to our game and makes the our game more exciting without even adding anything. So you can play around with the main thrust and add a bit, remove a bit. And what's even more fun? Well, you're asking me, why not make it minus 10000? So now in order to fly your rocket, you need to be, oops. Okay, so to fly your rocket, you need to be upside down. And as you can see, a filter like this, we fly down faster. We need to be rotated up. And this is how we move now, our rocket. So let's say you create a level where everything is upside down and okay, this is kind of funny and it's really nice. You know, you can create diversity with so much in your game and keep your fan base or player engaged until the end. And another thing that you can play around with is the rotation thrust. So for example, you're on a planet that has very strong rotation wind or something. Let's say it's 2 thousand. So now when we wrote it, this is going to be crazy. So when you fly, you try to rotate and the rotation, okay, maybe this is too much, but you get the picture so it's very strong and our rocket can go out of control and glitch into some of the obstacles. Or you can, for example, make the rotation negative, which is also a very nice feature. So you get on a planet where everything is reversed. So in order to rotate to the right side, you need to press the d key. So I mean, okay, so if you want to rotate to the left side, you need to press the d key. In order to rotate to the right side, you need to press the OK. So OK. Nice. So we have to try to rotate our rocket. Ok. So nice. So as you can see, you can play around with things that may seem insignificant, but they really add flavor to your gain just by tweaking things that you have already implemented. A, another thing that you can make is you can actually go ahead and for example, scale your rocket in the x-direction. For example, you get on a planet where everything is scaled your rocket. Well, it's scanned of thin looking, but now when you click on play, you still have your rocket working completely fine. But now it's. Very thick, so we need to land a bigger rocket. Maybe you can even keep the same level, but now your rocket is much bigger and your player needs to make sure that he doesn't touch anything. You can even scale it. So let's put this back to one. You can scale it in the y direction. So now you have a very long rocket. Let's see how that, how that will look like. So now you have this very longer rocket that you need to take to the other side and it's very fun. You know, these things really can improve and add ideas to your game and really make it fun. So you can also, let's take this back to one, stop the craziness of it. You can, for example, also, which is a nice idea. Well, you can go into the prefab and add a second rocket. So let's put a second rocket right here, and let's reset its position. Put it next to our rocket, original rockets. So now we have two rocket ships. So when we click on play, we now control to rockets. And your goal is to get these two rockets to their place. So these, these are things that we can actually add to your game without going ahead and creating new code and doing some fancy stuff. It's all about creating moments in our game that are unique, that are special. Maybe you don't even need to be very maverick about it. Just add a small thing, a small detail here, small detail there. And it is very, can really add a lot of fun to your level and to your game. So now that you have a couple of ideas, I'm going to issue you a small challenge. And your challenge is going to be to create a fresh design for your love. So take the time to think of some kind of special rocket mechanic for your game. It can be anything you can add thrust, removed the thrust. Of course not remove completely the thrust. Maybe add more rotation, less rotation. Use the full power of your imagination. So put your query tivity caps on, Take the time. Don't worry, you don't need to create something and credibility. Amazing, but take the time and have fun. Enjoy yourself. See, feel yourself as an indie game developer that wants to create some kind of fun game. And of course, it's part of the challenge and it's to have fun. So pause the video right now and go do the challenge, and I'll see you with my own unique design. Oh, okay, welcome back everyone. So as you can see, I went completely crazy with the idea of adding multiple rockets. I really like it. I think it's going to be very funny. Honestly, I haven't even tested this out. I want dusted with you. And as you can see, the scale on every single rocket is 0.05. and we have ten rockets. And the goal of this level is to get as many rockets as you possibly can through this little gap right here and to get them to this platform. Now, I don't know how many will die, how many will live? I'm not sure. Just for now, we're having fun, we're enjoying ourselves. We are seeing, we are throwing things at the wall and seeing what sticks. So when we click on play that see what's going to happen. We have all of our rockets, Some of them are on top of each other. When we press the spacebar, all of them fly. We move num and we need to get as many as we possibly can across. So we still have one single rocket, and they are all on the other side. Now. We try to take them back and let's see what happens. Yes, some of them do, some of them are stuck somewhere. Let's try it again and nice. So as you can see, let's try to get the last one there. So as you can see, this really makes our level. We've basically created a level without adding any new features. We just used what we already have. Even the obstacles that are used were the same ones that I had from my previous level. So this was just an example. There are many, many things that you can do. So that's why I encourage you to take the time. Think of a couple of things. Have fun and enjoy being a game developer. So I hope you enjoyed the video and I'll see you next time. 24. Making A Second Level: Welcome back everyone to a brand new video. And as you can see, I've just stopped playing my brand new level that I've just created. So now if we go back, we have the loved one and we have a level two which is much cooler. So in the first level, our path was to simply go through this little gap. In level two, we have the sort of cave or dungeon or unnatural. I think it's a cave. It's a cave where you need to go over the first obstacle, so you fly, you need to get over the first obstacle books without dying, of course, then under the second one and then whoo, okay? Okay, very bad playing, very bad demonstration, but you get the point. We've created a second level and you will do the same thing. So that's not wasting more time and let's get started. Oh, okay, so creating a second level. Before we do that, let me first of all, create an empty game object, reset its position. And this empty game object is going to be our obstacles. And what this game object does, it simply or puts in or contains all the obstacles in our current scene. And this helps us have a more organized hierarchy. Second thing we wanna do is, as you've noticed in the previous videos, sometimes our rocket push, it, pushes through the colliders that we have on our obstacles. Now, this problem is not, cannot be fully avoided. There will always be collision problems, but we can do a little bit of tweaking in order to help that. So we go into our rigid body on the rocket. And here we have the collision detection and it's currently on the screen. We can change that and make it continuous, continuous dynamic. And basically how collisions in Unity work is that whenever we touch a collider with another collider, the physics engine and unity starts calculating, doing calculations and make, makes sure that we don't go through certain objects. And sometimes this, especially if we're moving very fast with our object, sometimes it doesn't have the enough time to calculate everything and we move through the object. This will help just a little bit, but it's not perfect. Anyways, let's save that. And now we're going to create a second level. So in order to create a second level, first thing we're going to do is we're going to rename the sample scene into level one. So now we have level one. Click on enter and make sure that you've saved everything in your sample scene. Then click on reload. And now we have a level one. So to create a second level, it's very easy, we're simply going to duplicate. So on level one, Control D, we have now a level two. And if we double-click on level two, you can see right here in the hierarchy that it is the level two, but it's exactly the same. And we're going to change that in just a little bit. But before we do, I want to issue you a challenge. And your challenge is going to be to create a second level. So think of a new wave for our rocket to move through the obstacle. So right now, my level is just the rocket trying to move as fast as it can and squeeze between these two gaps, our one gap, and get to the landing pad safely without touching the Obstacles. My second level, I think I'm going to make a sort of path for the rocket to move up over something than under something, then over something else. Those somethings will be, of course, obstacles. And I'm going to create some kind of path, some kind of movement for my rocket. And you should create also a way for a different way for our rocket to move through a level to add a bit of variety to the level. So think of a new way for our rocket to move to obstacles and use that idea to create a second level. So pause the video right now and go create a second level. Oh, OK, welcome back. So right now I'm going to create a second level in front of you. But as this may take a little bit of time, I'm going to speed up the video and then I will try to talk over it and just explain what I was thinking during the process and how my mind was working to create the second level. So see you in just a bit. Hey Michael here. Okay, so first thing I wanted to do is I wanted to change up my seem completely I didn't want anything on the top. I wanted to make something fresh and new. And first thing I did, I actually wanted to create a floor and remove the terrain from under. So it looks like he gave that we are inside a game. I tried to make the platform a little bit wider and increase the scale in every single direction that I could. Also, if you notice, tried to change the rotation so the platforms are the obstacles are facing us just a little bit, so it gives the illusion of being inside something. I also wanted to make the platform that we're sitting on to be sort of realistic, not floating in the middle of the air. And Let's see, I was just adjusting the main camera and position. Now what was time for the roof? And I tried to make it at a slight angle just to give that feeling of claustrophobia in our level and make the player feel as a feedstock and needs to manipulate and manipulate his rocket very carefully to not hit things. I've created the end wall and I'm probably going to shift it a little bit to make room for the obstacles, for the movement that they are going to make. Here I'm just adjusting things, looking at my level and just trying different things ways and moving angles, trying to add randomness to the cave so it doesn't look linear and things are the same. Just wanted to add different angles, different backgrounds, just to make everything look natural as much as possible, of course, using cubes. So now it was time to start making the movement possible. So I add these three cubes right here. I made them. And this is the third one. And now it's time to start adjusting the movement and adding a bit of difficulty. So I started doing the game a little bit and adjusting, turning. I noticed here that it's kind of hard to determine when the rocket is close to the last one because the last obstacle was facing the camera. So here I'm not sure how far or close ion, so I change the angle and I changed it a little bit again. Oh, okay, welcome back everyone. So I hope you enjoyed this video. I hope you created your own level. And let's play this level just a little bit to make sure that it's kind of fun. So here we have the over, so we go over the first obstacle. We need to keep our rocket well-balanced to go under the second one, and then we get to our landing pad and we have success. Very nice. So I hope you created your own level. I hope you enjoyed the video and I'll see you in the next one. 25. Prefabs In More Details: Okay, welcome back around to a brand new video. And in this video, I just wanted to make it really quick to explain how prefabs work before we move on to the later sections. Why is that? Well, because as we're creating our levels and adding more levels, maybe we will need to actually create different kinds of obstacles. So maybe you want to make obstacles that bounds, obstacle that don't bound, obstacles that are green, obstacles that are red, so on and so forth. So you need to understand how prefabs work. And we've covered prefabs just a little bit, but I wanted to make all or almost all the rules clear. So you already know what prefabs are, how they work. Now with our loved one. And I just wanted to show you a bit more detail on how these pre-fabs actually work. So let's move these two up here just a little bit to have room to create a couple of cubes and play around with them. So we're not actually going to make anything in this game. And in this video, we are simply going to explore prefabs just a little bit. If you have a significant knowledge and pre-fabs, you can skip this video of course, but if you are thirsty for some more knowledge, it's time to explore prefab. So we go into our Prefabs folder and as you saw right now, I've created a cube. Let's think of this cube as our prefab, and let's add this green material to it. So now we have a green cube. We go back into the prefab and we prefer this cube. So now we have a cube prefer, what's cool about this is that we can add another cube. So whenever we have a second cube, we can create a third cube. We can create a fourth cube. So now we have four green cubes that are from the same Prefab. Now what you've learned previously is that whenever we choose one of these prefabs and we scale the x or wait, scale the zealots or we scaled the zed. And if we go to the override right here and apply all, all of our cubes also get scaled to the same scale as the first one. And this is because they are all from the same prefab. So when we apply one, changes to one, all of the subsequent ones also changed. This is true also. Lets try to add this blue color. So now if we go here, we apply all of that. All of them also become a blue. But let's try something different. Let's see if we click on the first cube. And let's say we want to increase the Y right here. And let's say we take this cube and we decrease or no, let's keep the x and we decrease the scale on these Zed. So what do you think will happen when we try to override this one? Which ones will change? Will they all change? Well, when we click on apply, we can see that even though the scale on the zed axis of this prefab right here or this cube is different than this one, only the y scale changes. And now if we try to apply, for example, the changes on this cube right here, which is on the z, that start to apply them and see what happens. And now all of them change to the same exact scale that this one had. Now these are very important things to understand about prefabs because sometimes, let's say you've created a level from a lot of meetups and you see that you want to change one of, one of those prefabs. Let's say you want to add a Rigid Body, increase the scale, change the color, whatever, at some bounciness, you need to make sure that you know which ones change and which ones don't. So as a rule, you need to make sure that, for example, let's increase the x Now, all of these will have an increased on them, but if this one has a different scale. So now when we apply this one, exchange on this one, but that doesn't solve some times. Properties that are unique to want prefab stay unique to that prefab and they don't change. A better example of this. So for example, let's say we add red to this one and green to this one. And let's say we overwrite the green one now, the ones that were already ok, so the scale changed. But the lesson here is that the one that was red and had a unique aspect to it, state that keep kept that aspect or property NOT aspect kept that property unique to itself. So just wanted to make this thing clear about prefab. So whenever you are creating your levels and you have things that you change and you sometimes think that you've changed them and everything should be working fine. But no, sometimes there are a couple of things that you need to make sure our changed properly. So I think this is all that we need to talk about in Prefabs. This is all I just wanted to make things clear to avoid any confusion in the future. So now that you have a better understanding of pre-fabs, you are ready to go out into the wild, wild west of creating games and creating levels. And I hope you enjoyed this video. I'll see you in the next. Let me just tell you about a challenge. So your challenge is to play around with prefabs and make sure you fully understand how they work. So to avoid any surprising future, pause the video right now, play around with prefabs. Try different things. Try changing the scale and the material or scale without the material or the position or the rotation. Or there are many things that you can tweak, play around and see how prefers actually work. Ok, so pause the video right now and go to this little challenge. 26. Level Loading & Scene Management: Welcome back, my fellow game developers. In this video, we've added a game controller with a game controller script attached to it. Now what this game controller does is it actually allows us to move through levels. So now when we move our rocket, that's tried to when this the first time. So we move our rocket through the little gap. We land on the landing pad and we are at level two. But what happens if we touch an obstacle by mistake? Well, okay, so here it doesn't work. What happens when we touch an obstacle? Well, we reset our game. Very nice. So this is a very fun video. It needs a bit of concentration and a bit of trust. So let's not waste any more time and gets started. Oh, okay. So let's get started with loading our levels and resetting our levels. Before we go on, I just wanted to make sure that all of you are actually committing your work. I've been committing it in the background because sometimes I forget, sometimes I didn't realize that I have to film it, but I want you to always commit work whenever you do something significant. But that established, let's start loading our levels. So first thing first, we need to make sure that we have the launching pad and the landing path set up correctly. Next thing we're going to do is we need to make sure that we have the finish on the landing pad and we have the friendly on the launchpad. And of course, all of our obstacles are at the default ON tagged options are tax, I mean, okay, great. Next thing we're going to do is we're going to create a game controller. Now, some of you might be thinking, why not simply use descriptive we already have, which is rocket in order to move through levels. And if you're not thinking that, I'll just tell you why you should not be thinking that. Because using the same, using one script to do all of the work for us is bad coding habits. You need to diversify your workings. So we'll create a game controller which will control everything that's happening in our game. And one of those things is actually moving us through scenes. So we keep the rocket ship doing its rocket ship things. And we'll create a game controller that will do the game controlling things. Okay, great. So now with that established, let's go back into Unity and we're going to create an empty game object, which is going to be called the gain controller. Now it doesn't matter where you put it. I'd like to put it right here in the reset position. And we're going to add a script to it. And this script is going to be called the gain controller. And make sure that it's written correctly and you don't want to change it later on. So controller New Script, create and wait for it to compile. And it should be shown up in the assets anytime now. So now we have the game controller, put it inside of the script SIR folder. So we have a scripts folder. Okay, great, so now we are ready to start coding. Oh, OK, so let's see what we are going to do in here. First thing first, what you need to understand about what we're going to do is that while moving through levels, we are actually moving through our scenes. So we have our levels are scenes. So in order to be able to manipulate scenes and US scenes, we need to add a namespace that will allow us to do that. And that namespace is going to be using unit is Engine dot seen management. So make sure that you have it here on the top. And this will allow us to access scenes, move through scenes and load scenes and so on and so forth, everything related to things. Next thing we'll do is we'll simply remove the start and update if we need them. Electron will, of course add them later on. Okay, great. So now what we're going to do, well, we're going to create two methods in here. One will be the reset game, and this will be used whenever we hit an obstacle and we need to reset. So we go back to the first level, that means we die. And we're going to create another method which is going to be the next level. And next level will be activated every time we get to the landing path and let's get started. First of all, we're going to create a public, make sure that they are public. Void, reset. Oops, reset game. And this is going to be the method that resets our game. And another method which is going to be also public void. And it's going to be called the next, next level. So now we have two methods. One is the reset name and the second one is next level. Now inside of here we are going to use the namespace that we've added in order to manipulate our sins. But before we do that, we need to go into Unity and make sure that our scenes are inside of the built structure. What do I mean by that? Let's go into the files right here. Underneath you can see that we have something called the build settings. Now, when we enter the build settings, here is where we actually build our game. And as you can see, there is an option up here, which is the scenes in built. Now it's empty. We need to add seems to it. So let's do that. We go into the scenes folder right here that we have, and we simply drag the level one and we drag the level two. Now, two things to keep in mind while we do this. First of all, level one is over level two. So we start with the level one and then we go to level 2. Second thing that we need to keep in mind is right here, you can see that each level or each scene has an index to it. So level one is at index 0 and level two is at index one. And this is very important to keep in mind because later on, when we want to load scenes and reset scenes, we are going to be using these indexes right here. Okay, great. So now that you have the scenes, save all of that. And let's go out. And before we go, just let's talk about the cool stuff that we have here. So you can build this on different platforms. If you have the model setup, you can build it on the WebGL, on Android, on Xbox One, on PS4, on iOS, which is. Of course you should know it's the Apple one. And on the PS4 soon hopefully there will be a PS five and the Xbox series x or is that what's called well, the big fringe, Xbox. Okay, great. Anyways, let's go back into our script right here, and let's make sure we save that. And how are we actually going to load AC? Well, now that we have the namespace of sin management, we actually have access to someone called the scene manager. And in here we are going to use the scene manager to load a certain scene. Now if we open this up, we can see that it, oops, it requires a scene built index, so we need to give it the index of the scene that we are looking to load. And because when, when resetting the game, we are going back to the first level. And as we remember, as we made sure to keep in mind that the index of the level one as 0. So now we have loading scene 0. Great, now this should be working, but let's make sure where are we going to call this method inside of rocket ship. Let's see where we actually need to reset our game. We need to reset it here when we die. So let's delete the few case for now because we will not be using it. And let's try to access this reset method right here in the game controller from our rocket ship script. So first thing we need to do is we need to get a reference to our game controller. So let's go up here and let's create a variable that is the game controller. And we're going to call this game controller. No need to call up my game controller because it's not ours. Now, the problem here is that if we write get component, something will be, was something will go wrong. Why is that? Well, because when we write get component, we are looking for a component that is attached to the object that has our rocket ship script. But game controller is outside of the realm of our rocket ship it somewhere in our scene. So how do we get it? Well, we can create a public variable right here and add you can controller to it and the game controller to every single one of the rockets that we have in each level. Or we can do something much smarter and use something called the find objects of type. So we write game controller, we write equals, and we have a method that is find object not objects, find object of type. And this, what this method does is that it actually goes out there and finds a game object that has a game controller script on it. So now whenever we start our gain, our rocket ship immediately goes and finds the gain controller that is present in the scene. Great. So now that we have a reference, we simply need to go down into the on collision. And in here, instead of the, instead of printing that, we are going to simply access the game controller and access the reset game method. So let's save that. And let's go back into Unity and see if any of that work. So we click on play, we move our rocket, we hit an obstacle, and we reset our game immediately. It's not very nice because we don't want it to be reset immediately bought. It works. So let's try this again. Let's try to when the level actually, ok. We didn't. Let's try it again. This is the last time I try. So we squeezed through, but when we land on our landing pad and nothing happens, and nothing happens because it's part of your challenge. So we want to load level two when B collide with the landing pad. So it's kind of obvious that you need to check it in the OnCollisionEnter in the switch case. Then you need to make sure that level two is inside your build index. And finally, you will need to use the next level method to load level two for now. Why do I say for now? Because later on we'll be using next level to load all next levels. But for now we'll just use it to load level two. So pause the video right now and go to the challenge. Now, let's go into our scripts and inside of the game controller. And the next level we are going to call our scene manager and low scene manager, we want to load a scene. But now the scene that we want to load is at index one. It's still level two at index one. And now we go back to the rocket ship. And under the finish, because our landing pad has the finished tag on it, we're going to remove the print and actually we're going to call our game controller. Hi game controller. We want to load the next level. Thank you. So make sure we save that. Go back into Unity. Let's click on play and let's try it out. So we need to, when this level before we move on, so it goes through the gap, we land on our pet and we go to the next level. Very nice. So I'm not sure why I'm so excited, but it's always nice whenever you start actually controlling your game and not double-clicking on level two and then going to the second level. So now we have full control of our game and tags actually have a use for us. Everything is coming together to create an incredible gang. So I hope you enjoyed the video. Don't forget to complete your work and I'll see you in the next. 27. Using Coroutines: Welcome back everyone to a brand new video. And in this video we are going to be using something called a Colton. And what that will do it with us or what will help us with is it actually whenever we hit a wall, we wait for two seconds and then we reset our game. And if you've noticed, another thing is that our rocket goes them so we can no longer control 20, we hit a wall. This is not part of the Colton, but it's something that we're going to learn. Another thing that we've added is that whenever we fly, we go through the gap and we land on the landing pad, we can no longer move and we wait for two seconds until we go to level two. So this is a very fun video. It's full of information and useful things to use and our future game development. So let's not waste any more time and let's gets o k. So first thing before we start, as always, we have a first thing before we start. As you can see, some of you may have saw that whenever we are inside of level two and we ups and we hit a wall or we get to the landing pad, nothing happens and we actually get an arrow. And this arrow tells us that there is object reference instance. Whoops, sorry. So there is no reference. And that is because we don't have a gain controller on level two. So some of you may have fixed this problem. So please let me stop. Some of you might have fixed this problem. In level one. We simply go to the Prefabs and we prefer up our game controller. And now we go to the level two. So it's safe level one and we go into the level two. And in here we are simply going to add the game controller into our world. So now when we click on play, our rocket flies, it hits a wall and it resets. And this also should be working on the landing pad. But what happens is that when we get the landing pad, we are reset back to the level two. So great. What are we going to do? Well, the problem is as you saw, that levels load very fast. There's nothing wrong with that, but we want to have a more authentic field or gain. So we want to delay a bit the level loading, and we are going to delays things using something called coroutines now call routines or things or methods that are very used in Unity. They are indispensable in game development. So let's talk about coroutines and using our laser. First thing, it's a method that can suspend, suspend the execution of instruction, instructions until certain conditions are met. The suspensions are known as healed. And in our example, we'll be suspending the time until we reset or load the next level. So these methods are only used when me want to suspend execution. So we want to delay our level load a couple of seconds before we actually start loading it. So let's go ahead and create a coroutine. Nice. First thing. Let's go into the game controller. And inside of here we are going to create another method, which is going to be the load first level. So the way we create a co-routine, as we'll create it as a private, it doesn't matter. We don't need to make it private. But because we're only using it inside of the game controller, private is a good way to use it. So private eye enumerator, so coroutines have the type of ion numerator. Don't worry about what that means. That only means that we need to return a yield. You'll see what that means in just a bit. So load, first level, Great, so we've created our first eye enumerator or cold. Here we have a small problem and error. And what it tells us that there is no returned. We don't have no return. To. The way we return is we are going to yield, just like we've said in this slides, we yield return. And here we're going to add the condition that will need to wait for an Intel or the condition that we'll wait until it's met and then we can start the execution of whatever we want. So it's going to be the new. And we're going to wait four seconds. Side of the wait four seconds. We tell it how long you want to wait and it's going to be two for two seconds. Very nice. And after we wait for these two seconds, we are actually going to call our senior manager and told him that we want to load the scene 0 because we're recent ing to the first sin. And finally, inside of reset game, we are going to start the coal team and we are going to load the first level cake rate. I'll go over this code again, but first thing first, let's test it out. So we start our game. If we hit the obstacle and after two seconds we are at the level one so-called routines are not a myth. They actually work. And let's talk about this courting one more time before to start your challenge because you're going to be creating your own. So in here, inside of recent game, sorry, inside of reset game, we are going to start the coating. So the reset gate is called from the rocket ship. Reset game is called, we start a co-routine, which is the load force level. And this is our first load first level. It's a coroutine and coroutines our enumerators. No need to worry ourselves with the scary word. Just know that I enumerators are coroutines and they require a return. And that return will be in the form of a yield return. And here, after the return, we add the condition that we want to be met until we start loading everything under our yield return. So our condition will be to wait four seconds. And here we give it how long we want or how many seconds. And these, and the amount is two F, which means two seconds. After two seconds finish, we are going to simply be loading our first scene. So. I hope you understand coroutines a bit. Coatings are very scary. I know the feeling. I also learned covert means for the first time. They are mind-boggling. He would have no idea how it's working. I tried my best to make it as simple as possible. But the best way to learn core routines is to actually go out there and try to create some. So this is where the challenge comes in. So finish this second CoRoT, create a coating for the load next level. Use yield to wait a certain number of seconds and start the coltan from next level. This is a scary challenge. Some of you will just wait for me to finish the challenge and do it with me. But I want you, the ones that are scared too with yourselves, to pause the video right now and actually go and try it. You can make mistakes, you can fail, it's perfectly fine. The only problem is, or the only downside is when you don't even try. Pause the video right now and go do the challenge. Okay, welcome back. Hope you actually go. Got up there and Troy. So let's create a private I enumerator. And it's going to be called load next level level. And in here we are going to yield return new and wait four seconds. And under it, when we finish these two seconds, we are going to call the scene manager, hazing manager. Whoops, nope, no. What's that? We're want to load excuse me, load scene and it's going to be the scene one. And the next level will remove this one and we'll start a coroutine which is going to be the load next level. Save all of that mixture that you've saved script. And let's go back into Unity. Let's go into level one. And here we click on play. We move our rocket and we need to get through the gap. Hopefully we do. We get to the landing pad and after two seconds we get to level two. Very nice. But the only problem is still before we go. When we hit, we can still move our rocket and fly around, which is very bad. And I don't want that. What we want is that whenever we hit the obstacle, wait for two seconds, but while we're waiting, we want our rocket to be unable to move. The way we do that is very simple. That's going to rock chip, go to the top. And let's create a variable that is a Boolean. So we'll create a Boolean that is, is alive and we're going to make it true. So this, this, what this is. It's a variable that is Boolean that is true whenever we start our game, it's true. But when we die, we are going to turn it in to false. So inside of the default right here, whenever we hit a wall. We're going to make it, is alive equals to false. So now when we are alive, as alive as true, when we hit default means we die, is alive is false. And we want to stop the rocket movement. And here we are going to create a if statement. And if it's alive, we are going to move our rocket. So whenever r is alive is false or rocket does not have access to the movement and we cannot move. So when we hit, the default is alive as false. And here is a live as false salty condition. Never used CU Another thing we want to do is we want to stop the collisions whenever we had, whenever we actually stop being alive, we want to stop any collision because it can lead to some bugs. So the way we do that, we're going to use the same alive. But instead of simply adding the is alive and then adding all these switch statement inside of the, inside of the condition, we are going to add this exclamation mark, which means it Gates. And if is alive. And this means if it's alive as false, we're going to enter into this condition right here, and we are simply going to return. So what does return mean? Well, it means that we go out from the collision. Let me explain return just a little bit more. So in him is alive. Whenever it's false, we negate it. That means this whole condition right here is true. That means the if statement goes into the, whatever is written inside of it, and inside of it, we have the return. So what return does is it actually goes out. So we stop anything that any code that is below the if statement or under this return. And we go out from our own collision enter and from any method that we are currently in. Last thing we need to do is whenever we hit the Finish, we want to stop our rocket from moving. And the way we do that is by accessing the rigid body and turning on the Is Kinematic. And what this does is it allows us to rotate and stops us from moving. So let's see how all of that works. This was a long mouthful, but it's fairly easy and I just thought of creating the code before we start demonstrating everything. But anyways, now we fly. When we hit, we can no longer move. Okay, great. So again, we can no longer move yet. They're still sound in the background. That's OK. And now if we get to the we didn't plant. Okay. Let's try that again. So we move through our oh, please don't. Okay. So we get to the landing pad. Okay. Now we can move, we can only rotate and we are on level two, but we've hit the ground and we're back at level one. So this was a very long video. I hope you enjoyed it. It was full of new information. And so if you're still scared of proteins, go and try and implement them in various ways. They are not the scary when you get used to them. They are fairly easy. So I hope you enjoyed the video and I'll see you in the next one. Don't forget to complete your work. 28. Level Debug Keys: Welcome back, my fellow game developers. In this video, we are going to be adding debug keys. And debug keys will enable us to move through our levels and feel our games much more easily. So now we can see that we have our rocket. You already know what happens if we hit a wall, but we have a secret key that we can press, which is the CQI. And when we press it, we no longer feel anything so we can collide with the obstacles. We can move down, up and use our level freely. And what else do we have? Well now, we can also press the LP and after two seconds we immediately go to the next level. So the boxes are like cheat codes and games. They help us move through levels and test our game much more easily. So let's not waste any more time and let's get started. Oh, okay. So let's get started. The first thing, let me explain why we want to create these two input keys, which will help us, first of all, stopped the rocket from colliding with obstacles or stop the collisions. And what I mean by collisions as it stops the death sequence. And the I'm going to the next level sequence and the second button will enable us to move from level to level immediately. Now, why do we need these two? Well, because we need a way to fund, to be able to test your game without actually going through each and every level and getting to the end. So now it's fairly easy. We have two levels, so we own, we only need to go from the level one to level two. But imagine if you have 100 levels and you need to win all of them in order to go through them. And it's not about simply double-clicking on level two and going to it, you want to see how the game fields, the progression is, and how it is during the gameplay of your game. So adding debug keys is very important. And the way we're going to add this debug keys is by simply using the input system that we already know. And that's why I'm going to issue you the challenge right now. So your challenge is to create, to debug keys. So use the input system we learned in game controller to, first of all, stopped the rocket from colliding. The collisions should always be there. So your rocket should be able to collide with obstacles, but it shouldn't have any impact on the game. That means u, as we did with the variable, is alive. We also need to do a similar tactic in order to stop our rocket from colliding. And then you'll need to create a second input system to load the next level. And you need to do all of that inside of the update and game controller. So this is a bit of a hard challenge, but I'm sure that you're up to the task. Pause the video right now and go do the each. Alan. Kay, welcome back. So first thing we'll need to do is we need to create the update inside of our game controller. And inside of update, we are going to create a method that is going to be called respond to. The buck, because we are creating debug keys. So respond to debug and let's go ahead and quick, quickly generate this method under our update. So what should we be doing here? Well, first of all, we need to add an if condition to check for the input. So M input. And we're going to use the get key down, get key down. And we're going to use the key code of the L button. And what this button does, it will immediately take us to the next level, simple as that. So inside of the respond to debug, if we click on the button l, we will go to the next level. Would we trigger the method that is next level, which will trigger the co-routine, and we move on to the next level. Now to create collisions, to create a way to stop collisions is a little bit more tricky. First thing we'll need to do is we need to create a public variable right here, which is going to be the public boolean. And it's going to be called Collision Enabled, and it's going to be equal to true, so true. And what we want to do is we want to have this collision enabled variable to change based on the click of one of our buttons on the keyboard, we're going to be using the C key. So let's add it right here. So if condition that's simply copy this right here to save us a little bit of time, remove the next level. And instead of l, we are going to use the C button. And what this C button will do is it will actually take the collision enabled and it will negate it. So this is what I mean by AND gates. So, but this line right here does, is it takes the collision enabled and it turns it around to the other option in the Boolean. So for example, let's say we have Collision Enabled equals true. If it's true, whenever we press the CQI, it becomes false. So it takes whatever the Collision Enabled was, it negates it using the exclamation mark and then it puts it back in the collision enabled. This means it turns it to the other side. So true becomes false. False becomes true. So we can turn on and off the collision unable at our well using the CQI. Now, next thing we need to do is we need to access this collision enabled inside of our rocket and based on the the condition, so if it, if it's true or false, we are going to stop our rocket from colliding. And it's fairly simple. And here inside of the collision enter, we have already a condition that stops any collision which is, is alive. So we're going to add another condition to it. And it's going to be a 4x. And the way we add an ore is by simply adding these two straight lines right here. And inside of it we are going to write. If the game controller, as we, oops, nope, I'm Andy, game controller variable that we already have access to. Dot Collision Enabled, then we will return. So what have we done right here? Let me explain this condition inside of you. So we already have Collision Enabled inside of our game controller right here. So if the Collision Enabled is true, then this one, this entire line here would be false and we will not return from our OnCollisionEnter and we will check for collisions. But if the collision dot enabled is false, then this variable right here and this entire line right here is true. And then the if condition works and we return. That means we go out from our on collision enter. So now with that firmly established, let's talk about these two straight lines right here. And this is the operator for the or. So this checks. Is this condition true? Yes or no? Or is this condition true? So one of these two must be true in order to enter the i