Unity 2D Game Development: Beginner Unity and C# in Unity 2020. 3 | Kaupenjoe (Nico) | Skillshare
Search

Playback Speed


1.0x


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

Unity 2D Game Development: Beginner Unity and C# in Unity 2020. 3

teacher avatar Kaupenjoe (Nico), CS Student, Nerd and Educator

Watch this class and thousands more

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

Watch this class and thousands more

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

Lessons in This Class

    • 1.

      Introduction to my Unity Class

      1:29

    • 2.

      Unity Installation

      8:27

    • 3.

      (C#) Creating our First Unity Project

      3:55

    • 4.

      (C#) Introduction to C# Datatypes

      12:43

    • 5.

      (C#) C# Syntax Explained

      6:51

    • 6.

      (C#) Integers and Arithmetic Operators

      11:40

    • 7.

      (C#) C# Math Methods

      9:31

    • 8.

      (C#) Assignment Operators

      4:49

    • 9.

      (C#) Booleans and Comparison Operators

      3:39

    • 10.

      (C#) Booleans and Logical Operators

      4:55

    • 11.

      (C#) C# Strings and String Methods

      15:00

    • 12.

      (C#) Casting Variables

      8:22

    • 13.

      (C#) Conditional Statements (If and Else)

      8:18

    • 14.

      (C#) Ternary Operator

      4:55

    • 15.

      (C#) Switch Statement

      4:49

    • 16.

      (C#) While Loop

      8:08

    • 17.

      (C#) For Loop

      4:20

    • 18.

      (C#) Break and Continue Keywords

      4:02

    • 19.

      (C#) C# Arrays

      11:32

    • 20.

      (C#) Multidimensional Arrays in C#

      5:49

    • 21.

      (C#) C# Lists

      8:01

    • 22.

      (C#) C# Dictionaries

      5:32

    • 23.

      (C#) Foreach Loop

      3:00

    • 24.

      (C#) Namespaces

      9:09

    • 25.

      (C#) C# Methods

      9:33

    • 26.

      (C#) Method Overloading

      6:10

    • 27.

      (C#) Classes and Objects

      12:26

    • 28.

      (C#) Class Members

      4:49

    • 29.

      (C#) Static Members

      7:26

    • 30.

      (C#) Access Modifiers

      10:24

    • 31.

      (C#) C# Properties

      9:08

    • 32.

      (C#) Inheritance

      9:55

    • 33.

      (C#) Polymorphism

      4:49

    • 34.

      (C#) Abstract Classes and Methods in C#

      8:04

    • 35.

      (C#) Virtual Methods

      3:45

    • 36.

      (C#) C# Interface

      7:15

    • 37.

      (C#) Enums

      4:12

    • 38.

      (C#) Exceptions & Try and Catch Statement

      7:28

    • 39.

      (C#) Basics of Generics in C#

      5:18

    • 40.

      (C#) Basics of LINQ in C#

      5:58

    • 41.

      (C#) Events and Delegates

      8:02

    • 42.

      (C#) File I/O

      6:46

    • 43.

      (C#) C# Conventions

      8:19

    • 44.

      (Unity Basics) Unity Layout and Editor Explained

      18:03

    • 45.

      (Unity Basics) Unity Folder Structure

      4:42

    • 46.

      (Unity Basics) Scripts and The Inspector

      8:52

    • 47.

      (Unity Basics) Kenny Assets & The Asset Store for our Games

      3:30

    • 48.

      (Unity Basics) Scenes & Build Settings

      7:31

    • 49.

      (Unity Basics) MonoBehavior in Unity

      12:54

    • 50.

      (Unity Basics) Short Maths: Vectors

      3:39

    • 51.

      (Unity Basics) Transforms and Vectors

      15:15

    • 52.

      (Unity Basics) GameObjects in Unity

      12:18

    • 53.

      (Unity Basics) Input Methods in Unity

      7:15

    • 54.

      (Unity Basics) Creating a Very Simple Movement Script

      12:27

    • 55.

      (Unity Basics) Mouse Input

      10:49

    • 56.

      (Unity Basics) The (Main) Camera

      8:22

    • 57.

      (Unity Basics) GetComponent in Unity

      14:07

    • 58.

      (Unity Basics) Prefabs & Spawning new Objects

      11:00

    • 59.

      (Unity Basics) Textures and Sprites

      10:11

    • 60.

      (Unity Basics) Sprite Editor

      5:42

    • 61.

      (Unity Basics) The Sprite Renderer

      10:06

    • 62.

      (Unity Basics) 2D Collider

      14:47

    • 63.

      (Unity Basics) Rigidbody2D Basics

      11:14

    • 64.

      (Unity Basics) Basic Unity UI Text

      7:08

    • 65.

      (Unity Basics) Basic Unity Debugging Tools

      6:57

    • 66.

      (Cheese Clicker) The Idea of "Cheese Clicker"

      3:24

    • 67.

      (Cheese Clicker) Creating a Cheese to Click

      17:58

    • 68.

      (Cheese Clicker) Creating Buildings to Build

      32:32

    • 69.

      (Cheese Clicker) Making a Basic UI for Building Buildings

      44:52

    • 70.

      (Cheese Clicker) Creating Upgrades

      32:27

    • 71.

      (Unity UI) Adding a Canvas

      15:20

    • 72.

      (Unity UI) Panels and Text

      9:23

    • 73.

      (Unity UI) TextMashPro for Better Text

      8:24

    • 74.

      (Unity UI) Adding Images to our UI

      5:15

    • 75.

      (Unity UI) Clicking Buttons can be Fun

      9:41

    • 76.

      (Unity UI) Toggles and Sliders

      8:15

    • 77.

      (Unity UI) Layout in Unity

      12:23

    • 78.

      (Unity UI) Scrollbars and Masks

      8:16

    • 79.

      (Unity UI) Dropdown and Input Fields

      12:05

    • 80.

      (Unity UI) Adding Layout Groups to our Cheese Clicker

      4:52

    • 81.

      (Unity Intermediate) Adding an Audio Source

      9:25

    • 82.

      (Unity Intermediate) Adding Particles

      8:42

    • 83.

      (Unity Intermediate) Project Settings

      9:17

    • 84.

      (Unity Intermediate) Adding Tags to GameObjects

      6:52

    • 85.

      (Unity Intermediate) 2D Raycasting in Unity

      11:35

    • 86.

      (Unity Intermediate) Preparing the Scene for Saving Data

      46:48

    • 87.

      (Unity Intermediate) Saving Data with PlayerPrefs

      9:49

    • 88.

      (Unity Intermediate) Saving (Custom) Data with JSON Files

      14:33

    • 89.

      (Unity Intermediate) Using TileSets

      16:36

    • 90.

      (Unity Intermediate) Animation Basics

      23:24

    • 91.

      (Unity Intermediate) Scriptable Objects

      13:23

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels

Community Generated

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

746

Students

--

Projects

About This Class

Have you always wanted to create your own games, but didn't know where to start? This is exactly the class you need then! 

In this Complete Beginner Unity 2D Game Development Class, you're gonna learn the basics of the C# Programming language as well as Game Development with Unity 2020.3. No experience is needed for this course to learn the ins and outs of making games with Unity.

This Class is accessible to complete beginners. Even if you have never programmed in your life. Basic knowledge of Unity and Game Development would be advantageous but isn't necessary. As part of this class, you will also make fully playable 2D Games from start to finish, which you can remodel, modify or update as you wish and use as a Unity playground.

First, you will learn C#, then we'll go through basic concepts of Unity Game Development and then look at intermediate concepts as well as the Unity UI System.

The Entire Source Code will be made available so you can follow along with everything I do in the lectures.

If you have any questions or suggestions, also feel free to contact me here. I'm happy to help you learn to make games with Unity.

Meet Your Teacher

Teacher Profile Image

Kaupenjoe (Nico)

CS Student, Nerd and Educator

Teacher

I am Nico - also known as Kaupenjoe - I have a Master's Degree in Computer Science and teach Game Development through many different classes. Mid-2020, when I became a bit disillusioned with my job, I set my sights to something different. Multiple people have previously told me I was good at teaching things.

With some of my prior YouTube Video making knowledge I was able to make my first courses. The Minecraft Courses in particular made a huge impact on students and myself and allowed me to teach full-time with courses and other supplementary methods.

I hope you will also join me and allow me to help you learn Programming, Modding or Game Development. As a hobby, side-hustle or as a promising career, it is an amazing and fulfilling field and I'm so happy to have y... See full profile

Level: All Levels

Class Ratings

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

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

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

Transcripts

1. Introduction to my Unity Class: Hello, I'm Nico caught me on muscle student for computer science and all odd nerd for everything game development related. For nearly eight years, I've been programming in Unity for both recreational and professional reasons. The amazing power of the Unity engine gives you for free still baffles me to this day. In this complete unity and C-Sharp class, you will learn all the skills you need to make awesome games in Unity or from the very basic to more advanced topics. First, you'll be thoroughly introduced to the C-sharp programming language. These fundamentals will help you understand unity in all its beauty. And so even absolute beginners to programming are very welcome in this class. After learning the fundamentals of C Sharp, we'll move on to the basic concepts of unity, such as the editor, how scripts work, textures and sprites and more. As soon as the basics are done, you're going to create your own first gait, She's clicker. This project is inspired by him, Cookie Clicker. And we'll use all of the C-sharp fundamentals as well as all of the basic concepts that you will have learned up until that point. And then we'll continue with more intermediate topics such as an in-depth section on the USU I-System, as well as recasting, saving and having persistent data, as well as using tile sets, amongst other things. All that and more awaits you in this complete class on Unity game development. So what are you waiting for enrolling in this class now? And let us be the first step of the awesome journey to create amazing Unity games. The power is in your hands. I will see you in the first lesson. 2. Unity Installation: All right, welcome to this lecture where we go through how to download Unity and install it. So this URL is available as a resource so they can very easily get access to it. It's simply stored at unity.com slash download. And then make sure that you are, that you meet all of those criteria here. And you could simply say, Yes, I meet all those criteria. This is basically if you're simply a single person and you're not doing this in any sort of company or something like that, then you can use the Unity personal license here and yeah, and just download Unity Hub. So there's going to be a program that is going to be useful for all sorts of things. I'm going to quickly put this inside of this folder here. So this is simply an EXE, you can just start it. And then you might have to do that. It has admin access and then you will be greeted by the terms of service. You will simply accept those and then say wherever you want to install this. Now I have personally already installed it. You will simply click Install and then everything will work on from there. After you've installed it, it will probably prompt you to basically sign in if you already have a Unity account, that's great. If you don't, then you can simply make one on the Unity website and then log in with that after you've logged in, something like this should appear. Now your projects will probably be empty, but that is totally normal. But the first thing we need to do is install a specific instance of unity. So in our case, as you can see, I have 20 1946, I have 2020 to 0. This is a beta version. And then I have the 2023 0 version, which is basically the one that we are going to be working with mostly. Now if you go to this Add button, then a new pop-up will open and you can see that you can either get some recommended releases. So there are actually four new foreign versions have been released since the 2020 point three-pointers 0. And then there are also other official versions as well as pre releases. Now in our case, we actually wanted the 2020 0.3 version, whatever the number is after that usually means that there are just some bug fixes and some minor changes. So let's click Next year. And then if you don't have it installed on your own. So if you don't have Visual Studio, I highly recommend that you add this to your installation as well as a module. Because I'll be using Visual Studio and there might be some in congruencies. If you use a another development environment, basically documentation you absolutely have to have. And then you could also in theory have some different language packs here as you can see, and all of the platforms don't really interest us. Maybe if you are basically on a Mac or Linux, then I would of course say that you should definitely take that as well, so that you can actually build your game onto your own machine. Otherwise, that would be not so smart. Hour, however, I do believe that unity, the hub actually detects on what type of system you are and should install that automatically. But yeah, so I definitely think that you should definitely have this Visual Studio here. I already have this installed, so I don't need it, but I highly recommended. And then you simply click Done. Now as you can see, this is downloading now and then also installing. This is going to take awhile depending on your internet connection as well as your speed of your computer. After the installation has finished, we can go back to projects. And now we'll go actually going to create our own first huge project here. So you're gonna go to New. And usually I go to this drop-down menu so that you can choose which which version of Unity you would like to select. Let's select the newest version here. And then it's going to create a new window here that says Create a new version with this particular version. Because this is a 2D course, we basically only wanted to D, selected as a template here. We can select a location, I'm fine with that location. And then the name of the project. In this case, we're just going to use the installation example in our case for you, because after this we're immediately going to start into the C sharp introduction. Maybe that would be a better name for you. So maybe named the project C sharp introduction for you. I'm going to stick with installation example, then click Create, then Unity Hub will close and a unity will open. You might have to say yes to the actual Windows Defender wanting to use the firewall. We're just going to say yes, of course, because that's ok. and then in just a little while after it's importing some stuff and even downloading a few more things, then it will open for us depending on how good your PC is. This might take a little longer or shorter, and there we have it. Now the first thing that I will do is I will change the layout to my personal layout, which I use. I have saved this under KJ layout. And if I select this, then this is the layout that we are going to be using in during this course. Now I've actually given you this as a layout here, cotton general layout, W LTE. This is the file available as a resource as well. And then you can basically import it by going to kJ, then seeing Load layout from file and selecting this file. And then you should have exactly the same layout as well. If you would like to. You don't need to necessarily have that. It's just that this is the layout that I'm I've grown used to. Yeah. One more thing that you will need to check before you can continue is you should go to the Edit and then go to Preferences. And this will open a preference window here. And then inside of external tools, make sure that you have the correct script editor here selected. So for us, this for you, this will probably be Visual Studio Community 2019. I Visual Studio 2019 itself. So just so you know that you have to select this. Otherwise, you will use the default script editor, which is what? It will look a little bit different than what you will be seeing with me. But that would be it for this one. This is the installation done. Then when you are continuing with this course, you basically have on some of those are some of the sections. You have two options. So you can either get the complete package for something or an empty package. So this basically means that you can either get everything done or you start with basically nothing and build it up while I'm doing it. So to import this, you can go to Assets, import package, custom package. Then it will open a particular folder here. And we're just going to basically go to our folder where I have this in. And as you can see, there are some of those packages, all of those are available as a resource. So for example, what we want is the C-sharp complete. So let's open this. And then as you can see, everything in here is already done for you so that you simply need to say Import. And then it's going to import all of those classes and all of those scenes. And then you can basically start lecture 10 datatypes. There it is. And then if I were to start this, then what you can see is it immediately works with, well, it's going to reload and then as you can see, it works and everything is fine. So that would be basically it's, that's very important. So you have to choose whether or not you want the complete version or if you want the empty version of this. And yeah, that would basically be it for the installation. That would be everything that you really need in order for you to start the journey for programming in Unity. Yeah, I hope you found this useful and installation was successful. If any questions remain, of course, feel free to ask and I'll be sure to respond. And yeah. 3. (C#) Creating our First Unity Project: All right, welcome to this lecture. And this is just a quick addition here. So you know what you have to do. Because next lecture we're immediately going to start into this C-sharp introduction. And basically, I just wanted to show you one more time creating a new project and then basically importing the actual package that I have provided here. That was the lecture before. That was the complete and the empty package. They are Unity Package Files. And yeah, basically when you have Unity Hub open, you simply click on this little arrow and then choose the newest version. And when you click that, a new window will open here. Create a new project with Unity 2020 three, and then whatever the current version might be, ME sure to select the 2D template here. And then I would suggests something like C sharp introduction as a project name or something like that. Of course, you will also have to specify your location. Where do you want this to be created? Let's just say I'm happy with this. And like I said, C-Sharp introduction that makes the most sense. And then it creates the new project. So you actually do have to create a new project. Overall, I would say that probably for each section. So C-sharp then comes the basic concepts. And then we get to basically building our first game, the cheeks clicker, unit, DUI and so on. So for each of these sections, I would advise you to make a new project for that, then you will always be able to import whatever the actual contents of that are. For the C sharp introduction, you have the ability to choose between the following two. So if I just get them over here, so there's the C-sharp. As you can see, the complete unity package and the empty unity package. They both come with a predefined, so folders and scenes are already laid out and done. The Empty simply are basically empty scripts. And the complete ones are the complete scripts that are already that we're basically doing in the C sharp introduction. So whatever you feel like is better for you to learn C-sharp. You can either get everything done already or have this empty, same with all of the other sections. They are. You can either get the complete packages they are or basically create the entire project as we go along with the lectures. So let's just see, once again, usually the layout here should be different. If you look back into the unity insulation, they are, is number one a resource or number 2, I tell you that we'll change the layout to this. And this is also the layout that we are going to be using during the entire course here. And you can go to Assets, import packages or import package, custom package. And then it will leave you basically open this file dialog. And then you can choose either the complete package or the empty package. Like I said, the MD package will contain everything as well. However, the scripts are going to be empty except possibly for the first two because that's, that's the most basic stuff I want to explain a few things they are. And in the complete one, everything will be inside of it. So the import itself will look the same for both the complete and the empty one. However, in the complete are filled, which we can basically check just for the sake of argument here. So let's go to scripts, for example, and let's just click on anything here. And then as you can see, this is already filled in, sometimes with a few comments as well so that you can also check that. But yeah, from here on out, we're going to immediately start with the lecture one, datatypes. I hope you'll have fun with the course and that you'll learn something new. And I will see you in the first lecture. 4. (C#) Introduction to C# Datatypes: All right, Welcome to the C-sharp introduction here for the unity course. And in this first lecture we're going to take a look at a data types. So first things first, make sure that you have the Lecture 1 datatypes open here. And then just simply go to scripts and double-click on datatypes and then the datatype script will open. Now, there's a few things I want to say first, the first thing is that we're going to ignore most of what's up here. We're just going to ignore that for now. We're going to get to that later down the line. And I'm going to explain that in detail. But right now, we need to start with a little bit of other foundation first. So let's just say that we need all of this to have the program run. Let's just say like that and then we're going to be fine. And then everything else up there, we're just going to ignore. And we're going to look in, into this start here, so we see the start. And then we have this curly bracket and everything that's written inside of here. This is what we're going to look at. So in code, in C Sharp for example. And also, I think like basically any other programming language, we always go from top to bottom. So each of those lines, luckily there are numbered here as well. Each of those lines are executed in serial. So basically, first, line 10 is executed and then line 11 and then line 12 and so on and so forth. There's a few things where you can, for example, group together a few lines and then have them executed. But right now, we're just going to think of it as we're going to go through from top to bottom. And everything has happened in cereal, right? And now datatypes. So what? The first question is, what are data types? Datatypes are basically a way of storing information and there is different types of information. So in C-Sharp, we have truth or Boolean values. We have numbers. Those can be integers or floating point numbers. And we also have basically text. These are either characters or multiple characters, characters next to each other, which would be called strings. Now, let's start with the truth or Boolean values. A few things for the basic syntax as well. So if we want to create a new variable, then what we have is we write the type that we want. In this case, this is a Boolean value. So we write bool and then we write the name of the variable, and then we end every line with a semicolon. This is what would be called a declaration. We're going to look at that again in the next lecture, a little bit more, the syntax of it all. But right now, this is the idea. So we have now created a variable, as you can see, local variable of type bool, which is called, is grounded. And then we can assign this variable with this equal operator a value. In this case we say equals true. So in this case, after line 12 is grounded is equal to true. So this is the assignment. And you can, for example, imagine this is why a cold it is grounded. The variable is grounded might be something that keeps track of when you have like a 2D platformer where Mario, for example, runs back and forth and as soon as Mario jumps is grounded would be set to false because now he's in the air. And then as soon as he touches the ground again is grounded would be true. So this is something where you could, for example, make it so that you can't jump infinitely high because you need to be on the ground to be able to jump. That's just like a sort of a real example that you can use in a game. And then we have the Unity specific output here, just so that we can see what the variable actually entails. We're going to look at the output at the end when I'm through with the explanation here. And then this would be the truth and Boolean values useful for basically deciding whether or not something is true or false. Because that's the possible values in there are either true or false. And that's it. Then let's look at the integer. So integers are whole numbers. In this case, we are, we at make a variable that is called points of type integer and we immediately assign it a 50. So in this case, declaration and assignment together in one line would be called initialization. And that immediately just sets the points variable 250. And then we also have a long. A long simply has a higher limit. So we can store bigger numbers in there. And I've actually like have this here just for reference. So the max value of a normal integer is 2 billion, and then the max value of a long is five quintillion, I believe. But in the end, it is so big that it's rarely used. And I've also, in, especially in games, usually the integer maximum is enough. And yeah, lungs are there. If you ever need them, then you can do this and have it basically be nine quintillion. And you should be fine At that point, I do believe. Right? And then floating point numbers are basically numbers with a decimal point. However, they are saved with a in scientific notation. So scientific notation are things like ten. Let's do like 3.5 times ten to the four, for example, this is scientific notation and this is how the floating point numbers are saved. And there are two types of floating point numbers there are interesting here. One is a float and one is a double. And the difference between those two is basically the precision of numbers it can save. So a floating point numbers can save up to eight points of precision. So we can have eight numbers in here. So either before or after the decimal point, and it would still be accurate. And the double can do up to 16 numbers. So up to 16 numbers before and after the decimal point. So, but to get it right, so if we have something like Ro, something crazy like this. Then you would count 123, and then you would count here 456 and so on. And if that is 16, then or is it, if it's bigger than 16, then it would not. It would round up or down. It would round. So that's important to know. If you need like precision. It's best to use integers if you don't need decimal points. Yeah, those are floating point numbers. We're going to see how those work as well in future lectures. But those are also can be very important. And then let's go to the characters and the spring. So characters, there is a char, variable type, a data type, and a string. A char is simply a single letter and you write it with these single quotes here. And a string is a is multiple characters next to each other. And you write that with these double-quotes. Yeah. And the idea simply is that like I said, the letter is a single letter. Now this can be an a, it could in theory be a number, but then it is not the number itself too, but it is the textual representation of two. And then also, for example, a special characters like a I'm Space-bar or an underscore or something like that, would also be characters in this case. And then a string is simply like I said, a multiple characters next to each other. And yet, one thing I also wanted to mention, C-sharp has something called implicit types. So what we've seen before is that we've always designated the type, the data type that it was. So char a string, a double, and so on. However, we can also just write var, so VAR, and then the name of the variable and then put it like just assign it to something and then it's just going to know, okay, this is an integer now. And as you can see, if I hover over it, integer total points. And here we have string player to name. So this works as well. Personally, I don't use this very often or wherever because I I don't get anything out of this. Some people use this when you have maybe long datatype names because in the future we can, for example, make our own datatypes. That sometimes helps. Usually I found that it's better to really be specific, or in our case, explicit, right? So this is an implicit type and then this would be explicit typecast. We type it explicitly. Hey, this is a string, this is a character that is a float. So yeah, but you can of course use this. And you might see it in code that other people have written. So that's always important to know things, even if you don't tend to use them or if you don't want to use them. But it has everything to do with style and nothing to do with whether or not it's better or worse in terms of performance or something like that. The var keyword changes nothing. Whether or not I write var or a string in there. After everything is compiled on all, that, doesn't matter. It it changes nothing. It is only for readability sake. And that's also one of the things that is important. The code must be readable for people. And it will very easily actually, you can write code that works. But it also needs to be readable for someone who has never seen the code ever before. And that's really hard, right? So let's see what happens when we actually run this. So what we would expect this, the first thing to be put out is grounded, true. And then the points should be 50 by nine, quadrillion or continuing them. And then we have a damaged 3.5, big damage, a 100, then the letter a NICU as player 1, James player two, and then the total points would be 100. This is sort of what we would expect here to be put out, right? Once again, make sure that you have lecture one open. And then we can just hit the play button here. And as we can see, there we go. So if we look down here, we can actually scroll a bit and then is grounded is true. Then we have points 59, quintillion, 3.5 damage. We also have big damage, a 100, and then character, a character, a player one is NICU Player 2's James, and then point spawn a 100. One thing to note is here that the 100, actually the decimal point gets cut off. In this case, because it doesn't actually contain any useful information because it was 0 anyway. So it didn't really matter if we have 0.01, for example. And then we let it sit for a bit and then play again. Then we're going to see that it actually does this. Also important to note, these are commas in my case, this is just because of the localization, because my machine runs the German localization so that commas or no decimal points get converted to two commas and commas for the 1000 separators are going to get converted into dots or, you know. Yeah. So that's just a important to know. Just don't be confused about that one. That's all fine. Yeah. And that was basically it for the introduction to the datatypes. And like I said, just a rough overview. In the future lectures, we're going to really make use of those different types, what they can do. And we're going to manipulate them. We're going to, for example, the numbers we're going to math with them, right? So we're going to calculate stuff. So that's all to come. And I hope you found it useful. If there are any questions. Of course, always feel free to ask and I'll be sure to respond. And yeah. 5. (C#) C# Syntax Explained: All right, welcome back to the C-sharp introduction for the unity course. And in this lecture we're going to take a look at the C Sharp syntax. So let's just open the script here, the syntax script. And let's just go through and see what we can see. So first of all, if we have two slashes here, this is a comment, as it says. And then we can also have multi-line comments. If we do a slash and then star, and then basically do another star and a backslash or slash. And then each time we basically hit Enter, we create a new line, new line weight, or we can comment. So this would be multi-line comments. It sometimes can be important to explain pieces of code. Or maybe we have some to-do and then we can just write something like to do and then just add more stuff. That's actually kind of, sometimes it can be important. For Commons. We're not going to get into the sort of ideological argument whether or not commons are good or bad. I'm just here to tell you that there are comments, basically, right? We've already seen the declaration where we simply put in the type of variables, the datatype into the name of the variable. And then the assignment is simply assigning a value to that variable. Here we actually put output a string, enter the I variable. We've already seen this in the last lecture. Now, this is simply a way that we can combine basically a variable in this case, as well as a string and then prints out both of those. Debug dot log. Right now, we don't need to get into the specifics. What does that mean? Well, it simply means that we output something to the console inside of Unity. But very important, this is specific to unity. And yeah, so if you are only using C-sharp, this would not work. You would need to use something else. This is why this is a C sharp introduction for unity. If we want to access variables and methods of objects, then we can do this. Now, variables, we know that variables are write this like this is a variable, integer. I write that's a variable we had the Boolean is grounded, that was a variable right? Now, what are methods and objects? We're gonna go into that as well a little bit later in a different lecture. But right now, we can just think of this as an object basically being something where we can store variables and methods. And a method is simply multiple lines of code condensed into like one expression. Think of it like this. So for example, in this case, when we have, we want the length of the string S, right? We can do S dot length. In this case, the length is a variable because it's just, it's just written without the parentheses at the back. And as you can see, S dot normalized in this case has parentheses here. And the parentheses denote that this is a method call. So that's the difference there and we access things inside of an object with the dot operator. So if I write S and then a dot, then as you can see, there's a whole bunch of stuff that I can access urine and do. And we're going to look at that in more detail in future lectures. In the beginning. It's a little hard because if you don't have any programming language, And, you know, we need to start somewhere. And in the beginning I'm referring more and more to future lectures, which as we go along won't happen as much. It's just, it's just that right now we're trying to basically bootstrap up from the basics and then continue along, right? So that is the idea that we can access some things inside of our variables. For example, interestingly enough, so we have the AI here, which we can of course do the same thing with the eyes. So if we do I dot and as you can see, there are also some things that we can do, in this case, less than we could do with the string. Because the integer just hasn't, doesn't have that much functionality to it. That's how you can think of this, right? And then there's also one other thing. The curly brackets are basically can define code blocks. These are also called scopes. So this would be a different scope. And the idea being that inside of this, so we have declared I up here in the scope of the start method in this case. And this is a new scope. And now because this scope right is inside of the scope of that came before it, where I was declared in. We can access it. Now if we declare x in here, we can put it out totally fine. But then if we look at this, right? So if we can do this, and if we do this, and as you can see, x is actually marked here as an arrow. And it says the name x does not exist in the current context because we declared inside of this scope. And after we're out of the scope, so at the end of this curly bracket, it doesn't exist anymore. And so this is why sometimes this can be useful. You can just basically define it. Define a new scope by simply putting the curly brackets. And these are also used if we define methods later down the line. And then it's going to get an even more clearer. But we can also just put in scopes like this. And then, for example, we can just collapse them as well. Could be useful sometimes for code management, just to make it a bit more tidy or something like that. But yeah, yeah, That is basically like a rough overview of the syntax here. Having looked again at the declaration and assignment, that's sort of important than the output here. Very important that it's specific to unity. And yeah, let's, we can actually also look at the output just for the heck of it. Once again, make sure that you are at syntax. Let's just play. And it's going to output the one length of the string is 11. And then we have a 0. That was the x inside of the different scope, right? Yeah, and that was it for the syntax. Next lecture, we're actually going to do something. We're going to look at the integer and the arithmetic operators. So we're going to start actually using some of the variables and some of the data types that we've learned about. And yeah, that was it. And if there are any questions, of course, always feel free to ask and I'll be sure to respond. And yeah. 6. (C#) Integers and Arithmetic Operators: All right, welcome back to the C sharp introduction for the unity course. And in this lecture we're going to take a look at integers and arithmetic operators. So let's just open the integers script here. And let's zoom in a little bit. And very important that you do everything that you're going to do inside of this start here. So instead of this scope, and yeah, let's just start. So let's define two integers. We're going to call the first 1 first and maybe the second 1 second. That would work. So the first one right now, so the variable with the name first now has 100 written in it, and second has 200 written in it. Now what we can do is we can do math. Now. First of all, don't worry about it. We're only going to do, let's say the simple math things right now. And yeah, so the first thing we're gonna do is addition. So we're just going to add those together. So let's just say integer sum is equal to first plus second. And that would be of course 300. You can also just debug dot log this out. Addition. Note that's definitely not it. It's called some Diego and then we have it. So if we take a look at this, so let's just think about this. We have declared a variable called sum, and then we immediately assigned it first plus second. So this plus, as you can see, this is the, this is an operator with two integers. If I can actually hover over it, there you go. So in left and right, and it just adds those two together. That's all it does. It adds 100, in this case, first and then second, 200. And this is going to result in a 300. And just so you know, to double-check, let's just see Let's just run this as you can see 300. Also make sure that you are on lecture three integers. Very important. But yeah, it does work. And I would have been surprised if all of a sudden this didn't work. I was also very interesting. So if we can, of course do this with, for example, first plus, you know, we can do plus Arno like 500. And then plus, plus seconds, something like that. You know, this also would work. We can basically put in the variables and different integers as well. So like 500-year, we can also then, for example, say, Well let's put in another 200 there, something like that, that also works. And then if we can just copy this Debug lock, this is sometimes I do this very quickly. This is why I mentioned it right now. So what I do is I basically mark this right. So I make sure that this is selected. Then I'll press Control C. And then I put, I go here to the end of the line and I press control V. And then it just, then it's just going to basically paste it into the next line. So you're probably going to see me do that in future lectures like quite a bit. It's just, you know, when you're, when you're let's say programming for a while, then sort of those things sometimes get automated. So I just wanted to mention this. I'm probably going to mention it throughout some of the future lectures as well. I just wanted to say that this is how you can do this. You know, marking something, making sure that it's selected Control C, Control V, and then it's going to be done. And I save with Control S. Or you can also go up here to the safe ones. And then it's also going to save to the, to the loo. What does that floppy disk write? The save icon. And let's see what comes out there. It should be 1005, if I'm correct, I believe, yes. Yes. Okay. That's good. My my math skills are still fine. Even though there may be a little bit roster, but yeah, that also works. And that's sort of kinda cool what we can do in addition, but I mean that's just the addition. Let's look at subtraction. That's going to be the next big thing. So what is that? So let's just say integer Sub is a first minus second. What could that be? Well, this would be negative 100. That's interesting, is it 100 minus 200 is negative 100 because the integers can also be negative numbers. That's, there's nothing saying that that doesn't work. So let's do sub and let's just print that out as well. And then let's just see if that actually works. If that's negative 100 and indeed it is negative 100. So that's kind of an important thing to note that integers in this case can also be negative. There are also integers that can't be negative. However, I have intentionally skipped those cars. They are usually not required in basically like 98% of political stances. So we'll just skip over them for now. If there are ever needed, you can always ask a question and I'll be sure to give you some more information. Now let's get into something that is also interesting, which is the multiplication. So let's say into mole is equal to 4 times first, this would be 400. And that just works because why not? Let's print that out. And let's print mole out here. This should just work. So four times 100 should be 400. Seems legit. Let's print this out and see if that also works. And of course it does totally fine. So as you can see, the multiplication operator is this star here. That's, yeah. And the plus and minus should be self-explanatory. I believe that this is also sort of standard star. And then if we go one more to division or to divide, then we can say the div is equal to second, divided first. This would be two because we're dividing 200 by 100. And we can also print that one out or debugged on login with the div, right. And yeah, that's, so this is a one slash in this case, two slashes being a comment, one slash being the division. And like always with a normal math rules, basically, plus or minus the order of operations doesn't matter, right? So second plus first is the same as first plus second times. Some multiplication also doesn't matter. Subtraction division, it actually matters what way, What's comes first and what comes second. But I think that that's I think that was like basic high school math. That should be figured out. Right. And then we have a2. There you go. So that actually works as well. And there is one more thing which you've probably going to be like, what does another one though? Those were the four that I know, yes, but there is also one that is called the modulus or the remainder. Now, you have probably, if you're maybe like Arno, like ninth grade, maybe tenth grade, you've maybe seen this before. This is the idea is that if you divide something by something else, in this case, it was perfectly even. So it worked fine. But it could also be that if you divide 13 by 213 divided by two, that's not, that's not gonna work, right? So that's gonna be, uh, it's not going to fit perfectly. And so we will have a remainder of one in this case. So let's just see an example of this. So remainder, remainder equals 24, let's say, and then the remainder operator, the modulus operator is the percentage sign 2 and this would be 0. So let's just actually put this in here as well. So this is going to be, right, this is going to be 0 because 2 fits evenly into 24. So if we divide 24 by two, as you can see, 0 remainder here. However, if we, for example, go to this and say divided by or modulo 5, then this is not going to be 0 anymore. Let's just do this. It is four because the closest number that we get to by dividing by 5 is 20, right? So four times five is 20. And then for 24, four numbers are basically remaining. So the four here remains. I wanna do this with a 23 just quickly because 4 times 5 could be maybe a confusing. There's going to be three, so we get to 20 and then five doesn't fit into three. So three is the remainder. That's the idea there. It is actually kind of important in some regards. So the modulo 2 is great for knowing whether or not a number is even or odd. Because if you have integer modulo operator 2 equals 0, then you know, this is an even number. And if it's equal to one, then we know that it is an odd number. So that's one of the use cases where the modulo or remainder operator is incredibly useful in this case. And of course, other types of arithmetic operators are also useful in, well, I mean a lot of ways. If you've ever needed something in mathematics, that is, yeah, those are incredibly useful and that's sort of the first step into knowing or into gathering some knowledge about how to use integers. In this case. In theory, everything in here. You could also replace everything in here with floats or doubles. And everything would work just fine as well. So you can do that, for example. Experiment around a little bit with that. I always try to encourage that as well because while the lectures here are really good to sort of get a headstart or to have a structured way of going through some material. I always encouraged and say that it is very important that you try out things on your own as well. Because that's like the best way to actually solidify and learn even more. So if for example, you're going to look at this with floats, just replace all of the integers with floats and see what happens. And then you can play around with that a little bit. And yeah, that's just a little idea for you. And yeah, overall that is, that would be it for the integers and the arithmetic operators. Next time we're going to take a look at a little bit more of the math methods that we have in C-Sharp. So some more, let's say specialize things like a square root or something like that, which sometimes we might need for different things. So that's what comes in next lecture. I hope this was useful to you. And if there are any questions, like always, feel free to ask and I'll be sure to respond. And yeah. 7. (C#) C# Math Methods: All right, welcome back the C sharp introduction here for the unity course. And in this lecture we're going to take a look at some math methods that C-sharp has to offer for us. So once again, makes sure that lecture for Math methods is open and then we can just open the script. And I've already prepared two integers here, x and y. And let's just see what kind of methods we have. Now, first thing to note, there are two different type of math, basically libraries that we can access. We can access the normal math library with basically doing system dot math. And this one offers us some things like maxing, maximum, max and Min methods, the square root and also some other things. However, this is specific to C-sharp. However, we're going to use the math F, Basically collection as you can see. And this one offers specific, basically almost the same things, but specific methods that are for unity. So this is only accessible if you are in Unity. If not, then you need to use this System.out math method in, for example, right? So first things first, how about like max and min? I've already sort of spoil that. Let's do a debug dot log. And then inside of it, we're going to do math F dot Min. And then we're going to pass in x, y. And this should be 225. So the idea here is that this do math F dot Min. And then as you can see, we have a parenthesis around this. And so denoting that this is a method call. Now in this case, and we've not seen this. We actually have two things in there. And so those are what we would call parameters. Like I said, we're going to look at how methods work in way, way more detail in a later lecture where we talk about methods and go into deep about how they work and what they are and what this is. However, right now, we can see that we have two premises in here, and they are separated by a comma. And this will evaluate if we actually hover over it, as you can see, returns the smallest of two or more values. So we can also put in more values. In our case we only have two. And this is, of course, that's not right. So this would be a 100, sorry. So if we min this, it's going to return the smallest of those two values. In our case it's going to be a 100. And just to be completely full here, we're going to switch this out to max and then this is going to be 225. Because the max of course, returns the largest of two or more values. Let's just this out and see if that works. So this should be a 100 and then 225. And as you can see, first hundred, two hundred twenty five is being logged. So let's go over and see. So those are the Min and the max method. We can also look at, for example, a square root, right? The square root, Let's just quickly copy the debug here. And then we're going to do math F dot square roots. So this is SQRT. And then inside of here, we're going to put in y. Because y actually can be like a square rooted immediately. This is going to go into be a 15. Square root of 225. And let's just not look at the output yet. Let's just go to the next one, which is going to be the absolute value. So absolute value is basically used if you have something that is a negative. So for example, negative 2500. And you want only the absolute value and not the negative. So you don't care about whether or not it's negative or positive, you only care about the actual value. You can see returns the absolute value of value. So whatever we put in here, it's going to return the absolute value. Let's just see the outputs of those two. So the first one should be 15, that's the square root of 225. Exactly. And the last one, of course. The last one didn't open. Oh, because I didn't save. That's why yep. They go. And then if I go in here again and hit Play, then it's going to output 2500. They go because that's the absolute value of negative 2500. And then there's a few more things. For example, the seal and floor methods, which are interesting, for example, for well ceiling and flooring. The idea being that if you have specific float numbers, so that's going to be seal as your float floating numbers. So for example, 22.1, 45. Then maybe what we want as well, actually, we want a rounded, but we want to round it up, uh, regardless of what's after the decimal point. And then this is going to be a 23. And if we just quickly do this and then we do floor here, and this is going to be a 22 because in this case we're, we're rounding down. So as you can see, returns the largest integer, smaller or equal to f, read. And seal is going to be the smallest integer greater or equal to f simply means that we're basically, as soon as this is like 0.0001 steel, we're going to go up and then in this case we're going to go down. So in this case, we're going to go to the ceiling. This case we're going to go to the floor. Should sort of make sense in that in that way. But yeah, those are basically for rounding up and down. Specifically, we also have a round. I believe we should have a round. I'm not a 100 percent sure. Yes, we do have around. So a round, it's going to round to the nearest integer. This should also do a like a output 822. Because in this case, yep. Oh, it didn't, I didn't save again, the unbelievable. This is very uncommon, but it should also open a 22 and it does. So the rounding just follows normal. The normal rounding rules, I guess we also have the power to, so if we might have something like Math.pow, this is so ten to the power of two. So this would be ten to the power of 2 is equal to 100. You could of course, also do 10 times 10 would also work. However, sometimes you need to put something to the power of something. So that is what the powers for. So returns F raised to the power p. And then the last one, which might be, might interesting, is basically clamping the clamping Val variable variable between two values. This is a very specific thing that might be used for specifically unity. And we're not actually going to print anything out because that's not because, well, there's nothing to print out right now. However, the idea of beam, and we're going to look at this in another example later down the line as well. But the idea is that the clamp, as you can see, clamps the given value. So this would be speed Given the minimum and the maximum. So the idea is that the speed right now was a 100. And we could imagine maybe for example, a racing game where we actually speed up or slow down. There should be at some point that maximum speed. And if we only have something that's checks, Hey, is this button press down and then add speed at speed at speed. And then we could imagine, well, actually clamp this down. So it's going to basically make sure that this speed variable is inside of those two minimum and maximum values. But like I said, a better, we're going to see a better, Let's say use case for this orange, actually use case for this later down the line as well. I just wanted to mention this. There are some other interesting methods in here. For example, there's a sine, sine and tangent. So there's this basically almost all of the things that you might need for mathematics. There is infinity, I believe. If I see, yeah, pi is also there. So there's quite a few things that you can take a look at and play around with as well. But this is just sort of as a general overview right now. The power to seal absolute value, square roots, Min and max values. Those are the ones that in my experience are, well, I would say the most useful but most often used, especially especially the minimax, are used quite a bit. But yeah, that's a general introduction to integers and that the math methods. And yeah, that was it for this lecture. I hope you found it useful. If there are any questions, of course, always feel free to ask and I'll be sure to respond. And yeah. 8. (C#) Assignment Operators: All right, welcome back to the C-sharp introduction here for the unity course. And in this lecture we're going to take a look at assignment operators. Now we've already seen the standard assignment operator. That was where we simply assign a value to a variable. But there are some special cases in some assignment operators that make it a little bit easier to basically calculate stuff. So let's just open up the assignment script here, and let's just start with a simple integer called I. Make this equal to one. Now, if, for example, we would like to add one to this and then save it back in to I. We could do I equals I plus one. This shouldn't be too crazy and should actually be sort of self-explanatory. We simply assign the value of I plus one because I is one. In this case, we're gonna, we're gonna calculate 1 plus 1, and then when I save it back into the variable itself, so in this case this would be 1 plus 1. Let's write it like this. Now. We can write it like this, totally fine. We can also write it like this. I plus equals 1. And this is functionally equivalent to this. So we're just going to basically add one to the original variable I, and then we're going to assign it that variable. So in this case this would be 2 plus 1 is equal to 3. So because after line 13, I was 22 and I will going to take 21 to it. And then we're going to write it back into I. So in this case this would be three. Now there's one other thing that we can do and that is I plus, plus. And this will do exactly the same thing as well. So this would be, in this case, I plus 1. And because I is three, this would be a four. Then we can also do I minus, minus, and this would then turn into i negative one or minus one and that is then a three. So those are some basic, basically how you can condense the adding of a variable. In this case, you can, of course, plot the plus equals. You can write whatever you want. You can write a 12014, another variable, whatever you want. In the plus, plus, that is always going to be a plus one or a minus one. This would be what's called an incrementation or increment and decrement. And that's really useful for some type of structures that we're going to look at in C-Sharp coming down the line. Now this plus equals, we can actually do other assignments as well. So as you have seen, so we had a plus equals. So let's say for example, plus equals 5 and 14, right? This would be then a 17 equals 17, something like that. Then we could make it minus equals to just for the sake of argument right now this minus two will lead to a 15, right? So we can also do minus equals. We can also do a times equals. Let's do two again. So this would be a 15 times 2 is equal to A3. And then we can, for example, doing divide equals as well, divide by three. So this would be 30 divided by 3 is equal to 10. And then in the end, we can also do modulo equals and that would be a 10. The model over four is equal to 2. Now, I very rarely seen the modular equals actually, but the other ones might actually be really useful at some point down the line. And like I've already said in a previous lecture, it can be the case that while you might not use some of those operators, Some someone else might use them. And if you don't know what they are, then you're going to have a harder time reading other people's code. That's why I always say that even if you are, tend to not use something where even if you're like, Well, maybe I'll keep it like this because once again, this is completely the same as this one, right? So writing I equals I plus 1 is the same as I equals 1. Some people just say, well, this is just easier to read. I understand This way better. Some people say I understand This way better. That's definitely just a style choice. And you can do either of them. When it comes to performance. There really is no difference. So yeah, that is the different assignment operators as well. Yeah, I hope that you found that useful and you'll learn something new. If there are any questions. Of course, always feel free to ask and I'll be sure to respond. And yeah. 9. (C#) Booleans and Comparison Operators: All right, welcome back to the C-sharp introduction for the unity course. And in this lecture we're going to take a look at Booleans and specifically comparisons and how to put to how to write them into Boolean variables. So let's just open the Booleans script and let's see what we can see. So remembering back, we had the is grounded variable and let's just set this to false. And Austria, remember, Booleans were a truth values that we can either set to true or false. So they can either be yes or no, one or 0. That was the gist of it. And maybe for example, we have a boolean that is called x. And then what we want to actually assign it to is a calculation. So a Boolean calculation or just an expression, a Boolean expression, for example, two is smaller than five. This would be a Boolean expression. As you can see, the a, an operator, the smaller operator added this returns a Boolean. In this case, this would be true because 2 is smaller than five if it was the other way round. So for example, this way, then two would be bigger than five and this would be false. So this is the idea of a comparison operator. We can of course also have a bully bool. Why? For example, 10 is, 10 is bigger than 50. And this of course, would be false, right? Because of course Sen is not bigger than 50. And this is why the expression here is false. There are plenty of different comparison operators. So we've seen the smaller than, bigger than bigger or equal, smaller or equal, equal and not equal or unequal. So this would be, for example, this is like a 100 equals a 100. This would be true, right? And this is because in this case, a 100 is exactly equal to a 100. Now, as you can see, this sometimes can look a little bit confusing because the equals operator are two equal signs and the assignment operator is one equal sign. That is something that you definitely have to look out for because sometimes either you forget one of the equal signs or maybe you're just enthusiastically programming and then you just oversee that either you've only put in one equal sign or two equals signs. Those are completely different things and they have nothing to do with each other. One is the boolean expression to see if two variables or two things are equal. And the other one assigns a value to a variable. Just as a quick note. And then for example, we can have something like this. So 51, unequal, 50. And this would of course also be true. And this is an unequal. Or what else could it be like, not equals, something like that. But those are the comparison operators. So they can be incredibly useful to compare different variables with each other. Is something bigger or equal to something, is simple equal to something else. Incredibly useful, widespread applications that we're going to see over the next coming lectures as well. But that's it. Just as a short little introduction to the Boolean and the comparison operators. If there are any questions, of course, always feel free to ask and I'll be sure to respond. And yeah. 10. (C#) Booleans and Logical Operators: All right, welcome back to the C-sharp introduction here for the unity course. And in this lecture we're going to take a look at Booleans once more. So let's just reopened of the Booleans script here. And in this case, what we're going to look at is not the comparison operators, but we're going to look at the logic operators. The idea being that we had these Boolean expressions like to smaller than five or 10 is bigger than 50, which could either be true or false. So they were expressions or statements that either were true or false. So they were Boolean expressions. And now we can actually chain those together. So for example, we make, we're gonna make a new boolean here, B2. And then what we can do is we can say x and y. So if we do this double ampersand sign, then this is going to be, this is an end operation. And the idea here being that it's going to be x and y. Now x is true and y is false. Therefore, this entire doesn't tire statement here is also false because this is an AND operator. And the operator basically is true if both of the state statements are true as well, then there is another one which is the OR operator. So this, for example, we can take is grounded or B. And this in this case would be true. Now the reason is because B is true, right? So we know that B is true. Your B was a 100 equals a 100. And that is true. And the OR operator basically is true if one of the given, if one or both of the given Booleans or statements is true. And then there's one last thing which we've sort of seen before, and that is just the exclamation mark. And that simply this simply reverses whatever is given. So in this case, this is basically the NOT operator. So not true is just false, right? So this simply flips or reverses the Boolean value. So in theory, what we could do is we put the parentheses around this. I could put a exclamation point in front of it and then it would negate everything that's in the year. And they're also like fancy mathematics that you can use. The words that you would look for, for that would be either truth table or Boolean algebra. And so you can imagine maybe you have something crazy like this, right? You have to B2 and B4, or B3 and x or y, or how about or see somebody like that, right? So we can't have something crazy like this. It would, it works totally fine if you would, of course, have to basically evaluate each of them separately. But you can possibly also simplify something like this to a much smaller version of the same basically function that we have here. Well, the same expression and this was, this is what's called Boolean algebra. So we could simplify this. I'm not going to, if however, there is like a lot of interests in this, I can make a separate lecture for it. However, I would say that it is rarely really necessary. It's more something theoretical and that's really important in theoretical computer science and of course sometimes also applied computer science. In this case, when you have incredible, incredibly long like boolean statements, then it makes sense to look at how you can maybe make them a little bit. Both easier to understand and also may be easier to just evaluate. However, like I said, it's not necessarily the most important thing. However, if there is enough interest in front of people, want to see that, then I'm happy to make a new lecture on this. However, right now this is the, basically the logic operators, the AND operator, the OR operator and the NOT operator or the reverse. I mean, it's it's called the NOT operator. And yeah, that is basically the main three logical operators, which with which you can basically do everything in logic. And yeah, those are the two terms that you, if you want to, maybe look at some other things as well that have to do with that. Those are the two terms that you should look at. And if there are any questions regarding this, of course, always feel free to ask and I'll be sure to respond. And yeah. 11. (C#) C# Strings and String Methods: All right, welcome back to the C-sharp introduction here for the unity course. And in this lecture we're going to take a look at strings. So once again, making sure that we are on Lecture 8, strings up here. If not, you can simply go to the Scenes folder and open it. And then making sure that inside of our scripts folder, we double-click on these strings script. And here we are inside of our script. And let's just start by actually making a new string. So the string sentence, for example, let's make it say helloworld. This, this lecture is wonderful. Well, let's hope that that's true. But first of all, as we have already seen, the idea of a string is that it is multiple characters next to each other. And the first thing that we are going to look at is basically once again, the length. We have seen this before. So the length of the string. And this was, we were able to access that by typing the name of the variable, in this case sentence. And we can autocomplete that with tab and then dot length, the length. And then we could also autocomplete that with tab. And after we've saved, we could just switch back to Unity. And let's see. The length is 39. Well, that's great. So let's go back. And let's see. So the length of the string can be useful in many different parts. For example, sometimes, maybe we want like sub-strings or certain parts of a string and then we need to know the length. I'm going to look at that soon enough. First of all, let's look at upper and lowercase. This might be useful, for example, if you want to, regardless of certain input, verify whether or not that input is the same. But in this case, we're just going to basically convert the sentence to shouting. So we're gonna type in sentence dot two upper in this case. As you can see, this is, this ends with a parentheses, meaning that this is a method call, so this calls a new method. And then we can just once again copy this by basically simply selecting the debug log, pressing Control C and then Control V to paste it in. And this is going to be to lower. And this is going to be, of course, whispering. Right? And then, yeah, let's look at that. So showering just to upper is just going to make it all in uppercase. And to lower is it's just going to make everything, every single character in that sentence to lowercase. So as you can see, shouting is going to be uppercase and then whispering. Everything is lowercase. Like I said, the sometimes what is interesting an application for this is basically to make it so that whatever, regardless of upper or lowercase, you can compare two strings with each other and see if they're still the same regardless of whether or not everything's upper or lowercase. And, well, let's just look at the sentence itself. So the spring itself. Let's also print that one out. Just, just for the sake of argument. Well, what we respect us that it's all slowed, small but are lowercase, but as you can see, the H and W are actually still uppercase. What, Why is that? Well, the idea being that even though we have called this method here, as you can see, it actually says string and then it says string dot two oper. So the idea being that this actually sort of it, it returns a new string. So it is, the sentence itself is not being modified. And that happens with some of the methods. I believe that it's almost all of these string methods don't actually change this original variable or the value even. They always give back a new instance of this variable that is then changed. In this case, uppercase saw all is large. And then this one, all lowercase. Maybe what we want is we want to find out where something is inside of that string. And we can use index off for that. So let's just make a Debug lock again. And then we're going to find the word lecture. The word lecture found at position. And then let's put the position in here with making it doing sentence dot index off. And then we can pass in a string here. And we're going to say lecture, oh, that's not right. There you go, lecture. And this is going to return the index of where electrons starts. So let's just see what, let's just count first. So 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 19. So let's see if we actually get 19 or what we're getting. We're getting 18. Well, that's isn't that weird? The IOM like count wrong? No, we didn't count wrong. Well, we did in some way. But no. The idea is that a sentence, the first character here, the first char here is actually 0. So we actually have to start at 0. And if we start counting at 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18. Then we see that the L of lecture is actually found at position 18 because we start counting at 0 and that is actually important, start counting at 0. So that's an important thing in programming. Most programming languages start there, count both of strings and of other datatypes at 0. Kind of important to know. Because it can sometimes lead to weirdness. There are also some other programming languages where that isn't the case and the count starts at 1. However, it's really confusing to switch between the two. That's why I'm saying, okay, start the count at 0. Very important. There is also a replace method. So in this case, the replace method replaces all of the, all of the instances of a particular phrase, basically. Let's say he's called the replace method and we want to replace world with students. And the idea is that, oh, I know why the ego, that's why the, it takes two strings. The first is the string that is to be replaced and then the second string is what it is supposed to be replaced with. So in this case, what's going to happen is that the output is going to be hello students. This lecture is wonderful instead of hello world and this lecture is wonderful. Let's just run this and see if that works. Yes, Hello students. This lecture is wonderful. And once again, don't forget that this is not modifying the original sentences, actually giving us a new one. So what we can do is we can also, when we have a new string, for example, string S, that is just going to be an empty string. So this would be an empty string. We can also say strings.xml for empty string, but those are basically the same. Then what we can do is we can basically have a Boolean. So we can call string is null or empty. Pass in a string, in this case S. And this is going to return true if the string here is null or empty. And it's going to return a false if the string is neither null, novel, nor empty, right? And we can also look at whether like what a certain string starts with an, what it ends with, can be useful in very different moments. Let's just take this one. This is going to be Stuart's with, and this is sentence starts with, starts with returns a Boolean. So basically we can say, hey, does it start with an H? And then we can say ends with. And then we just quickly to this one, ends with, and let's say it ends with a big a. And that's of course not true. So this would be true. And this would be false. That's formatted nicely. There you go, That's great. Right? Let's look at that after we've looked at the next one and the next one is the contains method. The contains method simply returns true or false. So a Boolean value if something is contained in it or not. So let's say we want to know whether or not the sentence contains world. This is of course true because what world is the second word in here. And once again, the replace did not replace the sentence. It actually created a new string sort of in the background. So let's see. Yep, starts with an H. It does start with an H, capital H, and then ends with a big a, that was a capital a and that has folds. And then it's a true here for the contains the string world. There is also sort of a different way. The index here was an integer. So basically the number where the L of the lecture starts, we can also sort of make it the other way around so we can actually get a character at position. So let's get it at position 10. And the way we do that is we're just basically typing in the name sentence. And then we make these brackets and then typing in whatever the position is that we want. So this returns a character. And in this case it would be, I guess the D, I believe one. So 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10. Yes. So this would return the D here in world. And something that is also to do with that is the substring where we also need to specify positions. And now on yeah, so let's do debug log sentence dot substring and E Once a start index, and then it wants the length, it goes. So basically the substring, what it wants is it wants to know, okay, where do I start and then how long do I go for? So in this case, this should start at the t and end At, I'm not sure, actually, 123456789, 10, 11, I guess. Tour. Well, we're going to see about that. Let's see that is actually the case. Let's see what that is going to bring. So the substring is actually yes, and that also has the space in there as well. And elect to this lecture. And as you can see here, the D is also output this leg two. So this would be 12 and wouldn't start at 13, I believe if we want to, want it to print out this lecture, Let's just do that. And they go This lecture, great. That's exactly what I want, right? And that is a substring in this case where we have, when we take a particular part of the string and create another one. So once again, we don't modify the string itself. The way we would modify the string could be something like this sentence, sentence dot substring for example. And then what would happen is it would create this do substring and then save it back into the sentence itself so that the variable itself, so that would work. However, we're not going to do that at this point. That's actually not quite what we need in this moment. The last thing I want to show you is if we have a string and then maybe what we want in this string is we want to have quotes. Now, the issue being that as soon as I type in quotes, the string ends, that is of course, not quite what we want. And what we can do is we can make one of those backslashes. And this backslash is basically an escape character so that the program knows that, okay, this is now actually meant to be quotation marks that are actually inside of a string. There are also some other things such as the backslash t, backslash, backslash, backslash. If you want to type in a backslash. Those are basically the main ones. So the backslash quotes, backslash t, backslash n. So the teach simply MIX tab. So if you press tab, you tab over a certain number of spaces and makes a new line. And the backslash, backslash simply types in a new backslash. So as a character, same with, the, same as with these quotation marks, right? Yeah, those are the sort of main things about strings and some of these string methods. Once again, I implore you to look at a few of those yourself. There are a few more. So if we just look at this, what we can see, there's also compare equals, there's insert, um, there's a remove method. So there's a few other things that we can do as well. Like I said, I implore you to look at them. That's just a general overview of springs, usually especially in game development itself. It's not the string manipulation is not as common as maybe in some other fields. However, sometimes you never know what you're going to get. So it's best to know about these things and to have taken a good look at them. I hope that this was informative to you. If it was, then I will, of course, appreciate a review from you. And if there are any questions, of course, like always, feel free to ask and I'll be sure to respond. And yeah. 12. (C#) Casting Variables: All right, welcome back to the C sharp introduction here for the unity course. And in this lecture we're going to take a look at casting. Now, casting might not say anything to you. The term might be okay. What is casting? Well, let's just take a look by opening the script here. And the idea is that let's see, we have a variable called loan, which is 750, and it is an integer. Now, what we also have is a float called the interest rate. And that's going to be, let's say like 5.25%. So this can be written as 0.05 to five. Now what we can do is we can say, well, the homeowner calculate the interests. Well, the interest is simply going to be the loan times the interest rate, the interest rate that you go, right? So that's not going to be too crazy of a calculation and should be fairly straightforward. And then let's also make sure that we just log the interest right now. And let's see what we can see. What's going to come out of that. So it's gonna come out of that is 39.375, or let's say 39 point, let's say 3, $8, let's say. Now, how does that work? We have just taken an integer and basically multiplied it with a float. So the question comes, how does that one work? That, that is kind of weird, right? Why can we just take the integer and basically multiply it with a float? Well, this is what would be called implicit casting because the both are numbers and that works. What wouldn't work is, for example, if I said, well the interest is now an integer, then would actually be a that doesn't work because as you can see there, it says cannot implicitly convert to type float to int is because this is a float. And if we have a integer multiplied with float, then it gets converted into a float because a float has more information than an interrupt. However, I can explicitly say Hey, regardless, treat this as an integer. So I can say well int. And then it's going to be like Okay, sure, the interest rate is now an integer. The big issue with that is going to be, well, what does that really mean? Well, let's just see if we still get 39. Now we get, we get 0. How do we get 0? Well, the idea is that an integer doesn't have any, anything after the decimal point, right? So an integer is always a whole number. Therefore, this gets converted into an integer. And what happens when a float gets converted into an integer? Everything after the decimal point, it just gets cut off. So basically what the interest rate after it's being converted into an integer sees is 0. So interest rate is 0, therefore, the loan is 0, which of course doesn't make any sense. Or if the interest is therefore 0, which doesn't make any sense. That is why we want this to be a float. We can also see this as another example. Let's say we have an integer x and we're just going to say something like 50.5 f plus 20.6 f, right? And we are going to now a log this out. So we'll look at what we would expect. In this case, a 71. Yes, 0.171.1. Now it's an integer. So what we should see is a 71, and indeed we see a 71. So once again, in this case, this would actually be 71.1. And then everything after the decimal point gets cut off, therefore, it is 71. And what's also interesting here is when we divide something, if we divide, for example, a 100 by 200, F, for example, right? It's kind, it's sometimes important because sometimes a division is not going to return whole numbers. So in this case, it is a whole number. But if we, for example, were to do something like something like that and then Sure, why not divide that by two hundred and two hundred F. So dividing this by a float. And then let's see what that actually yields. As you can see, this yells to point to 55. Now, if we were to divide this by 200, and then we can also say it doesn't float, it doesn't actually matter. Issue being that this then is a two. So sometimes it is better if we have a float in here, sometimes it's best to work with integers. One note that I really want to make clear just so we have this out. So I used this loan and the interest rate just as an example. If you are ever working on a banking system, whether it be the inside of a game or real-life, never use floating point numbers. Always do everything with integers. So save both the, both the full amount of dollars as well as cents in both in integers. Because floating point numbers, like I've already told you, are prone to errors. And especially in rounding. And you really don't want rounding errors when it comes to money, that is going to be a real big issue. I just wanted to mention that always use integers if you do that just as a quick aside. When other thing that we can do is we can actually cast characters. So what we can do is we can cast the character, for example, of the upper castes, eight, the upper, uppercase a. So let's do y. Now it's actually great out here a bit because the cast is redundant because I can actually just say, well, int y is equal to a and that works well. We're just going to keep it here just so that we know, okay, We actually casted. And if we then just run this, we can see that it is a 65. Why is that 65? Well, this comes from the way that the characters are basically encoded. And the encoding in the background is just a number. That's all it is. So we can actually do something like this. So we can say, for example, 50, well let's not 50, Let's do 12 plus this, right? So like that. And then we can also cast the integer to a character and then print out whatever that is. So we're basically going to go from a and then 12 encodings afterwards. Let's see what that is. That should be a nother. This is an M. There you go. So there is also some amount of ways that we can basically calculate the stuff with the characters as well. And those are some of the basic castings. And there are also a little bit more advanced concepts that we're going to take a look at in a future lecture. But right now we don't have the tools or the knowledge for that to actually to know how that works wherever this is a basic overview right now. So we can actually convert some data types into other data types. Most of the time, implicit. Implicit casting works. If you go from a datatype that has less information to a data type that has more information. So from an integer to a float works implicitly. From a float to an int doesn't work implicitly because you lose information, mainly in this case being the, everything after the decimal point, right? That was it for the casting lecture. I hope that this was informative to you. If there are any questions, as always, feel free to ask and I'll be sure to respond. And yeah. 13. (C#) Conditional Statements (If and Else): All right, welcome back to the C-sharp introduction for the unity course. And in this lecture we're going to take a look at conditional operators. What are conditional operators? Well, it's basically some keywords that we can use to see whether or not something is true or false. And then, depending on whether on this trophozoites do certain different actions or execute different coat. So let's just start the conditional script here. And let's see what we can see. So as you can see, it's going to be the if and the else statements that we're going to take a look at. But first of all, we need some variables, so we're going to have an x and a why as well as a bool is good course. And that is, of course going to be true. Let's hope that that is also true, but I'm fairly certain that it is. Well, what can we do? Well, let's just type in IF this is the if statement. Now what we can do is we can press Tab twice and then it's going to generate for us the way in if statement looks, as you can see, it has parentheses after the if. Then inside of these parentheses there is a Boolean expression. Now this can be as complicated or as easy as you wonder. It can be either just a Boolean value, like true. It can be a Boolean variable or like we have seen in previous, uh, lectures, the crazy Boolean comparison operators or something like that. So let's just type in x is bigger than y. And then if that is the case, then everything inside of this scope here is executed. So let's just say debug dot log. And then we're gonna say x is bigger than why they go, bam. And then if that is the case, then this gets executed. Now of course, we can actually already see that x is a 100 and y is 1000. Therefore, this is definitely false. What can we do then? Well, then we can just add an else statement. The else statement then gets executed. If this is false. So if this is true, then this gets executed. Else. So if this is not true, then this gets executed. And in this case, x is not bigger than y. Let us just run this and see what happens. Once again, making sure that you are on Lecture 10. And then as you can see, x is not bigger than y. And that's the only thing that gets executed. Instead, what we've seen here, what we've seen before was that we just go straight from the top to bottom and everything, every line is executed. In this case, we actually have a conditional. So this is sort of a branching thing. In this case. It depends on what happens here. Interesting. How else can we do this or what else can we do with this? Well, first of all, one thing to note is that, for example, if we have this is good video, It's good course here. What we can use is we don't actually need to have these brackets. We can also just hit Enter and then have one line that we want to do. So yeah, it's pretty good, for example. And this then gets executed. If this is true. We can also, if we just copy this over. And in this case we just put in the, the Boolean. We can also explicitly say, Hey, this needs to be true. Now this is not necessary because this all already does this. However, some people prefer this because it makes it a little bit more explicit to what this actually means. So, so what do I want with this? I personally prefer to use this version. However, if you think that this is more readable to you, you can of course use this as well. What I also wanted to say that is, if you do use the M this way of writing it, so the if statement and then with the indented next line, I would say that it's not the best thing to do. Because if we ever want to add a new line that is also inside of this, if then we would need to add the curly brackets any way. Therefore, it is actually always the best thing to do to add the curly brackets. Just, I just, I wanted to mention that one, right? So let's see one last thing. So for example, we have a grade, for example, right? Let that is, let's say something like 99. So maybe you, we've just written an exam and the grade is 99%. And then what you could imagine is that maybe what we want is we want different things too. A, B output depending on what happens with the great. So for example, if the grade is smaller than 50, well then what we would want to print out is you have failed the class. Because that makes sense, right? If you have less than 50, then that makes you fail a class. Now, if we maybe want, right? And then you've succeeded in the class, so you passed, right? You have passed the class. If it's not 50, however, well, maybe what I want is I actually want to have this, right, because you have passed the class, but not quiet with, quiet with a 100 points. So maybe what I want is actually I want this to be called if the person doesn't have a 100 points but has passed. And then I want another thing to be cold. So what we can then do is we can do the else if statement, simply changing the, another if statement in here saying, for example, grade is bigger or equal to 50. So this is exactly the reverse of this right end. The grade is smaller than 100. So it is between 50 and a 100. And then this gets called. So you have passed the class, but not quite with a 100 points. And if we then say else, we can then look into, for example, doing this and then having this. You have passed the class, Let's see, with on us something like that. And this would then work. So right now we have 99. So what should be printed out is you have passed the class, but not quite with 100 points. Let's see if that's the case. You have passed the class, but not quite with 100 points, exactly. And then if we have 100 points, then it should work. Let's see. Indeed you have class, the class pass the class width on us. Right? Now, there's a tiny little flow in there which you can look at your self. Maybe you can find out and add to this on your own time. Because if I have 101% in year, I still pass the class with honors. As you can see, it still works. Maybe you can add either a new expression in here or maybe eight, another if statement. But that's genuinely just an idea for you. If you want to play around with this, a little bit more. Very important if and else statements are a crucial building block of programming. They are basically one of the most important things to get down. So this is a very important area of knowledge that you need to have in order for you to program. So this is why I really want to stress, try out a few things with the if and the else statements. Play around with it a little bit. And if there are any questions in this instance, in this topic, very important, Duke, ask any questions that you have that might not be maybe completely clear if there's anything unclear, please ask a question. I'll be sure to respond like always. And yeah. 14. (C#) Ternary Operator: All right, welcome back to the C sharp introduction for the unity course. And in this lecture we're going to take a look at the ternary operator. Now first things first, the ternary operator sounds like it's incredibly complicated and some like vastly crazy thing. It's not crazy at all. It's actually fairly easy to understand and we're gonna go through it right now. Once again, making sure that we are on Lecture 11, ternary, and then just opening the ternary script. So as you can see, there's already something in here. We have a great grade and a bool that just express whether or not this greatest past has passed or not. We have seen in the last few lectures how we can basically manipulate that a little bit. And now there's just going to show a quick shorthand basically. So we can say past is equal to. And then for example, we can say grade, I'm bigger or equal 50. And that just works because we can of course save the Boolean expressions. In this case with the comparison operator just in side of a Boolean as well. Instead of, instead of always evaluating this inside of a if statement, we can also just save it into a boolean and then basically look at it like that. Now the ternary operator has something. It basically works almost like an if statement. So we can, for example, say past is equal to and then we say grade is, let's say, smaller than 50. Let's make a sum parentheses rather than the ternary operator is a question mark. And then whatever should be returned. If this is true, it's going to be a little bit. We are right now. This can be false and then we do colon through. So as you can see now it's actually showing no more errors. The idea being that in front of the question mark, you put a Boolean expression. And the first element here is what gets returned. In this case, written into the past variable. If the expression here is true. And then what comes after the colon gets returned? If the expression here is false. So this one, So this, this expression here is basically the same if I were to do the following. So this one passed equals false. Else passed equals true. So those are completely equivalent. In this case. The same would happen here as it does here. Maybe a, another example might be a little bit better, for example, with a string. So let's say, for example, the phrase and then we're going to say grade equals a 100. Then we're going to say congrats on 100. And then if it's not a 100, so this, this gets returned if it is a 100, and this gets returned if it's not a 100, not a 100. But it's still good. Something like that. For example. As you can see, that works out. And this might be a little bit of a better example than the past one year because we're using Booleans here as well. This the ternary operator, like I said, can be replaced with normal if statements as well, or if statements can replace with a ternary operator. It really depends on the situation. Something I would definitely not do is have multiple ternary operators, like inside of each other. So in theory we can say, well, okay, this is another journal brighter, so we can say greatest, bigger or equal to 50. And then another question mark, and then we can return past and then we can, for example, return failed, right? So we can do this. At this point, it starts getting a little bit more complicated to read. I think that this might be okay. If you have like two levels deep, maybe that works. But I really would not advise you to do any more than that. Yeah. But it's also sort of thing that you get a feel for if you start programming a little bit. Yeah, So that is the ternary operator. It's just a little short introduction to it. There's nothing too fancy about it. And it's just important that you've seen that are all. So yeah, yeah, that was it for this lecture. I hope you found it useful if there are any questions, like always feel free to ask and I'll be sure to respond. And yeah. 15. (C#) Switch Statement: All right, welcome back to the C sharp introduction here for the unity course. And in this lecture we're going to take a look at switch statements. So last we've seen the ternary operator. There's another operator or a statement that we can use that I wouldn't say replace the if statements, but that we can use instead of the if statements if we so choose. So let's just open the switch statement script here. And it's can see I've already prepared an integer value or integer variable x with value 75. And we're going to look at the switch keyword. So it's just switch. And then in parentheses inside of it, we want to put a variable that we want to evaluate, in this case x, and then we need the curly brackets. And that is basically already what we need for the switch statement. Then inside of the switch statement, we are actually going to define specific cases. So if for example, x is 10, so we're going to write case 10, then a colon, and then whatever we want to have happen. So here we can actually write like a whole bunch of code, method call, whatever we want. In this case, we're just going to print out or debug log x is 10. And at the end of this, so after the semicolon, we actually want another keyword and that is brick. And this simply signifies that, okay, this case is now done. So obviously the, IT, there's an easier way to output whatever x is in this case. This is just for demonstration purposes in this case. And so we can have another case, so for example, case 20. And then we're going to say debug log x is x is 20. And another break. And let's just copy those over. So we're going to basically make sure that we mark them and have them selected. Then we're going to press Control C to copy control V to paste in. And then we're going to have another fifty and a hundred and fifty and a hundred. And yeah, that's fine. Now, as you can see, the let's say drawback here is that we actually have to specify each specific case instead of an if statement where we had the sort of ability where we pass the Boolean to have ranges. Here it actually needs to be explicit in each case. So it can be a little bit tedious. And there is one specific case that happens if x is something that we haven't thought about or if we don't want to define a case for that, and that's called default. And default happens. So for example, say debug log. I don't know what x is. Kinda weird. And then a break, you're as well, right? So in this case, obviously default would be, the case would be default because x 75 falls into none of those four cases. And we can actually check that. Making sure that we are on the switch lecture. And let's play and see if that works. I don't know what x is kinda weird. There you go. Because x was something where no case was defined for. So yeah, that is basically the switch statement. It has some uses in specific cases. However, it's usually reserved for maybe where you have three or four predefined cases, where this doesn't go on for too long. And also usually integers and also floats. So never use switch cases if you have floats or doubles because that, I mean, literally doesn't work. Or My lead to disaster. Integers r can be fine. However, usually switch cases are reserved for things like enums, which we're going to take a look at a little bit later, where that basically have predefined values. So that's sort of the idea. But I wanted to show you the switch statement. It can be useful and can be basically interchanged with an if statement. And yeah, that was it for this lecture. I hope you found it useful if there aren't questions, like always, feel free to ask and I'll be sure to respond. And yeah. 16. (C#) While Loop: All right, welcome back to the C-sharp introduction here for the unity course. And in this lecture, we're going to take a look at the while loop. So we're off to the next section, let's say, which is loops. And let's just see what we can see opening the while loop script. So I've already defined an integer x equals five. And now what we want, maybe, what we want is we want to lock this x, maybe a lot of times, right? So we want to lock this. So right now we have looked at 6 times, but actually I want to log it a 100 times, right? So I have to copy and copy again and copy that. I mean, that's ridiculous, right. Obviously that's that's way too much. And maybe actually what I want in-between those locks, I actually want to increase this. So I want to look five and then I want to look six and then 78. And I mean, that's, that's madness rate. Of course that's madness. That is why we have loops. A loop simply repeat a specific section of code. Let's say number of times that we defined. And in this case, a while loop does something while a certain Boolean expression is true. So let's just write the while, a loop, the while keyword here, and let's just tap twice and as you can see, it generates a parentheses, parentheses here and curly brackets. So everything inside of the curly brackets gets executed as long as whatever is inside of the parentheses is true. In this case, while true will always run and keep running. And it's basically going to crash unity if we do this. So that's one of the things that we need to look out for. There should always be a great condition instead of a while loop. Otherwise, it might turn into an endless loop. And that will then in turn, turn into Unity crashing. Believe me, it's going to happen to you at some point. While you program something with while loops. It has happened to me. And who knows? By the end of this lecture, maybe it's going to happen as well. I highly doubt it, but you never know. So let's put in x is smaller or equal to 10. And while that is true, we're going to debug dot log x log x, and then we're going to increase x. So if we wouldn't have this increase here, then it would keep logging out 55, 55. But it would do with this To Eternity, which of course doesn't work, and therefore unity would crash. That's not what we want. Therefore, we are going to increase X each time the while loop runs. So it's going to run like any other type of code from top to bottom. So it's going to print this out or increase it. Check a is still a thing. If it's solving a log it out, increase it, check again and so on, so forth until we are done. And let's just add a debug after here. It's going to say out of the loop. The loop, no, out of the loop. There you go. And yeah, let's just run this so what we expect. So one thing that's always a good idea to look, what are we expecting to see in the console. So I'm expecting to see 5, 6, 7, 8, 9, 10. Yes. I believe. Am I going to see 10? Yes, I'm going to see 10, I believe. And then out of the loop. So five to ten. And then out of that is what I'm thinking about senior and making sure that we are on Lecture 13. While Let's see if that is the case. 05678910. And out of the loop, isn't that great? That's also just as a quick aside, very important. Think about what you want to see in the console. So think about your expectation and then look at what comes out. And if your expectation and whatever is output or locked is met, great, you have a thought about it in the right way. If there is a discrepancy, then try to figure out, well, what did I do wrong? Or for example, an easy, Let's say mistake or, or an easy thing to make is instead of having x smaller equals 10, we have, it's smaller 10. We're like, well, it's still going to output the 10, right? It's still going to go from five to 10 because as long as it's smaller than 10, and of course it doesn't output the 10, because as soon as it is 10, it's no longer smaller than 10. Therefore, it's not going to, it's not going to execute whatever's in the, in the curly brackets. So that's something to look out for. That's not specific to the while loop itself, but just general advice. And there's a second, Let's say. Another I do with a while loop that sort of ties into the smaller, smaller than or equals. And that is the do while loop. So we can just put in do and then press Tab twice. And as you can see, in this case, we are going to have a do keyword here, followed by the curly brackets and then the wireless at the back. Let's put in x is smaller than 10. And then we can actually do the same thing. So let's just do exactly the same thing. And let's not do it like let's not do this year. Right? Let's, let's actually quickly get this out of here. And the do-while loop. Well, let's just see what happens. So we've seen previously that the while loop with x smaller than 10 that printed out five to nine. And in this case, it's going to print out five to nine once more. Interesting, isn't it? Well, what is also interesting? If we keep this, then we're gonna run our x into ten. So this function is exactly the same way, right? So this is also going to evaluate this. And then let's put this in here. Let's say, okay, x is, as soon as we're out of the loop, x is going to be equal to 10. So the while is not, is never a thing. So X is always going to be bigger than 10, never smaller than 10. However, if we look at this, it's actually going to print out 11 here. And if we double-click here, we're actually going to see this is what is printed out. That's kinda weird, isn't it? Why would that happen? Because x is never smaller than 10 at that moment. And I mean, it's, it's pretty evident because it's actually printed out 11. Well, do-while does this one's, so there's DO command so to speak. They do keyword, is going to run the things inside of the curly brackets once. And then it's going to evaluate the while condition. And then it basically functions like a normal while loop would might be useful at some point. Personally, I have rarely use this. And also personally, I have also rarely used while loops as well, because they do, at least when I use them tend to crash unity. So be warned, but don't be, it's not gonna be too bad because usually as long as you save enough times, then it's going to be fine. But yeah, it's it's actually not too bad. I just wanted to mention that. And yeah, that is basically a short overview of the while loop. I hope you found it useful and I would really appreciate a review from you. And if there are questions like always, fees for task and I'll be sure to respond. And yeah. 17. (C#) For Loop: All right, welcome back to the C-sharp introduction here for the unity course. And in this lecture we're going to take a look at for loops. So we've seen a wild loop. So what is the for loop? Well, let's take a look by opening the for-loops script. Well, we're going to take a look at the for loop without anything else. So let's just type in four and we're going to make this manually first. So the first component inside of a for loop is an integer. In this case, we're going to call this integer I equals 0. I'm going to put in a semicolon. Then we have to choose a, an expression. So let's say I is smaller than five and then I plus, plus. And then put in the curly brackets as well. So what does this mean? Well, this means that I starts at 0. It is going to five. And it's increasing, increasing I by one. That's the idea because as we've learned, I plus plus increases. In this case, I by one. I starts at 0. And as long as this is true, the loop continues. So this one would be counting from 0 to 2, 1, 5, 4, 5 to 4. Let's just look at this. So debug dot log and then I. And then we're going to go through this. How this looks. So let's just lock this out and see what the console has for us. It should lock 0 to four. And as you can see, 0, 1, 2, 3, 4. Great, that's pretty good. And then let's think about this. So we start at 0, that's easy to see. So we're going to print out 0. Okay? Then we're going to increase I by one. And then we're going to evaluate, Hey, is I smaller than five? Yes, it is. All right. Let's print it out. And then it's going to be 2 is at smaller. Yes. Then it's going to be three small areas for yes. And then it's going to be 55. I don't know if you heard, but that is not smaller than 5. It actually is equal to 5. Therefore, we're out of the loop at that point. And this is why five actually does not get included into the eye, so to speak. So as soon as I is equal to five, it, we're going to jump out of the loop. So that's really useful for counting, and it's also useful for some other things that we're going to take a look at it very shortly in the next lecture already. However, the for-loops, definitely great. We can also count backwards. So let's just do that. So let's make an integer 10. And let's say, Well, I should actually be bigger than 0. And then we're going to say I minus minus. And we're going to print this one out. And this should be counting from, well 10, definitely write 200. Know once again, think about this. If we have in not, let's say bigger or equal or smaller or equal sign in there. Then usually that the number here doesn't get included. If we have a bigger or equal than the 0 would get included. In this case, it's going to be one. And then we're going to say also backwards, because this counts backwards. So we're going to, the output should be 0 to four and then 10 to one. So let's see if that is actually the case. Let's start it. So 0 to four and then ten to one, go. Great. Right? So that is the for-loop. In my personal opinion, usually more versatile than the while loop. But I think that it also has to do a little bit with preference. I think that there are applicable in different situations as well, so, well, that is it for the for loop, a very important part of programming, definitely. So if there are any questions, like always, feel free to ask and I'll be sure to respond. And yeah. 18. (C#) Break and Continue Keywords: All right, Uh, welcome back to the C3b introduction for the unit course. And in this lecture we're going to take a look at two keywords. Those are going to be break and continue. Now we've already seen a bit of the break keyword in switch statement lecture. However, this is actually the application FOR loops. In this case, we're going to take a look at the break and continue keywords inside of the for-loop. However, especially the break keyword could also be used in a while loop. So let's just open the break and continue script here. And as you can see, we actually have 24 loops that do exactly the same. Actually, we're going to count from 0 to nine in both of those. And yet that just is going to work. However, what we can do is we can use one of those keywords, keywords. So let's, for example, say if I is equal to four, then what we're going to do is we're going to continue. So what does that do? Well, the continue keyword basically says, all right, let's just move to the next I. So we're going to skip printing out or logging the four. And we're going to skip straight from three to five. So let's just see, Let's quickly copy this out of here so that the console doesn't get cluttered. And once again, make sure that we are on Lecture 15 break and continue. As you can see, we jumped from three straight to five. Because on a four, so I equals 4. What we have done is we have continued, Continue, basically just jumps into the loop again, ignoring everything that comes after it inside of the loop. So basically it gets cold again and all lines after it are ignored. Yeah, that is the continue keyword. Now, let's go to the second for loop. And let's say for example, if I is equal to five, then what we want to do is break. Let's actually do it properly so that it looks nice. Yeah, break. We've seen this before in, like I've said in the switch statement inside of here, the break simply means instead of a loop, break means loop stops. So break says, Okay, let's immediately jumped to the back of the org, to the end of the loop is the same as if the Boolean expression up here would be false. So therefore, we break out of the loop immediately. Let's see this. So what we should see is we should see 0, 2, 3, five to nine. And then afterwards we should see 0, 2, 4 because as soon as I is five, we're going to break out of this form. Right? So let's see if that is actually what we're going to see. What I'm fairly confident it is. So it is 0 to three and we're going to jump from five to 901234 and then that was it. Yeah, so that is basically the idea of the continue and break keyword. There are some people that say that it's not necessarily the best practice because it can sometimes be confusing, especially if you maybe have a long FOR loop and you have a lot of continues and breaks in there with maybe even more if statements and all of that, then it might sometimes be a little bit confusing for simple for loops. And while loops break or continue keyword is not going to be too bad. I don't think so. But yes, so that is it for the break and continue keywords. Also important parts to have seen at least and to know for loops. So if there are any questions, as always, feel free to ask and I'll be short respond. And yeah. 19. (C#) C# Arrays: All right, welcome back to the C sharp introduction for the unity course. And in this lecture, we're going to talk about arrays. Now, arrays are a vital part of programming. And the first topic that is a little more complex and complicated. So I definitely implore you to maybe even watch this lecture twice, because this has a little bit more in it. And of course, if there are any questions, feel free to ask. But let's just jump right in. By opening the script. I've already prepared three strings here. As you can see, students 0, student one, and student two, John, July and Ryan. Those are, let's say, email addresses of my students, for example here. And now what I want is I want to e-mail them or I want to output the emails, let's just say, so of course we can do debug dot log and then we can say student, student 0, and then we can say student one. And then we can say student today you go, now I've output those. Isn't that great? Well, that's fine. But let's say I have a 100 of those emails That's going to be a little harder than, well, we've learned something that we can do. We can take this four loop and we can say, well, let's just go through that and then we can maybe say debug log and then maybe put the I here are some, no, that doesn't work. Obviously that doesn't work, right? So this, sadly, this doesn't work. So we can't just output them with a for loop and we can't, we can iterate over them, right? So this is basically what we want. We want to, sort of, we want to list something like a list. And that is where the theory comes in. So we can, let's say init, an array, right? So the idea being that an array is basically a list of certain type. In this case, we're going to make a, an area of string. So we're going to write string, just the normal string keyword like we would with any other variable, string variable. And then we're going to type these brackets and then the name of the variable, student, males, let's say. And then we can make a, we can initialize this new array by putting it in curly brackets. And then we can put in, for example, John at gmail.com. And then the second one is going to be July at gmail.com. And then the third one is going to be Maria at Gmail for example.com. And then we'll also have Ryan at gmail.com. Let's just zoom out a little bit. And then at the end, a semicolon. And now this is, as you can see, no errors, everything is fine. And now we have actually initialize this array is also another way we can initialize this array. So this is explicit with four specific strings. In this case. We can also say, for example, an integer arrays of some numbers like that. It's going to be equal to new int. And then this way, so the brackets, then inside of those brackets we actually have to write how many. Numbers, or in this case, so how many integers are in there? So let's just put in 5. So this one would be, can have five entries. And then we can assign something to that. And how do we assign something to it? Well, we can just take the variable name. So some numbers. We once again put in the brackets. And inside of those brackets we take, we put in a number that is the index of the entry. So 0 means the first entry. So this, let's say 10, and then let's just quickly copy this over 1, 2, 34. So let's say something like 2054421337, something like that, right? Very important. Arrays start there, count at 0. We have seen this before with the strings. And I wanted to mention this here again. If we look into student males for example, right, we have four elements. So the size or the length of this string array, student males is four. That's okay, That's fine. That's understandable. However, the first element here, John edit gmail.com. It's actually at index 0. So once again we start counting at 0. So this is 0, 1, 2, 3. In, in sum, there are still four elements. However, we just start at the start counting at 0. So now looking back at this, well, we wanted to print out or log all of our email addresses, and now we can do that. So let's just make a new for-loop. And it already sources out length here. Well, what we can do is we can, well, let's just do four, because we know we have for student emails That's easy enough. And we can say debug dot log student are males. And then here we have assigned values. We can also just get the values back by just calling the doing the brackets. And then inside of here, we put in the eye because that's the number that changes. So it's going to go from 0, 1, 2, 3, and the 4 is never reached. We've seen this before. So our output should be, first of all, John, July and then Ryan Gmail and then June, July Maria Ryan. Because first those are going to be output here appear. Then the for loop is going to output. So let's see making sure that we are on Lecture 16 arrays. Let's just start this and as we can see, June and July, Ryan, those are the three that we did manually and then we have John, July, and Maria and a Ryan. Great. Well, I mean, that's that's amazing. So let's just add another one. You know, the Cloud is also joined. I mean, that's, that's pretty cool, right? So that's really nice. Let's, let's make sure that everyone is there and everyone is included here as well. Let's just start this and everything works totally fine as you can very clearly see. But now, well, first of all. Yes, but clouds actually wasn't output. So that's okay, that's kind of weird. But now, oh no, look at this. We are actually losing three of our students met. So only John and July are, you know, remain for this semester. I mean, that's, you know, it can happen. Can happen, but there's not there is no issue that's yes, there is an issue index out of range. So what is that? Well, what happens here is that all of a sudden we're trying to access something that doesn't exist. In this case, the student males only have two elements. So we can actually only count from, so 0 and 1, two elements. But in here, we're actually trying to access element 3, 4, 5, and so on. That doesn't work because, well, it doesn't exist. So what can we do about this? Because we've explicitly told it for, okay, I'm going to change that to two. But every time the student changes, we have to manually go in and change this. Well, that doesn't work. Of course there is something for it and then we can go student males that length. And that is always the length of the student males. And now it's going to go through this. So Maria, Ryan, and Klaus have joined us again. And now klaus will also be output because we have taken him into account. Let's see, there you go. Close at gmail.com, it's also output. So yeah, that is, that is the idea of arrays. It is basically a list. It can be of any variable types, so any datatype, as long as you put the brackets after it, can be an array. And in this case, explicit. Lee put in the strings. Here are some integers. The assignment works very similar to actually getting the output of whatever is in there. What is also important is that when you have defined how many entries are in an array, you cannot change the number of entries, so that stays the same. You can change the whatever is written at that position, but you can't change the number of entries in an array. Now there are some other things that we can use that actually do have this sort of dynamic list in it. Those are some other data structures that we're going to look at later down the line. However, arrays at this moment in time are at least a little bit important. This something that we can use later that's a little easier to understand in my opinion. However, right now, arrays are the thing. I would definitely encourage you to take a good look at this to really try and understand what is going on. If there are any questions definitely ask. Because this is like one of the, I would say one of the most important topics, but this is definitely an important topic. And just for a quick little aside here, I actually can tell a fun little story about this. So when I was beginning to learn programming and era's came up, I, in the beginning I did not understand them. This is why I prep this with saying, okay, this is maybe a little bit harder and a little bit more complex. And so I didn't understand them in the beginning. And I just I couldn't figure out what what I was doing wrong. And then I was like, I'm never going to use areas anyway. I don't need them at all. It doesn't matter. I'm always gonna do it like this. And of course, I mean, first of all, that's like the wrong way to approach this any way. You should never do that. If you're trying to learn something new. That is definitely not the right way to approach this. But in this specifically, there are just some things that you cannot do if you don't use an array or like we've later that like we're going to later see a list or some sort of different data structure. Sometimes you have to use these data structures that are different from just stupidly writing out string line by line. It works, but at some point it just gets very, very nasty, bad, it's just not good. So this is why I want to really encourage you to try and understand this. Maybe look at it one or two times. And if there are any questions, do feel free to ask. And like always, I'll be sure to respond. And I hope you found this useful. And yeah. 20. (C#) Multidimensional Arrays in C#: All right, welcome back to the C sharp introduction here for the unity course. And in this lecture, we're going to take a quick look at multi-dimensional arrays. Now, after we've looked at arrays, now we're gonna take a look at multidimensional arrays. Now on I mentioned that this is just a very, very quick overview, just a quick glance at how those, how they look, and just a little bit of how they work. And let's just open the multi-dimensions script here. And I've already defined a multi-dimensional array. As you can see, we just put in a comma into the brackets. And then inside of it, we actually define one array and then the next area is also defined. And then another curly brackets around there. So basically there's two areas. Instead of one array, you can think of it as an array of arrays. In theory, that is something you can think about. Or you can think about this as a table where you have different rows. So if we were to write it like this, for example, say something like this, then you could imagine that this is the first sell, second cell and so on and so forth. And then all of a sudden it makes way more sense when we think about this. So you can have, you have two coordinates to describe these cells. And then this would simply be 0, 0. And that makes absolute sense. And then this is something like 0, 3 for example, and so on and so forth. And let's just, I'm going to copy something over. So if we look at this, so we can once again get the contents or the elements of the array simply by putting the bracket in and then writing to in the indices right now because we of course need two indices in this case. And 03 will produce something from the first array. So this 0 notifies the first array. Once again, we start counting from 0 and then the three simply means 0123. Therefore, it's going to output 25. And the second one, it's going to be the second array or the one at position one, rather an index one. And then with index two, so we're going to have 1, 0, 1, 2. This is going to open 5 thousand. So let's see if that actually is the case. Making sure that we are under Lecture 17. And the output is 25 and 50 thousand, exactly how we have imagined. And there are two things we have seen the length and now there's something else that is the rank. So this is basically how many rows there are. So as you can see that those are basically the rows. This has how many inner airway arrays you could describe it like that. In this case, Rose, I think that the abstraction of thinking about a multi-dimensional array as sort of maybe even an Excel spreadsheet is actually quite useful. And what we can also do is we can do for loops. And I'm going to quickly also copy this over m. And this would be a two for loops inside of each other. One that goes through the rows basically, and then one that goes through each of the elements themselves. Of course, in this case, the elements is the length. So the length is the entirety of all elements, right? We have eight elements in here divided by how many rows there. All right, so each row has four elements, as you can clearly see. So we have to divide the number of elements by the number of rows. This is what this calculation does right here. And then it works was also very important is that each of the inner arrays, where each of the rows has to have exactly the same number of elements as the others. So if I do this, then as you can see, an array initializer of length 4 is expected. So we actually need four elements in each of the arrays. So if I were to add another array, we also need four. That's just quickly mentioned. Let's just see the output for this as well. And then we are basically done with multidimensional arrays. I just wanted to quickly show this to you. So as you can see, 10, 15, 20, and 25. So the first, the first row is printed out and then 5500, five thousand, and fifty thousand, and then the second one is printed out. So that's kinda nice. In my estimation. And my experience, it is very rare that multidimensional arrays are used. However, I did want to show them to you because they do have some application some of the time. However, I really wouldn't worry about it if there are certain things that you don't quite understand about this topic, That's not too bad, like that's not that important. Areas themselves are way more important than understanding multidimensional arrays. They're just like sort of a bonus. It's good to know, It's good to have really not necessary. But anyway, if you found this useful, I would really appreciate a review from you. And if there are any questions, of course, you can always ask, I'll be sure to respond. And yeah. 21. (C#) C# Lists: All right, welcome back to the C sharp introduction for the course. And in this lecture we're going to take a look at lists. So after taking a look at arrays and then just a quick look at multidimensional arrays. Now we're going to look at lists which are going to make our lives about approximately a 120% easier. And so let's just take a look at the lists script right here. And first of all, let's remember the arrays. Instead of the areas. We had different email addresses from students as an example here, defined. And it was as easy as just putting in the, the datatype and then the brackets. And then we had an array of a list is a little bit more complicated or a little weirder maybe. But let's just define a list. Let's, let's initialize a list. So we're just going to write in list. Then we're going to make these angular brackets. And inside of those angular brackets, we're going to write the data type that we want to save in there. So in this case a string and we're going to call this males. Then going to equal new list of type string and then parentheses and a semicolon to end it. This is how you basically initialize a list. Right? So now we have a new list as the name new list suggests of type string, so we now can add to it. So let's look at some methods that we can call for this list. So we can, for example, say males dot add, as you can see. And then we can write, for example, maybe Jonah's no longer at Google, maybe he's at Yahoo at this point. I don't know why, but who knows? And then let's just copy this over a few times and then add a few sort of July and then we're going to add Ryan again and then Maria. So that is the add method, as you can clearly see. Now, the first thing that you should think about back was, wait a second. We had, we had to define how many elements they were in an array. Exactly. We do not have to do that in a list. A list is dynamic. So you can have 0 elements and you can add multiple elements and then you can later down the line, you can also remove elements. And yeah, that's, that's one of the good things, are great things about lists. So let's just log out, first of all, just males and then also log out mails 0. So this once again, the same access, the same axis operator that we have seen with the array, right? Just the brackets and then the number that indicates the index of whatever we want. In this case, it's going to be drawn at yahoo.com. And then we're just gonna see what happens if we logout males, just to see. So let's hit the play button and see. Okay, so we're gonna system collections generic list. So something that's not really useful to us, not really. However, here we can actually see John at yahoo.com gets. The logged. When we log out the first element of the list, or the 0th element of the list. I guess. We could also reassign values. So reassign values, this is very similar to the, actually it's exactly the same when we did with the array. So let's see, actually John switched back again. So John is actually at Gmail again. So in this case, then the element John at yahoo.com changes to John at gmail.com. We can also remove an item. So remove they go remove an item. And that would be if we call males dot remove. And then we can remove. So we can pass it a string. So we can say, okay, I want a specific string to be removed. So for example, July at yahoo.com. Now, for this to work, we of course need to know what element we want to remove of who don't know that, but we know the place where it is. We can also say males dot remove at and then put in a one. So this is equivalent. Now of course I can't do it one after the other because after we have removed the July, Ryan All of a sudden becomes the thing that stands at place one. Therefore, that doesn't work. If we want the length of that of a list, we can get that as well. So this would be, for example, important for, for loops or somebody like that. Then we use count. So the count variable is what we need. So this is the length. Length. Sometimes some people also call it the size or the count of the list. And in different, in different programming languages, this is almost interchangeable length, size, and count. But in our case, it is the count at this moment, in this, in this script, it should be three because we have removed one of the elements here, namely July at yahoo.com. And then we can also clear the list. So males dot-dot-dot clear. This will, this call will literally clear the list. So it's just going to completely wipe out everything that is in there. And let's just print out the count after that as well. So let's see what is going to happen here. We are going to have this. Well, we don't need this anymore. We're going to print out John at yahoo.com. Then we're going to rewrite the first one. Then we're going to say, Hey, how much, how many elements are in there? This is should be three. And then we're going to clear the list. So nothing should be in the list anymore and then we should have 0. Instead of that. Let's see if that's the case. But I'm fairly confident here they go. So first of all, we print out John at yahoo.com. Then we have three elements in the list. After we have removed the one element, and then after clearing the list we have 0 elements in there they go. So those are some of the things that we can do with lists. If you look at, so if we do mail stat, as you can see, there are some quite a few more methods that we could call. In this case. I just wanted to give you a brief overview of the list. It is if you understand arrays, you basically understand lists. And the great thing is that lists are just better in almost in every way than an area. Because they're dynamic. You can add to them. And their overall, I think a much nicer to use the arrays usually, right? So overall, I would say that usually it's best to always use lists. Because release no. Let's say positive impact of using arrays versus lists. There might be some very specialized things, but it's as with almost everything. You know, if you ask a 100 people, then you're gonna get a 100 opinions. So that's sometimes just how it is. Anyway, that is a short overview of the list in C sharp. I hope that this was useful to you. And if there are any questions like always, feel free to ask and I'll be sure to respond. And yeah. 22. (C#) C# Dictionaries: All right, welcome back to the C-sharp introduction for the unity course and this lecture we're going to take a look at a dictionaries. Now, dictionaries are basically lists with a little bit of a twist to them. So let's just open the dictionary script and see what we can see. So first of all, how do we define or initialize a dictionary? Well, we're just going to write dictionary. And then once again, the angular brackets. And now we actually have to specify two different types, or not two different types, but two types of data types. In our case, we're going to make a string and string. So these are separated by a comma. Now we're going to call this capitals. I have my reasons for that, which will be evident shortly. And then equals new. And then as you can see, it already basically gives us a suggestion here that we can just auto-fill with clicking or pressing the Tab button, adding the parentheses and the semicolon. And then they we go, we have a new dictionary. Now a dictionary works in the following way. So it basically maps. So let's just write this down. A dictionary maps a key. In our case, this is a string, right? Because this is the first data type that we have given the dictionary to a specific value, which is also a string. Now, this is basically the, the key value. The dynamic is called a key value pair because they come in pairs, right? And this will now be shown with capitals. The idea being that, well, if you have a country, which would be the key, that you will always have a certain value for its capital. That's pretty, pretty much easily understandable. And then we can just add new entries here. For example, if we put in Mexico, then we can put in Mexico City as the capital. And then let's just copy this over. A few times. Germany would be Berlin, and then we have France with Paris. And then last but not least, USA with Washington DC. So those are now some examples that we have added into this. We have seen previously in the, both the array and the list that we can get certain elements in there by using the brackets and then putting in now whatever index that we want. Now in this case, that actually doesn't work. As you can clearly see, 0 doesn't work because it actually wants a specific key, not the index. So if we put in a string inside of here and say Germany, for example, then what we're going to get is Berlin, because Germany is the key for the value Berlin, z. No more errors. And if we go back here making sure that we are at Lecture 19 and dictionaries. Then we can see Berlin gets logged out because is in fact the value to the key Germany. So this is no different than having a list. But instead of having the keys be the position in the list, we actually have something different. We can also remove an item. So for example, because I capitals dot remove, and then we can just remove France, right? And this will actually basically just delete this entry here. So then we cannot actually gets the, gets a value Paris out of it because it actually has. Then remove the entire entry year. And if we then go for capitals dot count, which would be the number of elements inside of the dictionary. This should then be 3 after we have removed France. As you can see, that is as easy as it goes. Yeah, and that is basically a, at the dictionary. A dictionary incredibly useful in a lot of different ways. It can basically map some data type to another datatype. In our case, we put a string to a string. There could be of course something else. For example, we might have the string to an integer, and then this would be, for example, the number of people who live in the country or the GDP or something else. So we can do, we could do all sorts of things with the dictionary. I can definitely say that it's best to play around with it a little bit as well. There are some more methods that you can call as well. Well, yeah, that's, that's roughly a short overview of dictionaries. And I hope you found this useful. If there are any questions, like always feel free to ask and I'll be sure to respond. And yeah. 23. (C#) Foreach Loop: All right, welcome back to the C-sharp introduction for the unity course. And in this lecture we're going to take a look at the for-each loop. So this is going to be a very quick lecture just shortly looking at the, at another type of loop. So after we have seen that we can use lists and we have seen how we can basically go through them with a normal for-loop. We are now going to actually look into a, another loop. This is called the for-each loop. So we can just type in a foreach as a keyword. And inside of the parentheses, we're going to define a new variable, in this case a string called male. Then we're going to write in the keyword in so i n, and then we're going to type the collection. This is going to be males. And then inside of here, you are going to be right, debug dot log male and they go. And that is the for-each loop idea is, you can basically just read it out loud and it's gonna make sense for each string male in males. And then we're going to do whatever is inside of the curly brackets. So in this case we're just going to log it out. There might also be some other things that we might want to do. One thing that is mentioned in for each loops, we can really change the collection. We can change the elements itself, but not the collection in its entirety. So we can't just remove something from the collection, then the for-each loop will break that we can only do in normal for loops, let's say. And even that, it's not quite what would you say? It's not advised. Right. But let's just see if this works. We don't actually need to specify any specific item in the for-each loop. Making sure that we are at Lecture 20 for each loop. Let's call this. So the first one, John July Ryan, Maria, and then we have separator, John July, Ryan and Maria. So everything gets locked as we would expect it to. And that is the for each loop. This of course also works for dictionaries or other collections. We're not going to look at other collections in detail. In this introduction. However, there are also others and this would also work for dictionaries in theory, right? That is just a quick, short look. I'm at the for each loop. I hope that you learned something new. And if there are any questions, like always feel free to ask and I'll be sure to respond. And yeah. 24. (C#) Namespaces: All right, welcome back to the C-sharp introduction here for the unity course. And in this lecture we're going to take a quick look at a namespaces. So what are namespaces? Well, let's just open it, the namespaces script and let's see. So I have told you from the beginning that we're going to ignore most of the stuff up here, most of what's written here. But now we're actually going to take a look at these three things. First of all, the using keyword and then whatever is written after them. So those are namespaces. And the idea of namespaces is basically of them as directories where certain classes are kept in, certain scripts are kept in. That's the easiest way to conceptualize them. And we can then access those functionalities and those classes if we are using them. So for example, there is a particular namespace for the UI of unity. So for example, there is something called a button, which is obviously a button that we can use in Unity. But as you can see, it's not, it doesn't exist. If I put in button here, it doesn't show anything. However, if I go up here and I say using Unity engine, wi, then all of a sudden this button here turns, turns this teal color. And this tells me, haha, I can actually use it. And I can use it because I have the Unity engine wi a namespace in here. And if we hover over it, as you can see, namespace, Unity engine wi. And we can actually use namespaces on for our self as well. So that also works. We can add one for the existing script. For example, like this, we just write namespace. Then we put in the name of the namespace. Usually, what I would say is that now that you have a name for your project, so that's sort of a convention. You have a name for the project. This, we're just going to call our project, in this case tutorial. And then you can also divide that with namespaces below basically. So you can make directories namespace inside of a namespace. But we don't need to do it like this where we land, for example, do some like namespaces. Namespaces, right? We don't need to do this. This also works, right? And then what I do is I just quickly copy this over and they go. Then we have the class instead of a namespace. Now, we don't necessarily need to do this. However, I'm going to show you just afterward done with this, how you can actually automate it there so that it automatically adds every new class that you create into a namespace. So then you don't have to do this marking here, so you don't have to select all of this, you know, control X4 to cut it out, Control V to paste it in, saving everything and then you don't need to do that. We can actually automate this. I'm just gonna wanted to show you how you could do that if you don't have a namespace on here. But usually I actually would recommend starting with a namespace anyway. Uh, but yeah, we don't actually need to define two namespaces. So in this case, this namespaces class would be accessible if we were like, if we're in another class, then we would have to put in tutorial dot namespaces, and then we can use it. Now obviously we are now right now in this specific blood bold directory, let's say so we can use it anyway, but because we have two namespaces here, we can also just do this namespaces. And this is actually going to save us quite a bit of, quite a bit of space here because then we can actually do everything like this and then it isn't indented too much because if we were to have, so for example, I'm not sure if Unity UI has even more namespaces below it, it doesn't. But some of them as you can see. So system that collection of generic has like three already. Well generic has nothing more but it might be, maybe it's like at some point and then it's generic W2 and in util dot core or whatever. So you can have multiple namespaces inside of each other. Therefore, it's best to, however, all have it in one line. Idea being that you want to sort of separate your codebase. So if you have a 100 scripts, then you just haven't flying around in your folders, then that can, well, first of all, it's going to lead to all my god, where's my script? Where was this? I don't know what this does. And with the namespaces, you can basically sort of create certain groups of scripts and classes that work together and have a particular purpose. So for example, maybe you want to put all of your enemies scripts into one specific namespace. So that would, for example, be tutorial dot enemies. Or you want to put all of your combat in things into the combat classes, into your specific namespace that would, for example, could be tutorial.com, something like that. And maybe you have some interfaces which we're going to look at in a later video, what that is in a later lecture. Some things that you're going to use throughout the code. You can, for example, put that into YouTube class tutorial dot util. Those would be things that would help with everything. So like the math, math F was sort of a util class in some ways. And where you have certain other things that you might want to put in a core namespace. So there's a lot of applications for them. However, right now, what I would say is that the most important thing is just that I would advise to definitely use them. And when I would also advise in our case, because this is a basically just a C-sharp sort of tutorial lecture on this. I didn't, I don't have that good of a structure here inside of the script folder. However, what I would personally advice what you do is that your script folder. So the script should always be the root namespace. So it, so everything, every script that would be inside of the script. So if I create a new scope, just for the hell of it, read this one. In theory or this test script. I would want this to be in namespace tutorial. And then if I have another folder in here, so for example, namespaces, then I would want every class that is inside of that folder to be the foil dot namespaces. So basically reflect your folder structure with your namespace structure. But let's not worry about this right now. That's just, just a warning that we don't actually need to worry about. And now we can actually also make it so that each new script that we create already gets a namespace assigned. And we can do that by going to Edit Project Settings. And then inside of the editor go down a little bit. And then as you can see, C-sharp Project generation, root namespace. And we're just going to say tutorial. And that's it. I'm going to save this by pressing Control S. And then we're going to create a new script in here. We're just going to call that, let's call it festive. Sure. And if we then open this script, then you can see generates with the namespace tutorial. And that's basically all there is for this moment in time. I don't think that there's anything else for namespaces is just a short little thing. And it's not the most important thing, but it's still something that, especially when you really want to make a project in really wouldn't make a game, then I would highly recommend looking into the, also the conventions of namespaces. We're going to take a look at that at the end of the C-sharp introduction. Once again as well. However, i just something to think about and kind of important for expandability and also to understand code red understandability of the code in order to basically have is semi separated function novelties of the code in sort of different places, right? That was it for this lecture. I hope you found it useful. If there are any questions, like always, feel free to ask me, I'll be sure to respond. And yeah. 25. (C#) C# Methods: All right, welcome back to the C sharp introduction here for the kinetic cores. And in this lecture we're going to take a look at methods. Now methods are a big part of programming and C sharp in general. So, well, let's waste no time and see what we can see by opening the methods script. Also making sure that we are at on Lecture 22 methods. And let's just open it up and see what we can see. So we have seen, let's say, methods in a little bit in the abstract, where we had a few methods for strings, for example, we've seen those. We've also seen that we can access methods by the dot operator. And yeah, that was a few things of methods that we've seen. And now let's look at an example of, for example, once why methods would be really nice and really good to use in certain circumstances. And also, let's just, let's just start here. Let's just take a look at. So right now what we want to do is we want to calculate the factorial. So we can do that by very easily actually just them doing something like this and then setting it to whatever we wanted the factorial two to calculate. Factorial is just everything. So if we wanted to factorial five for example, this would be exactly this five times four times three times two times one. So this is the factorial, this is how it is defined. And that's simply what we wanted to calculate right now. So then we set the factorial num, and then we have a for loop that we go from num minus one until I is bigger or equal to one. And then we actually count down that. And then we say factorial times equals I. And this is exactly what this does because factorial starts out at five, I starts out as five minus one. So at four, therefore, we go through and we times I that so 5 times 4. And then the next one is going to be 5 times 4 times 3, and so on until we reach one, and then we are done. So if we now do a debug dot log factorial is, and then do this way around a go. And then we save factorial. And we can actually print that out or log it out into the console. And let's just start at C. What this is, factorial is 2, 120. So factorial 5 is 120. Now. And now my thing is, well actually what I want is I actually want factorial for eight different numbers. I went factorial for example, for seven and I also wanted for night, and I also want it for D. And I was thinking about having it for 11 as well. And now we get into an issue because now we have to take this and maybe copied like eight times or something like that. And that's of course. That's absolutely ridiculous. It doesn't make any sense. This is what methods of war. So we can basically take the entire thing here and put it into a method and then call it as often as we want. And to do that, what we're going to do is we're going to go outside of this stored method because this is also a method by the way. And this method gets called when a certain, uh, when the game basically starts. Let's easiest way to conceptualize this right now. So we're going to go outside of the curly bracket here, and we're going to type in the following. We're going to type in public int and then the name of the method factorial. Inside of it, we're going to write int number, and I'm going to quickly explain what this means. Now, we will have an arrow here for the time being. The worry about that, we're going to fix that soon enough. I'm just going to quickly explain, explain like the idea of this method and what, what all of this, this is called the access modifier. We're gonna take a look at that a little bit later as well. So basically what the access modifiers are and what exactly they do. Public in this case, simply means that we can access it from anywhere. We also have the return type. So this is the data type that is returned from calling this method. In this case, it is an integer. As you can see here in the start method, is actually void. And void means that it returns nothing. Integer in this case obviously returns an integer. Then we have the method name, then we have the parentheses. And inside of there there are parameters and the parameter type is first given and then the parameter name. In this case, we want to give it a, an integer called number. And this number is basically this num here that we've used here. So let's just take this and copy it over. Now a few things we don't actually need. We only need to get factorial here. And we don't actually need to do this. And we don't need to do this anyway. Let me just need to do actually we can even make it a little bit easier by doing number, they go. And then here we just need to replace this with number and then that's it. And then also return, return factorial, the ego. And that is the factorial method now done. And what we can do now is if we just quickly copy this over and we say with a method, then we can say factorial than 25, something like method is. And then we call factorial. And as you can see, it's actually here with this sort of cube in there. And then we pass it, for example six. And then let's just copy it over it in and let it do five as well, just so that we can make sure that it actually works. But I'm fairly certain that it does. And you can see, we can also see that this is a, has two references because in this case, our method is called 2 times 1, 0, 1, 1 here. And let's see if that actually does something, but I'm fairly certain that it does, yes. A 120. And then with the method is also a 120 when we pass it to the five and the six is 720. So methods are a incredible tool and something that is really, really important. There are some core tenons of methods, for example, that each method should only do one thing and one thing alone. The names shouldn't be too long, something like that. But those are some conventions that, like I said. Oh, so we're going to take a look at the end of the C-sharp introduction as well. Right now, methods are simply a way of basically containing certain instructions that we want to do. A lot of times. It is a way of knots of reusing code without copying it. That's also a sort of a way we can conceptualize methods. So it's a way of reusing code without copying it. And that's always a good indication if you've copied. So if we would need this factorial eight times R code, like I said, that would be a prime candidate for making sure that there is a method out of this because it, it makes sense if as soon as you start, maybe if you start using something twice, you can debate about, well, I don't really need a method for it. But when you start using a particular lines of code, like for a third time, it's time to make a method out of it. I think that that's that's a good rule of thumb. Yeah. But that is the C Sharp methods. I also wanted to mention that sometimes people can refer to them as functions. It, it's basically the same thing. Usually, in my estimation from what I've heard, a methods are tied to objects and functions are sort of like free floating. But usually you can, there are synonyms for each other. So I can say that this is C-sharp functions or C-Sharp methods. Usually anyone should understand them to be the same. But there could be some people who are like really pedantic were like. That's not correct. Writers like I am well, yes. Correct. This would be a method. A function is something slightly different. However, you can use the terms interchangeably, right? That was it for the methods lecture. I hope you found it useful. And like always, if there are any questions, feel free to ask and I'll be sure to respond. And yeah. 26. (C#) Method Overloading: All right, welcome back to the C sharp interruption for the unity course. And in this lecture we're going to take a look at overloading methods, or also called method overloading. So this is basically a continuation of what we can do with the methods and yet so little, something that's semi important to know what you can do. So let's just open the overloading script here and see what we can do. So the first thing that we're gonna do is we're going to create a new method and we're going to make it return an integer and call it multiply with two parameters, a and b. And as the name suggests, It's going to return a times B. Now of course, defining such a method is nonsensical in the sense that, well, it's fairly easy to just write a times b. And even if we have multiple parameters in here, so a, B, C, D, E, F, G at maybe the whole alphabet. We could always write it as a times b times c and so on. So usually this type of method isn't something that we really need. However, it is easy to demonstrate with this method, the concept of method overloading. So what we can do is we can log, so debug dot log. And then we can do multiply and then for example, something like 10 and three. So this would return 30. So let's just see if that actually works. Making sure that the method is correct. Lecture 23, overloading as the scene and let's see, yes, it is 30, so that's pretty good. And now you can do is we can define a second method, also called Multiply. Now this is, this is where it gets interesting. So it has to have exactly the same name as this one. So the name has to be the same also with upper and lowercase as will be the same. However, what we can do is we can change the number of meters and then this is a, an overloaded method. So for example, if we add the integer c here as a parameter, and then we make this, and then we can return, for example, a times B times C. We could also return, by the way, this is just as an example. We can also return multiply AB times C. For example, we could, we could return that, right? So we can, we could call the other method. And as you can see right now, there's no errors. Even though I have two methods with the same name. How does, how does the program know what which one to take? One has three parameters and one has to permanent. So if we copy this with Control C and then Control V pasting it in, what we can see is if we start with the multiply, we can actually see that there's, did I write that wrong? I didn't deny NO. Multiply. Am I going mad? I'm not going mad okay. For a second, I was thinking that this is multiplied. Now what we have to do is yeah, we have to start that. Sorry, Exactly. So as you can see, one of two. So there he realizes that there are two methods called multiply it. And he's like, Okay, one of them has int a and b and a, uh, take this arrow, click on this arrow, then we can see in a into B and C. So then we can take this for example, we can say 524 for example. And then also close debug dot log. So this works as well. And then the last thing that we can do, for example, is multiply with floats. So we're going to return a float and we're going to multiply floats once again, return a times b is nothing crazy in this case. And then we can also copy this. And then for example, say something like 3.512 for F, for example. And this is, It's the same, it's the same name for all three methods. The only difference is that part of the method signature. So this would be the, the access modifier, the return type, the name, and the parameters. They are. Some of those things are different, namely the perimeters and also maybe the return type. And that is method overloading. It can happen sometimes, sometimes there are some methods that have different number of parameters because maybe there's something that can, you know, a method can be called one or two or three different parameters, and either of them is okay. So we can call the method with one or in this case with 23. And then of course we could add to this, right? We could also have a multiply with a, B, C, D, and so on and so forth. But just, just shows you that you can have methods that are defined multiple times with the same name but different signatures, like the different number of parameters or different types of parameters. And that allows you to overload those methods. It's an important concept to definitely have seen. And best thing to do here is to just play around with it a little bit, especially after methods. That's a sort of a next big step. And then the method overloading is a little bit on top of that. So I would definitely suggest just playing around with it a little bit, just defining a few methods using some of the previous keywords and structures and statements that we've learned to play around with that a little bit and just see what you can see. And then that's the best thing I can. Basically advice at this point, right? I hope that you found this useful. If there are any questions like always, feel free to ask and I'll be sure to respond. And yeah. 27. (C#) Classes and Objects: All right, let's continue with the C-sharp introduction here for the unity course. And in this lecture we're going to take a look at classes and objects. Probably one of the most important topics in C-Sharp in this case. Because C sharp, as you might know, is an object oriented programming language. And classes and objects are sort of one of the most basic building blocks of this type of abstraction. So Object-oriented programming is just an abstraction. So we say that everything is an object. And certain objects have members and methods. And we can create new objects and new classes. And yeah, let's just take a look at this. So instead of opening our classes and objects script, we're actually going to create a new script by right-clicking the 24, 25 classes objects folder and then going to create and then C sharp script. And we're going to call this file fruit. Right after we have created the fruit file, might get a warning here. Don't worry about that. That doesn't matter right now. What matters is that we have created this fruit class and this fruit file. And I'm going to double-click it and we will then open it. Now as you can see, there's a bunch of stuff in here, and we actually don't want that. Also to note, we now have two files open. So if you also open the classes objects, you're going to have both of those open and you can switch them. They're just simple tabs like in a browser basically. And those are the different classes that we have open right now. Now, we're gonna do is we're going to delete everything inside of here. So we're just going to mark everything. And then we're going to hit Enter so that everything is deleted. And this model behavior and this colon will also delete so that we've only written in here public class fruit, and then the curly brackets, and that's it. That's all what we want inside of here. And then inside of our classes and objects, we are once again instead of the start method and we could actually already do something, but let's think about a fruit. So we want to create a new fruit. Now, when we think about a fruit, well, what does a fruit half? So we're thinking about sort of attributes of a fruit, right? So one of thing that a particular fruit might have is a number, a name, right? So mango, that's, that's a name for a fruit and a banana. And would also have an apple, right? So that would be a name for a fruit. So all fruits have a name. I would say that makes sense. Now we could think, well, what different attributes does a fruit also have? Well, maybe it has a sugar content, right? Maybe you and I live healthfully and you want to know, I want to know the sugar content, you know, let's just be safe about that. So better to know that, right? So that's the sugar content. And then maybe one other thing could be a color for example. So we're going to make a new string called color. Right? Now those three attributes, this is what we would call fields. So those are fields of this particular class, fruit. And you can think of them as basically the attributes that every fruit has, right? So every fruit has a certain sugar content, every fruit has a certain color, and every fruit has a certain name. Now, there might be way more attributes than we have right now. So there are way more than these three. However, we're going to stick with these three just to make it simple, right? And now we can actually already use this and we can actually already do something with roots so we can actually create a new fruit right here. So what we're gonna do is we're going to type in fruit. And as you can see, it actually already suggests this for us and we're going to create a new fruit and we're going to call it a banana. And then we're going to say equals new fruit, and then end with the parentheses. So as if we are calling a method, as you can see, there is no error here. And this shouldn't be too crazy. So this part of the construction is simply once again a declaration of a variable. So this is nothing like there's no difference between this year and in x. Basically, this is simply a new variable that we have created. And this variable, in this case is of type of fruit. So the only thing that has changed here is that we're not using the primitive datatypes. So the primitive data types for string and integer and so on and so forth. Now we have created sort of a complex data-type, but we've created our own class and that's called Fruit. And this year the assignment basically. And we have the Mu, we have the new keyword that we've seen with the lists before. And now, however, we have created a new fruit. And this might seem a little weird at first. However, this is basically just the, uh, like, uh, it is basically just like a method call. However, in this case, we coded the constructor. So this is a very special method that is related to classes and objects. In this way, we actually create a new instance of this class. And yeah, so let's see what we can actually also do is we can use this a banana and we can do with the dot operator. We can actually, as you can see, you go and access the color and we can access the name and the axis, the sugar content. So we can actually access all of these fields as you can see, as they're called. And, and yet they can be accessed. So for example, we could say, well, a banana dot name equals a banana, for example. Which would make sense. However, in the issue here being we would actually have to go through each one of those and create a new a banana dot name and then 80 nano a banana dot sugar content equals, I don't know, like 15 and so on and so forth. Well, that seems kinda tedious. However, we can actually make it a little bit easier by using this constructor and actually making our own construct. So there is a easy way with that we can make our own constructor. And that is by pressing Alt. Enter. As you can see, then you get this Generate Constructor suggestion here, and we're gonna do this and now we can pick what members we want. So we can just have to set the tick here. We have to say, okay, what members do we want to have as parameters in the constructor? We're just going to let, have everything selected and say, okay, and then as you can see, it created a new constructor for us with parameters in here and also the assignments. So the, this keyword simply refers to the object that is being created. So you have to separate basically two things. The class itself is basically a template from which we then create an object and that then exists. And then we also have the parameters that we pass in through the constructor here, and those are also separate. However, they are then saved into the object. As you can see here now, we're actually getting a, an error because there is no argument given a that corresponds to the required formal parameter name, and so on and so forth. What that just means is we don't have enough parameters in here and then we can fix that. Well, we could fix it either by putting in banana and then a fruit content and then a color. Or because what happens is that before it worked and so why doesn't it work now? Well, we have actually overridden the normal constructor, the, the, the basic constructor. And that is simply, that was this. So fruit. Oh, there you go. And then this one, we have overwritten this because and we've created our own. And this basically when you have a new class, this normally gets generated. So this is always in there, even if you don't see it. However, as soon as you make your own constructor, this basically doesn't work anymore. And now we have to explicitly type it in and say, Okay, this is now also constructor and then this works. As you can see now, there's no more error. But what we can do now is we can create a new fruit. So for example, we can say a, an apple. An apple is a new fruit. And this has the name apple. And it has a sugar content of 10, for example, and a color of red. And this way we have now created an apple with the name Apple sugar content of 10 and then the color red. So for example, we can say debug dot log, and then we could say an apple dot name. And then let's just print out or log everything, the sugar content and also the color. Right? So let's see if that works. Making sure that we're on lectures 24, 25 classes and objects. And let's just run this apple 10 and read, well, isn't that great? That's pretty nice. That works out really well. And let's just quickly go back once, one more time to the fruit here. And one of the thing that is to note that we're going to look at in, I think, two lectures. It is the public key word here. We're going to figure out what that is. We've seen this very shortly with the access modifier, sorry, with the methods. So this was the access modifier. And we've seen this with the methods that we also made them public. This simply means that we are allowed to access these variables in this case. And yeah, that is basically the idea I'm just going to quickly put in. So this is, so this is the constructor very important and used to create new instances. So that's basically Class of this class. So you can say, well, this is a new instance. So here the, an apple is a new instance, or you can say this is a new object. This sort of sort of interchangeably. But yeah, that is the basic overview of the of classes and objects and also how to create them. One more example, just so that I will leave you with, is, you could think of, for example, a, you could think of an enemy. And an enemy could be a class. So we would have an enemy class. And then an Emmy class, for example, has integer hit points, and so on and so forth. And that is maybe a thing that's a little more closely related to game development itself. However, I think there's fruit example also shows a little bit, I would definitely suggest to look at the next few lectures before you try out a few things. So I would say that probably until we are at Lecture 28 through where we talk about the properties. I think that you should look through those and then when we're done with them, then I, then I think that then you can play around with the classes and objects. There's a few more things that we need to look at before you can, before I would suggest for you to really dive in, of course, you can dive in at any moment and try out new things as soon as you want to. But that's just a simple suggestion from me. But yeah, that was it for the classes and objects lecture here. Very important. If there are any questions, really feel free to ask and I'll be sure to respond. And yeah. 28. (C#) Class Members: All right, let's continue with the C sharp introduction for the unity course. And in this lecture, we're going to take a look at class members. And this is basically a little bit of a deepening of the understanding of the classes. So let's take a look at our fruit class and think back. So we had the, these variables that we declared. And those are fields, right? However, they are also members. So members are basically a fancy way of saying, well, this is part of a class and a field simply means that this is a variable. Now, other members include, for example, a method. So let's just create a new method. So for example, a public void, eat fruit, which simply is going to do the following. So this is, we get the formatting right. There you go. This is simply going to debug dot log fruit. And then we're going to say, this.name has been eaten, right? So in this case, we actually don't need the, this keyword here name can be simplified. So we can also just write name because the program knows well, it means this name. However, personally, sometimes use the, this keyword even though it is not required. In my case, I think sometimes it makes it a little bit clearer and you can see a little bit closer, okay, this, with the, this keyword, it is meant a, basically a member or a field of this particular class. But that is very much a stylistic choice. You don't have to do this. I just wanted to mention, however, now we have a new method called eat fruit. Now what can we do with this? I mean, is it as easy as just calling, for example, an apple dot fruit? And yes, Actually that is how easy it is. So an apple dot eat fruit as you can see, and you can also now see that there are some other methods that we could call. Those are simply things from the object class that every object is, is basically a part of. However, we have created this, eat fruit, and we're going to call this, and we're gonna see what happens. So if we do this, then after the red output, we should see that fruit, apple has been eaten. That's what the output should say. So let's leave. That actually does work. Well once we start they go and fruit, apple has been eaten. Well, that's pretty good. That's pretty good. Yeah, and we can do all sorts of things with these methods basically. So in this case, it is a void so it doesn't return anything. However, we can of course, also do other things and can create different methods that return different things. So we're going to see, for example, in upcoming lectures is when we trained our access modifier, maybe we have to do something. They are something like that. And this is really cool. So we can create the new classes that not only have different variables in them, but they also have different functionality where we can use those variables, possibly manipulate them. And yeah, so this is one of those things. So all in all, the members are basically just parts of the class. So in this case, fields that are basically just variables. And then there are also new methods that we can call for the on those objects and on those classes, but on objects we can call them on the specific instance. In this case an apple. We could of course also say a banana dot eat fruit. That would also work. Yeah, and that is, I just wanted to show you. So mainly the method. That's pretty cool. And then also just making sure that you understand basically the terminology at least a little bit. It's not like absolutely necessary, but I just wanted to give it to you, the soil that you know it. So those are fields. And then this is a method and this is a member and fields are also members. Yeah, so that's it for the class members. Little lecture. I hope you found it useful. If there are any questions like always, feel free to ask and I'll be sure to respond. And yeah. 29. (C#) Static Members: All right, let's continue with the C-sharp introduction here for the unity course. And in this lecture we're going to take a look at the static keyword. We've seen a few key words before, but now the static keyword also a part of classes and objects. So we're going to still need the fruit class. But we also need orally this flu class and the fruit script in this case, and the static keyword script as well. Making sure we're on Lecture 26, static in this case. And let's just open the static keyword script. And before we can do anything in here, we actually have to modify the fruit script again. And we're going to create a new field, and that is going to be a static fields. So we're going to make a new public static int. We can call this num of fruits. So this is a new static field called a num of fruits. So right now it doesn't do anything. It's just sitting there as you can see, if I hover over it, you can see that it says field, static, int fruit, number fruits. So there's nothing really special going on right here. Now what we're gonna do is each time this constructor is called, we're going to say num of roots plus, plus. Now this is going to have an issue because this is actually right now not actually initialized. So we're gonna say, well, this is equal to 0 because right now there are no fruits, right? So this num of fruits is number of fruits. Let's just, you know what, let's be, let's be good programmers and else actually call it number of fruits because the BER, that really doesn't change a lot when it comes to the name. So number of roots equals 0. And then each time one the constructor is called, we're going to call this number of socket. That's okay, That's fine. And then we eat the fruit. We can also say, well, how about then we are actually going to minus-minus it because it has been eaten. So the fruit is God, even though it's not quite gone so that it's technically not gone. Let's just think about it like that. Well, okay, but I mean that doesn't get us anywhere because if a fruit has that, so we can create a new fruit, for example, a banana again. And we're going to say new fruit. And it'll say nothing. Amino k is. Then we can say, well, a banana dots a number of, well, number of Froude, number Froude. Why you can't access it? Well, that's weird. Well, if we look at this, this is not callable because this is a static member or a static field in this case. But also static member could not be cooled from the a banana object. Well, we actually have to call it via the class. So we actually have to type in fruit dot number of fruits. And this is the crazy thing about, well, let's actually just debug dot log this. Because then we can actually see this should be one after we've created this new food, let's just save that. It's actually the case. And then I'm going to explain to you why the static keyword is so awesome. Interesting, So that is a 0. We can, I'm sure that we can figure out why. So let's think about this. Well, because we have put this in this constructor and on in this constructor. Well, that is of course a real issue. So let's just copy this over and put it in here as well. So that if we call this constructor, we're also going to increase the number of roots. Then I am fairly certain that we're going to have one day ago and there's the one. Now why is the static keyword so great. Well, we call this by using the class itself. So we say fruit dot number of fruits. Why is that somehow a special or something like that? Well, this variable, this field in this case, is actually completely independent of each particular fruit. So in the case of number of fruits, it doesn't really make sense to store how many fruits that are with each fruit. Because first of all, it really doesn't make any sense because why would a banana know how many fruits there are in this world wall, like a particular banana. That grill doesn't make any sense. But also that each particular fruit would know how many foods there are. You know, that's, that's, that doesn't make any sense. So you could also call this sort of a global variable. I say this with, you know, with caution, but you can think of it as a global variable that exists ones for the class fruit, not once for each of the objects that are created from the fruit. So it exists only once. You can think of the static, can also be, you can also have static methods in this case. So let's say static. And then we could just say avoid for example, and then just get number. Let's do it. Yeah, gets number of fruits. In this case. We're actually, let's make this an integer and then have this return number of fruits of this. Of course, in this case, it's not really necessary, however, just to illustrate the fact that we can also have static methods. Static methods most of the time of I wouldn't say most of the time, but some of the time can be, for example, sort of helper methods. They can be sort of generate generator methods. So you could have something like a public seek fruit, generate fruit. So then it would generate a random fruits. So for example. Yeah, however, the idea of static is just that it is not tied to a specific object, it is tied to the specific class. So that's really important. Sometimes, especially in the beginning. The difference there can be a little bit misunderstood maybe or maybe a little bit harder to grasp. However, I think that once you, once we get going and we see a few more examples of this, I'm sure that we are going to figure out like a little bit faster. Okay, what is this? How does this work? What is this exactly? But right now, what is the say that the static keyword really useful? And you can also see this one last thing. So if I do this dot number of fruits, as you can see, that doesn't work because this is exactly the same thing as we've done before, where a banana dot number of roots doesn't work because number of fruits is not tied to a specific object of a fruit or as instance of a fruit presses tied to the class. That is it for the static keyword. Yeah, it's, it's incredibly useful. It can be really useful and there is, there are plenty of plenty of real applications for it. And in the future, we're definitely going to see more and more of it as we continue through the C3b introduction, as well as going into the unity part of the course because they are, we're going to have plenty of static methods and also fields. So, yeah, if there are any questions though, feel free to ask and I'll be sure to respond. And yeah. 30. (C#) Access Modifiers: All right, let's continue with the C-sharp introduction for the unity course. And in this lecture we're going to take a look at access modifiers. So access modifiers, we've seen the public access modifier before when we were talking about methods and also when we talked about classes. And now we're going to basically dive even deeper into those and see what the different types are and what well we can make happen with them. So for example, Let's just open our access script and also make sure that we open the person's script that is in here. That is, we're going to use the Person class in this case, and we're going to not continue with the, uh, with the very nice fruit class. We're going to stick to person right now. So what does the person have? Well, let's just say a person has a first name and a person has a last name. And those will both be public. And those would now be accessible everywhere. Now everywhere, of course, doesn't mean like literally everywhere. However, inside of our program, everywhere in the program, if you create a new person, first and last name could be read out. Okay, that's that's fair, that's not too crazy. We could also think, well, maybe we have an integer h and we want that to be protected. So protected int age. And this now is a little bit more complex. And this basically is accessible for the class itself. So everything that I write inside of the curly brackets here between for this class, right? So if I have a method in here, I can go to age and change it and use it. What I end. This also can be accessed, so accessible, so accessible for all by itself, right? So this is by the class itself, end classes derived from this. Now that's a little bit weird. Okay, What is that? Well, this is cold in heritance and this is going to be talked about in a future lecture, very important. However, I wanted to show you the protected keyword, in this case, in it's usable in the person class, but no, not outside of it. So while I could use, I could make, for example, now let's make the last one and then we're going to see an example of this. So the last one would be private. And this is, for example, a string. So for example, a Social Security number. That seems like something that would probably be best to be only accessible. Accessible only by this class. Because we wouldn't want either to be read out, nor would we want this to be changeable from outside. So if we create the constructor by once again pressing Alt and then into Generate Constructor, we're going to have all four fields as perimeters. And we're just going to stick with this. I like this. Grace. Then we could, for example, think of something like this. So we could also make a private or public method. So let's make a private bool is of drinking age, for example, we could do that and this could then return a Boolean age bigger or equal 21 if we are in the United States, if we are hurdle in Germany, for example, this would be 16. Depending on what type of liquor. Let's just leave that out of the equation. Let's just stick with 21 in this case. As you can see, age, no issue. I can access it in here. I can change it. Also social security, my I changed it in here. Not an issue over if you now go into our access script and we're going to create a new person. So we're going to create a person of Frederick. So shut up to you. And we're going to create a new person. And of course, firstName is rhetoric, and then the last name is going to be Johnson. If I can type it, they go and he's going to be 26. And social security number, I mean, I have no idea. So let's just put something like this in there. I like it, right? So that's great. Now we have a new object called frederick, so new variable called phosphoric. And we're going to say debug dot log. And then we can, for example, say Frederick, that firstname. That's totally fine. We can print up FirstName. We can also, if we look at the suggestions, print out the last name. As you can see, I mean both the age and the social security number missing and was also missing is the method that we have created. So we can like do this, but both h and social security number and not accessible. That's exactly right. So we have because the protected one would like I said, only accessible in the class itself. So while this now is a private, maybe we say, okay, you know what, this can be public actually, like. That's something that is maybe important for people to know. Like I quit EC of drinking age. We can also say, have a method that's called is a voting age, for example, right? And then of course, depending on the country, this changes. Let's just abstract this away and just say, okay, or drinking age is now 21. And we can do this and we don't even have to reveal his age in theory, right? So we can just do something like and let's just say something like Ken, person, drink. And then we can just say boo rhetoric dot is of drinking age and then call this, and this will now return a Boolean and B. We can access this. So let's just see, of course, with a 26, the person can't drink. So let's just see when we have Lecture 27, access open. Frederick Johnson, can person drink, true? Let's just see if we change this. So if we change the name here, or rather the age to, let's say 20. Which of course in our case would be. Less than 21, then Ken person ring should turn to false. There you go. That's exactly what I wanted to see. And the great thing about this is we don't even have to make the age open, right? So that's really good. So in our case, we of course we wouldn't know. Okay. Is the person over 21 or below 21, however, we wouldn't know the person's age directly. This is partially useful in our case because there's no real use case here. This of course, just to illustrate it. But yeah, these are the three access modifiers, public, protected and private. Usually, this is just something that's a very good practice. Everything should be private except if there's really good reason for not having it private or it needs to be accessible from outside. This changes a tiny bit when we talk about specifically working in Unity. Because we actually have an added benefit. They are because we can use some interesting way in which we can still sort of see what the private values hold without making them public. What we're going to look at that in, when we actually get to unity right now in C sharp, I would say use private variables, which you can then. Also, if we really need to use those, we can change them by adding in a guitar or a setup. Now a getter or a setup are basically ways in which we can still access variables, but have them still be private. So I believe that if we go here, we should actually know we can't actually do that. Maybe we can do it with this. We actually can't okay, that I thought that we could generate those automatically. I believe that there is a way to generate those automatically. Actually. He actually says that we should use a property. This is going to be what we're going to use next time. So in this case, a setup would be, or a guitar would be a public string. Get social. I'm just going to call this set number for just a moment. And then we're going to return this dot Social Security number. And then a cetera simply means to set this. This would be a void and as a string Social sec number. And then this one doesn't return it, but this one is specifically exactly this one. So let's just do this and then put this, they go, right? So this would be a guitar and a setup. In our case, of course, not really what we want because we don't actually want from anywhere in the sort of security number to be gotten or even to be set. However, in our case, just as an example, this is sometimes useful. However, I'm just going to delete it again because usually, and we don't use getters and setters in C-Sharp. Usually in C Sharp we use properties. And that is exactly the thing that we're going to look at in the next lecture. So this was it for this lecture with, for the access modifiers. I hope that this was useful to you. And I would of course, really appreciate a review from you if you found useful until, up until this point. And like always, if there are any questions, always feel free to ask and I'll be sure to respond. And yeah. 31. (C#) C# Properties: All right, welcome back to the C sharp introduction here for the unity course. And in this lecture we're going to take a look at a C sharp properties. So we have seen a whole bunch of stuff concerning the classes and objects, some access modifiers. And now we're going to take a look at properties. So for that we have the property script and a student script. Yeah. And the students script, once again, it's just a blank class without any of the Unity stuff and the properties script in this case has our start method. But we're going to start here in the student's script. So we could, for example, let's say a student has a public String first-name, right? That, that would make sense. That a student has a first name and let's copy this and also make a last name out of this. Now, this does work. But first of all, he says, Hey, you know, maybe what you wanna do is encapsulate this field using a property, and that's actually what we're gonna do. So first things first we're actually going to make the naming convention here for a property is a capital letter. And then as you can see, what we're going to start with is we're going to have these curly brackets. We're going to remove the semicolon at the end. And inside of those curly brackets, we're going to write, Get and Set. And with that, we have already declared a field. And you can see we now have, instead of having the slow box here, we actually have this wrench and this register simply signifies that this is a field or a property rather. And let's do this. Let's do last name as well. They go. And let's also do, and this is one of the cool things that we can do. So for example, we now have those two properties. And that's all fine and well, and it's like, Okay, what does that mean? What does that do? Well, obviously what we can now do, let's just make a new student also. Let's, yeah, let's just make a new students. So let's do a student. Let's call them Yes, sure students, why or why not? And the new student. So for example, we can actually call student dot first name as you can see, and student dot last name. And as you can see here as well, we have oh, there you go. Well, wait a second. Let's do that again. There you go. So last we have get and set so that we can see we can either get this variable, in this case, this property, or we can set it. Now what we can also do is we can make it well, you know, so maybe we can change our firstName button. You have the last name that is set in stone. So we're going to make it a private set. And if I then go, as you can see, I can still access the first name and the last name, but it says private set. And if I now say, for example, something like Arnold Smith, then it's going to say the property or index, our last name cannot be used in this context because it's set X is inaccessible, simply means we have a private set. However, a public good. And that is one of the very easy things, or easy ways that we can set the variable to private or public. And what we could also do, for example, is we can define a new string called fullName. And by using the properties we can say get. And then instead of just putting in a normal semicolon here, we can actually basically returns something that we want to have returned. So for example, we can return this dot firstName plus, and then a space, this dot last name. And with this we have actually, this could also be a method, but we can also just put it into a property like this. And there is no set at this at all because the full name is never said that this is never have variable that we change. We only ever get it via the first and the last name. And as just quickly add a public. Now let's actually add a, an age as well. So in age with a public getter and a private setup, right? And this is as easy as just adding this. This also has the added bonus that of course, when we, for example, set something, we can actually, instead of just sending a variable, we can make a method call or something like that, right? We can, for example, in theory, have a private variable behind everything. So we can have a private variable, age, for example, let's say, Well, let's say nothing. And then what we can do is instead of having the sort of not a visible thing that's like invisible with these strings. We can do this and then say return H here, and then this one and the private set for example, we can also do and this would then be aij is equal to value. So value is simply what we would pass there. And this also would work. I just wanted to quickly show that we can basically have an excess of for this variable that is then private. And then last but not least, let's just make a quick Student constructor here with string firstname. Let's do it properly. Firstname, the ego, string, lastName, and an integer h. And then we're just going to say firstName equals firstName, lastName equals last name, and age is equal to h. Now once again, we can set this age because we are even though the center is private, because we are in class. And we can, for example, if we now actually give this student a name. So let's say Jordan Smith, 31, something like that. Then of course we can debug log some interesting things. So for example, we can debug lock student dot FirstName. We can lock student last name. We can also look full name, right? That was the interesting thing. And we can lock the age. However, we can't change the age because as you can see, the setter is private. You don't even have a setup. Here. The seller would be proud as well and we could change the firstName, but we don't choose to write. So let's just quickly see the output of this now this shouldn't be too crazy, of course is just going to Jordan, Jordan Smith. And then the full name and then age as we have said it. And just to quickly mention, why, why would we use C Sharp properties? Well, I mean one of the lake, Let's see. Really good reasons is that we can decouple the getting and the setting, the accessibility basically, right? So that is one thing that we can't really do with normal fields and normal variables inside of classes. That doesn't work. And also with having the, having this, so having the getter and the setter and be able to basically have added functionality into it. This might actually work to make it so that first of all, if we want to change something that we can do it very easily. And second of all, we could, for example, keep a count. How often something is set, how often something is get whether or not that might not be the best example. But we can basically add functionality to the getting in the setting of a specific variable which might be useful. So for setting might be something like we always want to save the previous setting so that we can change back or something like that. Then we can always save that in a different variable that might not be accessible outside or whatever. So there are quite a few applications, but the main takeaway, I think is pretty cool is that the getting in the setting can have different accessibility settings basically, right? That was already it for the properties. It's a relatively big part in C-Sharp. But once you see it, it's quite obvious. Usually inside of Unity is a little bit tricky working with properties because Unity doesn't really is not a big fan of properties, all things considered. But we can get away with using them if we also have these single fields in this case. So if we have the private fields, then we can basically work around this. But yeah, that was just a quick introduction for the for the properties here. Like always, if there are any questions, feel free to ask and I'll be sure to respond. And yeah. 32. (C#) Inheritance: All right, welcome back to the C-sharp introduction here for the unity course. And in this lecture we're going to take a look at inheritance. So continuing along with it, the classes and objects we're now going to look at basically subclasses and inheritance. And for that we have for classes at the ready year animal, cat, dog and inheritance. If we open all of them up, then we can see that inheritance is just should be empty. I mean, all of the classes should be empty or they're filled depending on what you chose to look at. However, the important thing here is that the animal, the dog and the cat don't have anything fancy here. So they don't have a start Method, they don't have any inheritance. They're basically just empty. And at the inheritance script here has the start method where we want to implement stuff. Well, we're going to start in the animal class. And let's just think, I mean, an animal has a lot of different things that like attributes that it might have and field. It might have been. The only thing that really interests us right now is a protected string. We're going to call this the species. And remember back, so protected variables only accessible by subclasses. And it's right. We remember that we had that in the access modifiers lecture where we have seen that there was public, protected and private and protected sort of sits between those. And we're going to see how we can use this to our advantage right now in inheritance. So let's then create two methods here, public void run, which is simply going to debug dot log the following. So it's gonna do this dot species is now running. And then we're just going to copy this over. And we're going to hold the other method, eat. And then we're just going to say this species is now eating. And that's it for the animal right now. Now let's think about this. What are some animals now, of course, I already have the dog and the cat. However, you could also have a BVA or moves or arrow, great white shark for example, there are a lot of animals. And of course, what they all have in common is that they're an animal, but they also all have different things they can do. So maybe there's going to be something interesting here. But the first thing that we're going to do is inside of the dog class, we're going to make it so that it inherits from animal. How do we do this? We go after the public class dog and then we type a colon, and then the class it derives from, so in this case, animal. And what does this bring as well right now, as you can see, nothing has happened here. It just seems to work. Nothing interesting going on here. What we can do is we can now, how about we make a new public dog? So this is a new constructor here. And well, we know that this is a dog, so we don't really need to change the we don't need to give them any parameters. What about the Species, so like, Okay, well, this dot species. Well, how can I access the species? This is not, I, I haven't declared anything well, because we have derived this door from animal. And inside of animal we have a protected string call species. This is why we can change it here and we can, for example, say dog. And now the, every time we create a dog that's an object, will have species, the field, basically set to dogs. Now let's also make a public method called bark. Debug dot log. Not an arrow but normal. Let's do Sure. Let's do bark, bark. Why not? They go. I mean, it could be anything, but let's just do it like this. And then let's also go into the catalyst. Actually, just copy this over quickly because that's going to make it a little bit easier. And then also make this animal. So this inherits from animal. This is a cat. You will do a cat and it will actually meow please. How about that one? And then we're just going to meow once because that's great, right? And now we have a cat, a dog, and they're both animals. But now the question comes in, well, I mean, what can we do now? Really like where? Where's the interesting thing here? And the interesting thing comes from this. So let's say we have a dog called Fluffy. And this is a new doc just for the sake of argument. Now fluffy, right now. Fluffy. If I can write it correctly, the ego can bark. He can eat, and he can run. But if we look back, so if I say he's going to run, if we think about this width second, this is a dog. I mean, we have not specifically said that a dog can run, an animal can run, but we have not like redefined this method inside of dog. However, it still works. And if we look at the definitions here, so if I do put in fluffy and I hover over so selected as you can see, bark is of dogs. So this was the method in sort of dog eat is a method inside of animal. Same with running. Those are both methods that have, we've created in the animal class and the dog class. And let's just say for the last thing we're gonna do, a fluffy dot bark, right? And let's see. So what we would expect here is we would want to see dog is now running, then we dock is not eating and then bark, bark, I believe is the what we want to see. So let's see if that works. So let's do this one. Yes. As you see, dog is now running, log, is now eating and bark, bark. Everything works totally fine. We could of course, do the same with the camera right now. So let's just do that. Cat whole him whiskers. Sure, that's a great name. Whiskers, dot run. Just the same. And whiskers can also eat. And also meow in this case because whiskers is cat. Now, one interesting, very interesting thing. Because both of those, Let's consider this a little bit, Diego. Because both of those are animals. Can also have an animal called Henry. And this is, for example, in new cat right? Now, this works. Previously. We've always seen that the data type that we have given a variable must be the same as, let's say the constructor that we create. However, because cat is an animal, we can also save this new cat inside of an animal. A variable that works. And when we call Henry dot-dot-dot eat and Henry dot run, for example, let's switch this around so that we have it everywhere correctly. And then I'll also just put in a little divider year so that we know which is which. So after the divider, so we should see the whiskers. So dog run dog eat than bark, cap run cat eat Meow, and then cat and cat run again. Yeah, exactly. So we have dog dog bark, we have cat cat, meow, we have kept running cat ED. Even though Henry here is an animal. So the m, This is an animal. It can do everything that an animal can, but it can't do what? A cat. So Henry, Henry.me. It's a can see doesn't work. It's going to throw an error because animal, it's not contain definition for meow because we don't know currently that's Henry is an animal, a cat. We know that it's an animal and reason animal definitely. But Katas like Mao doesn't work. Henri that the male does not work. However we can do, is we can cast Henry to a cat. If we know that it's a cat, we don't necessarily, but in this case, this is one of those moments where we can have a more complex costing, let's say. So there's two ways to do this. We can, for example, type in, sorry, we can type in Henry as cat, meow, as you can see. That works. So this is the as keyword simply is almost the same as costing. And we can also do basically two parentheses, putting cat, as we've seen before, then do henry and then do meow. So those would be two ways where we can cast Henry to a cat. Now, we know that Henry is a cat. That's why this works. If we, for example, do something like this. So dog and then say bark. I wouldn't. I mean, let's just see what happens. You're right. I mean, that's because we can of course do that as well and see what happens here. And you can see we get a null reference because this of course, doesn't work because Henry is not a cat. Henry is a, Henry is not a dog. Henry is a cat. I've said cat and dog so many times. I don't even know where to add anymore. So there you go, meow and another meow. Like always. If there are any questions, feel free to ask and I'll be sure to respond. And yeah. 33. (C#) Polymorphism: All right, welcome back to the C sharp introduction here for the unity course. And in this lecture we're going to take a look at polymorphism. Now, this is a giant word for such an easy concept. When you really think about it, it's actually ridiculous. So let's just take a look at our inheritance class and our animal, dog and cat clauses. Now what we have done is we had last lecture a method called Eat, which basically just output this dot species is eating now. And what we're gonna do is we're gonna say, well, you know, dogs and cats might eat different things. Therefore, what we're gonna do is we're actually going to override those methods. Even though they are a method call, a quote by the Animal class, We are now going to make a new functionality in them and we're going to type in public knew, void, eat. So the without the seven, preferably they go. Idea here being that the, that the entire signature of the method is the same except for this new. And this new basically signifies a, this is going to be a new method with the same name. And we're going to say this dot species. Now is now eating some steak, for example, for the dog. Right? So let's put this in and then we're going to copy this over quickly to the cat. And then this one is maybe drinking some milk. And they go, we have now created to eat methods inside of our inherited classes. And what we're going to see is that all of the, each instruction, so to speak, are going to turn into exactly what the specific dog or cat is, you know, what they are eating. So let's just do this and see what happens here. If we go down, as you can see, dog is now eating some steak, cap, is now drinking some milk. And now the very interesting thing, because here, Kant is now eating. Why is this cool, even though this is a cat? Well, let's remember back here, henry actually is an animal. Therefore, animal that eat gets cold. And here cat dot-dot-dot gets cold, they see. So that is also one of the interesting things that you can have multiple different definitions or implementations, in this case, a different implementations of the same method. And depending on what the subclass is, we can have specific different implementations of it. And even when we call it on the animal, it might have a different, a different implementation than on the derived classes. One other example of that that I've seen quite a few times is you can have a sort of like an area, so an area class. And then this might have getArea as the method. And then the algebra class can be inherited by, for example, a square and a circle. And while the area of, you know how to get the area or the area is the same in the sense that it's, let's say for example, meters squared, that's always the area. But the way to get to the area for a square is different than from a circle. This is why you need different implementations for basically the same thing that you want to end up with four different subclasses as an example, right? That is actually it. If for polymorphism It's not the biggest thing. And I also really wouldn't advise to dwell on it too much. It's a big word for a very simple concept. And I think that even in the yen, one last thing is that the method overloading we've already seen in Lecture way, way a goal that is basically also polymorphism. It simply means that you have multiple methods with the same name or multiple implementations of a method, and they all have the same name. So that would also be considered polymorphism. I would say that that was actually quite easy thing to understand. Way easier than the name polymorphism would suggest. And yeah, that is basically it for this lecture. I hope you found it useful if there are any questions like always, feel free to ask and I'll be sure to respond. And yeah. 34. (C#) Abstract Classes and Methods in C#: All right, welcome back to the C-sharp introduction here for the unity course. And in this lecture we're going to take a look at abstract methods, an abstract classes. The idea is we are going to continue along with the classes, inheritance, things side of C Sharp. And we have three scripts here, the abstract, the abstract animal, and the beaver. Number one, right now the beaver first, or we're going to look at the beaver, be empty. The abstract Animal class should be empty. And then the abstract is once again the one with the star method, but also empty. And the first thing that we're going to do is the abstract animal is going to get a new keyword here, and that is the abstract keyword. So we're going to make it this specific class abstract. What that means, we're going to see in a few moments. But first of all, let's fill this class with some familiar things, such as a predictor protected string, species, species, and then also a public void run method. Debug dot log with this dot species is now running. Now we've seen this in the normal inheritance before that we had a run method. And now we're going to define an abstract method as well. Now the abstract method is going to be very interesting. So this is going to be public abstract void. And we're going to call this the animal sound method. And then we're just going to close this with a semicolon. And as you can see, that's it because, and this is the interesting things. So abstract methods have no implementation, implementation inside of abstract classes. Right? That is the very interesting. And the interesting thing there is that the derived or the subclasses, right? They need to, they must implement this individually. That's also very interesting to see. And the abstract keyword for specific, for specific methods can only be used inside of abstract classes. So if we don't make this abstract, then soon enough we're going to see is abstract but contains in a non-abstract class that doesn't work. Therefore, we need to make this class abstract so that we can use this abstract keyword for a specific method. Now, the beaver, instead of deriving from animal, is going to be an abstract animal. The idea is almost basically the same. The difference here just being that, well, I wanted to show the abstract keyword with a similar example that we've shown inheritance with. And the beaver now it has an arrow here and it says, doesn't implement the inherited abstract methods, abstract animal, animal sound. Now what we can do is we can actually fix it with the multiple ways we can either go to the, actually, it's easier to go here and say implement abstract class. And then it's going to do this on his own. So we're going to overwrite the animal sounds method. And then he's immediately going to be like throwing a new exception here. We don't really need that because we. Well, I mean, I don't know what the beaver says, but let's just say it says something like OK. And then we can also make a public Vivre. And then we're gonna say this dot species is equal to Beaver. And yeah, that is basically the idea of an abstract method. So we need to use the override keyword here in order to sort of override the abstract method and make it clear that this is basically the implementation of the beaver. We can also think about, think back to the cat and the dog. If they were to have the abstract animal as there, the superclass, then we could imagine that we would do exactly the same. And then the animal sample, basically the wolf and the meow that we have previously in the normal animal and the cat example and the dog example we have implemented basically as a like on our own, on the, on the subclasses themselves. In this case, however, we've actually implemented it right here. In the abstract class, was the, well, basically the idea. And then the implementation is down to each of the derived classes. Now what we can do, well, let's get bury the beaver. Why not? I'm Barry the beaver and berry. Well, first of all, run because that's what he could do. And then it's going to know it's not going to eat. Actually, he can't eat right now. But what we can do, and this is the great thing. Barry can do animal sound. So very can do animal sound. And then there's one more thing that I wanted to show you when it comes to the abstract classes. So abstract animal, right? We can just say abstract animal, just like we've done with the animal. And say for example, we have Mary the beaver run out and then we have a new beaver. But this works. Now, Mary is an abstract animal. But if we want to do the following, so we wanted to do abstract animal Larry, because let's go with it is a new abstract animal. What we're going to see is this doesn't work because we cannot create an instance of the abstract class or the interface abstract animal. So the idea here is that we cannot create instances of an abstract class. That's what's really important here. So an abstract class, this is why it's abstract. It can't have, you can't have an abstract animal in this case. Now, when we really think about it, it does make sense that some things. So for example, even in the case of an animal, we could imagine, well, I mean, having just a new animal doesn't really make a lot of sense when you really think about it. We do need to have sort of a more specific thing. So even a beaver that's like way more specific than an animal. So we could imagine, well, making animal equals new animal doesn't, it doesn't really make sense. So in this case, this is yet, so we can't really create new instances of abstract classes. And they however, do have the added benefit of having the animal sound here. And then also, if we have Mary, for example, we can still say Mary dot animal sound. And Mary is still going to say, Ah, so let's see. We would first have beaver is now running and then, and then on. The first of course, is from bury the beaver and then the married the beaver has done at the second one. And we can of course call this because remember when we didn't have this implemented, we actually had an error in the viva class because those abstract methods must be implemented, right? So as you can see, I did choose the word must year. They must be implemented. There is no other way. And yeah, that is the basic introduction to the abstract class and the abstract method. Also in this entire like object-oriented programming ecosystem, incredibly useful and incredibly interesting. But for now, I believe we're going to leave it at that. Like always. If there are any questions, be sure to ask and I'll be sure to respond. And yeah. 35. (C#) Virtual Methods: All right, welcome back to the C-sharp introduction here for the unity course. And in this lecture we're going to take a look at virtual methods. Now virtual methods, much like the abstract, the abstract counterparts, they're very similar. They can be something that has to do once again with implementation in subclasses and not. So let's just take a look at the abstract animal again. And let's add our good old favorite, the public avoid eat method. And let's also added the debug log. Let's say this species is now eating. This is something that we have of course seen numerous times, Not quite, but we've seen this before. And now instead of just having this a normal method, we're going to make this a virtual method. Now, at first glance, nothing has changed because the idea of this virtual method is that a, this is basically a member that can be overridden by the derived or the subclass. So in the case of the beaver, we can choose to override it or not. Now in our case, let's do overwrite it. And what we do is we simply do the same thing that we've done with the abstract method just because that just is not a, it's not a must. So we don't need to do it overwrite. And then as you can see, it is actually already presented here. And in this case, if we call base dot-dot-dot, this is what happens. It actually cools the virtual method here. But in our case, we actually don't want to call that. Sometimes it might be the case that we know we do want to call that. But more often than not, I found that you don't really want to call that as well. And then let's do this. Dot species is now eating some wood. For example, because of course, we're dealing with beavers. And now we can, if we go back into abstract script, for example, both Barry dot-dot-dot and also Mary dot-dot-dot. We'll be happy. So as you can see now, it's also very important is once again, because Mary is an abstract animal here. Barry gets beaver dot, Marie gets, gets abstract animal, dot-dot-dot. This is basically the same thing that we have seen with the polymorphism. However, in this case, because we have an overridden method, both of the coals are for the overridden of thing that the BVA has done. Even though Mary is an abstract animal. She's also a beaver. And this is why at the beaver implementation is called, in this case, for the virtual method, right? That is actually it. For the virtual methods, There's nothing fancy about it. As you can see, there's a lot of overlap in a lot of those things. However, there are quite some subtle differences. Like I said, an abstract method must be implemented by a subclass or Dr class. A virtual method can be overwritten, very important. Also very important. A virtual method can exist in any class. An abstract method can only exist in abstract classes with, and that was it for this lecture. I hope you found it useful if there are any questions like always feel free to ask now be sure to respond. And yeah. 36. (C#) C# Interface: All right, welcome back to the C-sharp introduction here for the unity course. And in this lecture we're going to take a look at interfaces. So interfaces are something that is very similar to abstract classes, but somehow still a little bit different. So as you can see, we have the interfaces of a plane and a bird script here. And we're going to create a new script as well. And there's going to be a new C-sharp script code I flyable. And we're going to ignore this one and the error here, or rather the warning. And we're going to just double-click on the AI flyable. Get rid of everything that's inside of here, also this, and instead of a public class, this is going to be a public interface. It, now the name is going to turn sort of this yellow color. And inside of it, we're going to basically define a, an abstract method. But it's not going to abstract, it's just going to be basically the return type, then the name of the method, the parentheses, and that was it. That's literally all we need to do to put into the interface in this case. So the ith label interface can be implemented by a certain classes that well should have the ability to fly. Of course, the plane and the bird of both have the ability to fly. Therefore, both of them are going to implement the AI flyable interface. It's the same idea we put in the colon here. And then we can see, hey, doesn't implement interface members. So we're going to say, okay, let's do them. And then we simply have to implement the method fly so that this can be called. In our case, what we're going to do for the plane is it's going to simply log starting the jet engines. Engines, they go. And in the bird, we're actually going to have something very, very interesting here. We're actually going to say, well, this is an animal. You can also, we could also say that this is an abstract animal. We're just going to say animal. And it's also so two comma i flyable. And then we have to implemented the interface as well. And here we are going to do the following. We're going to say debug dot log, flapping. Let's do flapping. Its wings. They go. And as you can see, the bird now is an animal and an eye flyable. And those really are not. They shouldn't be like mutually exclusive. Why? Right? Because of course, if you are an animal, you can fly that, that makes sense on a plane, can also fly. What's important is that a class can always only inherit from one other class. However, it can have multiple interfaces implemented. And let's just see how this would look inside of our interfaces start method here. So we're going to have a list of I flyable. And we're going to call that things that can fly. Because that's literally what the AI flyable interface basically tries to show us. And we're going to say things that can fly dot add. And then we're going to say it, new bird. And we're going to copy this and say new plane. And then let's just add a few. Let's make it a little bit random. Bird here, a plane here, and the bird here and maybe a plane at the end as well. They go. And then we're just going to have a for each loop at the end here. And now the interesting thing is instead of having this be bird or plane, we can have this I flyable, call this flyable, and then look into the collection things that can fly. And then call flyable dot fly. And now why is that such a interesting and crazy thing? Oh, sorry, there you go. Sorry, there you go. Why is that such crazy and interesting thing? Well, we have defined or implemented specifically jet engine or the wings in each of the classes that have implemented the eye flyable interface. But we are still calling the fly method on the flyable interface. So what will happen? Well, we would want to see is exactly this. Well, this is right now collapsed. So let's make it not collapsed. And then as you can see, flapping its wings and then starting the jet engines, Stirling engine flapping its wings, flapping its wings, starting the dish engines flipping, flipping and jet engines. So even though we have cold everything on the interface here, on the interface as a data type, we have still gotten the actual implemented methods. And this is exactly the great thing about the interface. Because as long as we know, okay, something is an eye flyable. We can always call fly on that. And it's always going to work. And then the great thing is we can also then convert it sort of into an AI flyable interface. And it will still work that we can say, okay, let's do the fly method on this. The, one other interesting thing I had with this that are actually was like a real use case that I had in Like sort of like hobby game I was programming was that I had. So it was basically imagine like a 2D RPG, let's say, like Zelda. And so like the old Zelda, let's say. And you were able to talk to specific things. So you are able to talk to certain people, of course, right, NPCs. But then you could also press the top key, for example, for a specific console or if there was a stove, then you can say, hey, what does that weight? And you can click and sort of talk to it in more or less. And I implemented an I talk bubble interface. And that I talk about interface then gave me the ability to basically whatever the thing is, talk to it, basically having the talk method, void talk or even spring talk, something like that. And I was then able to, once the implemented this in, for example, an NPC or whatever, I was able to then do the implementation there. Whoever the main thing that was looked for was I talk I talk about yes. Then talk to me. And yeah, that is the interface can be used in numerous different things and I'm sure we're going to see a few examples of that in the actual programming when we get to unity. Right now, this is, yes, this would be it for the interface. I hope you found it useful like always. If there are any questions, feel free to ask and I'll be sure to respond. And yeah. 37. (C#) Enums: All right, let's continue with the C sharp introduction here for the unity course. In this lecture, we're going to take a quick look at enums. Enums are basically a sort of the last like big data type that we're going to look at. They have the ability where we can sort of, it's sort of a pre-defined list. Let's just take a look. So we have two scripts, the game difficulty script and at the enum script. Let's just open the inner loop first. And let's immediately switch to the game difficulty script. The idea is that There's two ways or sort of two places where we couldn't define an enum. We can either define an enum in its own script or we can define it in sort of another script or, oring a class. Personally, I think that it's best if you put them into their own script. However, sometimes it might be easier to put them just basically in side of the script where they belong. So we have the enum game difficulty and we're going to define easy, medium, and hard. And as you can see, this is the way that an enum sort of works. We have public enum and the name of the enum. And then the individual sort of predefined things that it can be for us. For the game difficulty, it can either be easy, medium, or hard. So those are the only three things that it can be. This is why, for example, a switch statement with an enum is really useful because you have very much only predefined things that it can be. Therefore, that's some application where this can be really useful. Now, we can also do is we can in theory. So let's say, for example, enum language and define language. So for example, German, English, French, or something like that. And then we have created an enum inside of this enums class. Like I said, sometimes can be useful, sometimes not because it was, you want to access this outside of the class. Then of course, you need to make it public and also you will then need to call enums dot language. So it can be a little bit weird sometimes. But anyway, let's create a new deck game difficulty, for example, call it game difficulty equals game difficulty dot easy. So this is the way that this is written. So this creates a new variable of type game difficulty and then sets it to the value easy. We can also do the same with the language, language and make it language dot English, because that's what it is. And if we were then to debug dot log this, so for example, game difficulty, and let's copy this over and debug debug lock language. Then. Well, let's see what we can get out of this. Some interesting, well, easy and English. So it is literally exactly what we have written in here. So that's also kind of nice that we can simply outputted. And this gets output. Why would we use enums instead of an ANOVA, for example, like a string or something like that. Well, in a string we can always make an arrow. We can mistype something or something like that in an enum. We always call it by calling the name of the enum and then dot and then whatever are the predefined values for it. Therefore, we can't really mistype anything. Yeah, and that is basically already it for the enums can be really, really useful for certain things. Best thing is once again to just try around with it a little bit, see what you can see. And then I believe that in the future lectures, especially when we look at more than we're going to see some examples of those as well. So yeah, that was it for this lecture. I hope you found it useful. If there are any questions like always, feel free to ask and I'll be sure to respond. And yeah. 38. (C#) Exceptions & Try and Catch Statement: All right, welcome back to the C-sharp introduction here for the unity course. And in this lecture we're going to take a look at exceptions. So what are exceptions? We've seen a few of them already when there is an error. Basically that is what we could call an exception. But let's just open the exception script here and let's see what we can see. So first of all, we're going to make a new integer array here with two integers. And then we're going to say debug dot log. And then we're going to say numbers three. I mean, for that matter, we can also do numbers two, and this will basically throw an exception. Now what is an exception? Well, let's think about it like this. Let's just say, let's make it Hello. I am also here is another output that we're going to do after we call numbers two, which of course doesn't exist because numbers only goes from 0 to one, because 0 is the first index and then the second index is one. So let's just call this an end. As we can see, we're going to have index out of range exception. Index was outside of the bounds of the array, and then everything after it did not get hold. Now, why is this exception? Why do we need why does this happen? What is going on here? Well, we have of course made a mistake here. The mistake in this case was that we are trying to access a a number or something that doesn't exist, and therefore it's going to throw an exception. Now, we can do something about this. And what we can do about this is we can basically make sure that we don't do that even if an exception happens, everything still continues. So I basically commented this out and we're going to create a new method for this. Just to show this, we're going to call this the divide method. We're just going to divide float a and by float b. So we're going to return a divided by b. And famously, you cannot divide by 0. So if d equals 0, what we're gonna do is we're going to throw new exception, cold or a message inside of it. You cannot divide by 0. So let's just do that. So let's do debug dot log. Let's do divide something like ten divided by five. And then a second one. We're going to do 22 divided by 0. Let's just call this like it is. And let's see what happens. Let's start. And as we can see, we're going to get an exception here thrown. You cannot divide by 0 exactly the message that we have put in here. What we can also do is let's just put in a 22 divided by 0 as well. Let's just put it in like this. And as you can see, that actually doesn't work because 0 is a constant. So we would need to do something like float z and I'm not even sure, okay, this one works because the, this is a variable and it doesn't check variables. If we do that, we're going to get in, we're actually gonna get infinite. Very interesting. So infinity, which of course. You might say, Well, I mean, that's that's pretty good, isn't it? That's okay. I would have to guess that it will break a lot more things than having the exception thrown in this case. So why? Why do we need this? What can we do? Well, we can do the following, and this is a great thing. What we can do is we can do something that's called a try and catch. So we're going to put in the try keyword. And then we're gonna put in the keyword that has parentheses after it. And then inside of here we're going to do exception e. And then let's just put the debug inside of this. And let's also say have a debug here. And we're gonna debug log. Let's see warning the exception. And let's, yeah, let's just do that. And let's also, for example, put in another one. So a 120 by six or something like that. This is the exception of this is the normal one and this is just one after it. So let's see what happens now. Let's call this. And as you can see, two and then we get the, the system exception. You cannot divide by 0. Now this is not an error anymore because what we have done is we have quoted the exception with this catch. And what has made. And what possible here is that we can then basically continue along. So if I were to do this and I say, after trying and catching, then what we can see is the following, that the code will continue and resume after this try and catch, and it won't stop. This is why a try and catch, you know, sort of thing is really good. There also is something called Finally, that we can use. And this finally basically gets cold in whatever happens here. So we first try this and we're going to catch this, and then we're going to finally do this. Whatever basically happens whether or not we catch a, an exception or not. This finally gets cold. And at the end here idea is that, well, okay, exceptions, I'm kind of getting it, but why do we need them? The idea of is that we throw an exception instead of the program crashing. That is one of the big things. So an exception is thrown when usually this would actually call like lead to a crash. But we can then try this with certain things. We don't always know where exceptions might be thrown. However, sometimes we do know and then we can basically catch them with this try and catch statement here. And ideas are being, once again that we can then hopefully either with the catch, Do something about it or make it so that we can fix an error that might occur later down the line. So this, of course, maybe wouldn't be the best idea to do this. We could also do it a little bit differently in especially within Unity itself, we can also throw an error. So debug log era also would work. However, in this case, I actually think having this throw an exception is actually totally fine, right? That is it for exceptions. That's just a quick little short overview. Once again, it's nothing to, let's say exciting or it's nothing too important actually. But it's still good to have seen this once before, just so that you know, what's this try and catch means and what an exception is. So if that was it for this lecture, I hope you found it useful. If there are any questions, always feel free to ask and I'll be sure to respond. And yeah. 39. (C#) Basics of Generics in C#: All right, welcome back to the steep drop introduction here for the unity course. And in this lecture we're going to take a quick look at a generic. All right, so let's just open the generic script here. And we also have a pair script already at the ready. And we're going to create a generic script. So we've already seen something about generics that was, for example, a list. And you can see this is list and then t inside these angular brackets. And then we were able to just put in basically any type of a variable in there. So any datatype we were able to put inside of the angular brackets and it just worked. And this is basically what we want to create right now. So we want to create a class that is a generic class where we would be able to put in any type of variable or datatype. And I'm going to show this with a class that I use for myself on a semi-regular basis, I would say there is something that is very similar called a tuple. I believe that this is under system, System.out tuple, right? And you can basically, as you can see, you can do 12 or something else. The issue with a tuple is that while you can basically put in multiple different datatypes, you can never change them. So you have a set it once and then it's done. And this is why I have basically this pair class that we're going to create right now. So it's fairly easy. We actually put the angular brackets in and then we're going to put in x and y. Those are usually signified with a, an uppercase and one singular character. But in theory, you can also call it x2 or whatever. But x and y is going to be fine. Then we're going to have a new, a new field here, which is going to be x first. And then this is actually going to be a property gets set. And then we're going to have a public why second, which also getter and setter. And then we're going to have a public. Oh, sorry, Let's do one more. There you go. Public pair x first, y second. And then this is going to be this first SQL to first. And this is equal to second. And that is already it for the pair class. This is how easy it can get. We will first need to really wrap your head around this. What does this mean? How does this work? Well, if I put in a string, string, for example, then this would simply be a public string. If I put an integer animal, then this would be an integer and this would be an animal. You can really use it for whatever you want. And the x and the y simply gets replaced with whatever datatype that you put in when you declare the variable. So for example, we can put in a pair called int string. And let's just call this example one. No, wow, Okay, let's call it pair one, y naught, which is a new pair of int string. And then inside of here, we put in 2005 and for example, a yes. And the great thing is that we can then afterwards say pair one dot first is for example, equal to, to talk to 200. So we can actually change this up. And if we then for example, say pair with animal and string, then we can call this p R2. And this is a new pair of animal and string with for example, a new bird. And new bird and a string. Sure. Because, why not? And then we can, for example, also call first, which is an animal dot-dot-dot. So this is a pretty cool thing because first is an animal, we can then just call the eat method on this and it will simply just work. So the idea of generics, this is like a very little, like very basic example, right? Like not too complicated. Because in theory, at least in my personal experience, I found that it's very rare that we need like a very complicated new generic for anything. Anything else is usually also doable fairly easily. There are some times where they might be applicable. This is why I'm showing this as an example. But usually, I gotta be honest, it's very rare that they really come up. If they ever come up. We have seen this and then we can of course expand on this. But for right now, this is where I will leave it. Like I said, a very basic overview of generics. However, like always, if there are any questions, feel free to ask and I'll be sure to respond. And yeah. 40. (C#) Basics of LINQ in C#: All right, welcome back to the C-sharp introduction here for the unity course. And in this lecture we're going to take a quick look at a link. So what is linked? Well, let's just open the link into script and see what we can see. So this is going to be a very basic look at link, or also known as language integrated query. And we're going to have two examples right now I'm going to show you how you can basically filter a list. And then I can, I will also show you how to order a list by a certain parameter, let's say. So the first thing, we can get a new list which only contains the yahoo.com males in this example, for example, where it won't be like, I want everyone who has the yahoo.com mail. I want those. Well, we can actually get that by, first of all, having this using System.out link. Very important. So we need to be using this namespace and then we have access to new methods on our list. So as you can see, all as parallel queryable average, we have the concat method, we have a few methods here. And the method we are going to be using is where. So this is basically a method that allows us to filter. And now we're going to have a, an interesting Basically thing that we're going to look at, which is going to be a lambda expression. And that is going to look like this. So we're going to have a male, then we can have this arrow basically, right? This is basically a, an equal sign and then interest bigger than. And then here we're going to write mail dot contains yahoo.com, and then that's it. And this basically filters this. Now this returns a new, in this case, it returns a new iron innumerable. If we do to list, nope, not to string but to list. Then this is going to return a new list at which is probably what we want. But what is this year, right? So this might seem a little weird. I don't understand this. We've never seen the arrow before the lambda expression. What is this? Well, the idea is that at the wear takes a funk, as you can see, system.out.print. And what is a funk? Well, a fungus, basically a variable type or a datatype that stores a method or function. Now fungus defined as having a string, in this case as the input and a bool as the output. So this is what the string bool means. The mail. So the, each element is always the input in this case, right? So each of the elements is the input. And then we would want the Boolean as an output. Okay, is this inside of our new list or not? And then I'm going to say, well, if it contains yahoo.com, then it's going to be part of a list. If it doesn't, then it's not going to be part of a list. And that's actually as easy as this to be filtering this for people who have seen things like who've worked with SQL for example, it's similar to that in a lot of ways. And for the second example, I'm quickly going to just copy over something. So I'm going to copy a list of integers called high scores. They are basically randomly, but they're just random. And what we're gonna do is we can do high scores dot orderBy. This is the order by the method. And we can then say score and then just say score for example. So this would now order the highest scores. Well, by the, by the actual score. As you can see, the funk there is an integer and then it has another integer. So this is what is being compared. And this is basically once again, the actually this, yet this is what it's being compared. The idea is that we could, for example, instead of having an integer list, we could have a list of strings. And then we could order by, for example, the length of each of the strings, which would also work. This is basically the integer that's given back here. So we are simply returning the integer itself, therefore, ordering by it. This really is just a very quick look at this, a very basic look at it. There are way more things in here. But once again, like a lot of these, let's say later examples here or later topics. They're really not that conducive to. Looking at Unity itself. I just wanted to mention this once again, and also something that you can, of course, research on your own. And if maybe enough people are interested in this, I might just do an additional lecture. So the lambda expressions, for example, might be at least a little bit interesting. Although there are also other data types that we use or other ways we can use similar things inside of Unity. Well, yeah, that was basically the very basic look at link. Like I said, if there's enough interest, I might do a little bit of a deeper dive in here. For Unity itself, it really is not necessary. Those methods that I showed you, the wear on the order BY those are really nice and then maybe some other ones which could be useful. But at this point, I believe that those are the main two and everything else you can definitely look at. And if there's interests, like I said, just to ask if there are if there's anything unclear here, of course, feel free to ask and I'll be sure to respond. And yeah. 41. (C#) Events and Delegates: All right, welcome back to the C sharp introduction here for the unity course. In this lecture, we're going to take a look at events and the delegates. This is a, another more advanced topic. And we're just going to take a quick look at it and see what we can see. So the delicate script, let's just open that. We already have a float timer and a float targets time. Now, as you can see, this is declared inside of the class instead of the start method. And this is a very important thing because we're actually going to use one other method from Unity this time just to show this example. And this will be the update method. The update method is simply something that gets called once per frame. So you might have heard the games run at 60 frames per second. And then this method would be called 60 times per second. Now what we want to do is we want to create something where we basically call a certain method every 10 seconds or every second, we set this target time to, for example. And we're going to do that with the delegate and events system. Dear here is that let's just actually, let's first make a method that we want to call. So for example, private void test message. And we're going to put in the debug dot log, not an error, but normal log, just outputting a, outputting a message, something like that. And we want to call this particular method every time that something happens. And we can do that by doing the following. So we're going to make a delegate first. So this is a public delegate void. And then we're going to call this, let's say on ten seconds past, just as an example. And at the delegate, as you can see, must have the same signature as the method that we're going to call it. So this is void, so this is basically the return type and then also no parameters inside of here. So basically same signature as yeah, method, we want to call it. And then what we can do is while this is the delegate, we then have an event and then objects can basically subscribe to that event. So we're going to have a public event. And this is of type on ten seconds past, where this is basically the type of the event. And then we're gonna give it a name, for example, autocomplete. And this is how the event and delegates basically initialization work. So objects, objects can subscribe to events. Right? What we're gonna do now is we're going to add the test message method. To the event, and each time this event gets cooled, this method gets called. So let's say for example, onComplete. And then we're gonna do plus equals test message. And the important thing is without the parentheses, so we're only going to take the name of the method here. And what this is going to do is basically this is going to add this method to a list on this event. That when this event gets cold, then we're going to make sure that this test message schedule as well. So let's just add a way of calling this. So this is why I have these timer in here. There's a fairly easy way to basically added the timer. Now this is going to be a fair, fairly easy thing. I'm going to explain this targets time and then we're going to say timers equal to 0. And then we're going to say onComplete and call this and this is equal. And what is happening here? Well, each frame, we're basically going to add a little bit of time to this timer variable that is 0. And then we're going to check, hey, is the timer bigger or equal to the toilets time? If that is the case, we're going to reset the timer and coal onComplete. This should happen about every 10 seconds, as you can see, because the target time is exactly 10. Let's reduce this to something like four, so that this is going to happen a little bit earlier. And then every four years, every four seconds we're going to have this message be output. So let's see if that actually does work. Of course, making sure we're on lecture 38 events. Right now nothing happens. However, after four seconds have passed, we should see they go and then after another four seconds we should see another message. As you can see, Let's collapse this so that we can see each method message. And as you can see every four seconds, we're now going to get this message that is being output. Now, why is that such a great thing? Why, Why don't we just call the test message method in here? Well, we can see that this mess test message method is actually private. And maybe what we want is we actually want this to happen on a very particular moments and we don't want to make it so that every thing, every part of our program knows about every other part. So for example, maybe we have an HP system for an enemy or ourselves. And we then have a UI inside of our game that displays how much HP, either the enemy or ourselves as let's say the player, then what we could do, the UI could know, okay, this is the player's health and they could check every, every update frame, right? So every frame, okay. How about yourself, That's player have how much? Constantly updated, but we don't need to update it constantly. We actually only need to update it when the HP changes. And then we can make these events. So a delegate sort of on HP change. And then we have an event that then basically calls the UI method and says eight, the UK, the HP change. So this is the idea of subscribing to these events. We can separate our code very neatly. And, and there's also no real downside of having these events. So you can basically make like a 100 or 200 events, a fire. And if their subscribers great. And if you don't, you don't really lose anything because on this, in this case we call this, this wouldn't, right? So that is basically events now overall, this is also just a very short view and look into them. When, once we start actually using programming a real game, we'll game or a gaming unit heap. Then we're going to use this again. And I believe that in that actual example it's going to get way, way clearer. Right now. I just wanted to show you that there exists something called events and delegates. And once again, mastering them is really difficult. And yeah, it's just something that is very good to have seen ones. And we're going to look into this later down the line again. Just wanted to quickly show this to you and how this can be really useful. We're going to see in a future lecture. But nonetheless, if you have any questions, don't hesitate and feel free to ask and I'll be sure to respond. And yeah. 42. (C#) File I/O: All right, Welcome back to C sharp introduction here for the unity course. And in this lecture we're going to take a look at file input and output. So I have prepared a very cool text file, as you can clearly see here in our assets resources folder. And let's just open it and see how it looks. It is a super cool text. Isn't that great? And we're now going to learn how we can read this in. And then we'll also going to learn how to write out a new file. Let's just go into our file I O script here. And I've already prepared basically the reading path and the writing path you're going to be in assets, resources. And then the cool text file is the one we're going to read in. And then we're going to write to a super cool texts we made with code. And like I said here, t dot TXT, it's just a normal text file. So what do we need in order to, for us to basically input and output stuff? Well, to write something to a file. First of all, it is a very slow process. Now, slow in terms of comparing two things we can do in code. It's still incredibly fast, but usually writing something to a file is a slow process. I just wanted to mention that. And we will need to use the system.console namespace here. And then we're going to see, so first of all, we're going to check whether or not the file even exists. So file dot exists. And then inside of it we're gonna put the red path first because we're going to look at whether or not the read a path has a file that exists there. Because if it doesn't, well, we can't really open this. And now what we're going to use is we're going to use a stream reader. So stream reader SR file dot open text, and then we're gonna give it the path. Now the great thing about the stream reader is that this is a i disposable, I believe is the correct term for it. And hope you do there is we can use the using keyword. Now, you have not seen this before. We can actually take the using keyword and we can take all of this, put it inside of here. And then once we are done with it, it's going to close the stream reader for us because we need to probably close the file again. And this is basically all handled by the using keyword. And inside of here, we're going to have a string, cool S. We could also call it a habit, a little bit better name. I think AS will suffice for now. And I'm going to have a while loop inside of here, which we're going to say, well, S is equal to SR dot readline. So this is, the red line is simply a string and we're going to set S to that string. And as long as that IS NOT null. So while is that is not null, we're going to just output basically S. So we're going to read each of these lines that are in here. Now, there's only one line in here. We're going to output it. And once we're done, we are done using this. The stream reader will basically get disposed of. And everyone is happy again. That's all that we really need in order to basically read a file. Let's see if that works. Making sure we're on file IO. Let's not worry about this warning. This is simply because we have the right path variable declared but not used. And let's see, at supercool, texts will exactly what we've written into the file actually gets output. So that's pretty cool. And now let's see what we can do in order to write something. So if we want to write something, we're going to use the stream writer. So we're going to once again say using and then stream writer. This is going to be then SW is equal to file dot text, in this case on the right path. And we're then going to have basically what we call is the SW. So the right stream writer, dot-dot-dot write line. And then we can say, for example, hello, and then let's just copy this a few times. This is another line. Pretty cool. How that works. So let's try this and see if that works. So right now we do not have a new file inside of our resources folder. And once we start this, what we can see, let's end this. And we actually, I believe, have to reload this because it doesn't right, we have to refresh. So Control R. And then as you can see how they go. And as you can see, super cool texts we made with code is in here. And then Hello, this is an align. Pretty cool how that works. Everything that we've put in here, exactly how we've done it. And now let's sum this change up a few of these lines. Let's, for example, say, Sure, How would you, Why not? This is yet another line and then pretty cool how that works. And then let's change this to maybe one of those and see what happens if we just run this again. So let's just put this in. And once again, we've run this no errors, That's kinda nice. Let's open this file again. And as you can see, they like the program just changed whatever was written in here again, so it is going to override what we already have. So the UN, the text file at the right path in this case will simply be overwritten with the new stuff. Yeah, that is the basics really off file input and output. There are also more advanced things. And during the unity programming part of this course, we're going to look at especially how to read and write things with JSON files because they are formatted in such a way that we can use them fairly easily. But overall, this was just a quick, short little overview once again, of the file input and output. As always, I hope you found it useful if there are any questions, like always feel free to ask now be sure to respond. And yeah. 43. (C#) C# Conventions: All right, welcome back to the C-sharp introduction here for the unity course. In this lecture, we're going to take a look at these C-sharp conventions. So this is potentially the last of the C-sharp lectures here. And we're just going to quickly take a look at a few conventions that you should follow if at all possible. So let's just open the conventions script and see what we can see. So I have prepared a few things here and I'm gonna explain from top to bottom a few of these conventions and why they might be useful and why you should probably follow them. All things considered and also bought a few of those things are. So first things, first class names, right? So those would be, for example, conventions and what we've seen abstract animal or animal or person, should be Pascal case. What is Pascal case? Pascal case simply means that the way we write certain words, in this case, as you can see, abstract animal. While this is all one word, the abstract is one word and animal is one word. And they are both capitalized. So this is what Pascal cases. We capitalize the first, the first character. And then every time we get to a new word, we also capitalize that word. That's very important. That is Pascal case. When we look at local variables, field names, and also parameters, those should be CamelCase. Camelcase simply means that the first character is lowercase. And then each, each word that comes after it is going to be uppercase. When we look at constants, we have not seen the const keyword really. The idea here is simply that this is a variable that can't be changed. So it's not going to be that complicated. The idea is that those should also be in Pascal case and not in screaming caps. That is something that I personally do sometimes. I think that this is one of those things, like with all of those conventions that are not really rules, they're just guidelines that might help. And this is probably one personally that I would. So I personally probably ignore this most of the time simply because I sometimes feel like it's easier to see, okay, this is a constant. Even though you should be able to see this by the symbol it has right here. However, I usually do make it all in screaming caps, but it's still a convention that one might wanted to follow. So we always use meaningful names for variables. I've mentioned this throughout the course of a few times already. But it is very good to have a proper names for variables. We've used this most of the time. I think that one or two times I have not done this, but usually you should avoid the single letters. So for example, the integer t and we'll see, okay, well, what does that mean? Well, it's much easier to read if I It's in the timer and the full-time or completed. And also, don't be afraid of really long names for variables. If it is an expressive name and it is a meaningful name, then you really shouldn't be afraid of that. Because the better you can explain something, the easier it is to understand. That's why we should always use meaningful names for variables. I personally also sometimes get this wrong, but when you think about it, when you, when you're programming quickly, you would just call this S or just call this in AI. But what is AI? What is its purpose? And that can also sometimes lead to you thinking about your code a little bit better and thinking like, well, actually I don't really need this integer, this variable here. So yeah, don't use abbreviations in your names of variables. So things like ID and XML and something like that. That's okay, but not putting in person and then doing PRS n for that. That's just going to lead to confusion. And I gotta be honest. Those two, those two characters that you save there, it's just not gonna make any mistake at all. There is a thing that we don't really use underscores in C-sharp. That's just the convention. Especially in, well, actually in anything except for the private fields. And we've seen this in the C Sharp properties lecture where I made a, I believe it was a boolean or some type of variable that was private. And I started with that with an underscore. That is fine. A class names should always be nouns. So animal, person, those are nouns, right? And they should also be singular if I'm not mistaken. So that is also something so that shouldn't be animals or persons because it's always a class. It's a singular noun that describes a class. So let us hear the prefix interfaces with the letter I. So the I flyable. That was an interface that we have done where we could call the fly method from. And it is said that we should start this with the uppercase letter I. Now some people really don't like this because they're like, I know whether or not this is a, this is an interface. I personally think that this is a good convention. However, there are some people who have very, very strong opinions about or we don't need that, whatever, follow it or don't follow it, it doesn't matter, just stay consistent. That's like one of the most important things. If you change your conventions halfway through your project, then you will need to go back and rewrite the rest of the code so that it follows your conventions. Like if you have some conventions and stick to them, but don't go crazy. And also that something else. It's often that we end at the interfaces with Able. So that it's sort of, you know, I flyable, I talk bubble. Because that sort of also signifies, okay, what are they able to do? So that's also something to take with you. Then we should always have singular names for enums. So game difficulty, for example, not game difficulties. And we should never use the name inside, like enum inside of the name. So we shouldn't have game difficulty. Enum or color enum, always just the singular thing that it is a never using enum. Now where do I have this from? I have this from a GitHub repository of naming conventions. This is of course linked as well as a resource. I can only advise you to take a look at that as well because there's a few more things. Then I've put in here. I've those were just sort of the most important ones I've seen. And I can just really advise you to take a look at the link. They are. Because those are some good naming conventions that you should follow. At least most of them to make your code as standardized and easy to read as possible. But overall, that was it with the C sharp introduction here for the course. And yeah, that was it. I hope that it was useful to you and now it is off to basically learn Unity proper. So you can, of course, first of all congratulate yourself on achieving this and getting into here because it was quite the thorough introduction. And there were a few things that you probably need to learn depending on your previous level of knowledge. But yeah, it is done and I hope you found it useful. And at the end here, like always, if there are any questions, feel free to ask and I'll be sure to respond. And yeah. 44. (Unity Basics) Unity Layout and Editor Explained: All right, Welcome to the basic unity introduction here for the unity course. And in this lecture, we're going to take a look at basically the unity layout, the specific like edit things and well, just a few hearts and a few parts of the windows basically, just quickly explain like little overview given so that you know what all of this means and that you can find your way basically inside of the Unity UI here that you see, there are a lot of moving parts, a lot of buttons that you could click and not just them. Just a short little introduction for that. So we're going to start basically at the top left. This here is basically the scene window. And it is one of the most important things in Unity because this is basically what gives you your view onto your game world, right? So currently this is basically put into 2D mode. You can see when toggled on the scene as 2D view, when it's toggled off the scene as in 3D view. Idea here being that, of course, this is a 2D course. So we're going to do everything in 2D. We can look into the third dimension by clicking this button. And then as you can see, We get basically a 3D view. But as we don't want that, we're going to stick with 2D and then just figure out how we can move inside of here. So if we press the right mouse button down, we see a little hand appear and then we can move the, basically the game world. The view then shifts and we can move around, right? So that's a pretty useful. We can zoom in and out with them with the middle mouse button, of course, we can also move around if we hold the middle mouse button down. And then also we can basically move around. If we hold the left mouse button down, we can select things. Currently in our scene. We can see whatever we have in here, here in the Hierarchy. We're going to look at that a little later as well. But right now we only have the main camera in here. And we can, for example, select this. And then as you can see, first of all, the main camera appears down here. So this is what we would see inside of the game. And then at the right side here, a whole bunch of stuff appears, which we're also going to look at in a little while. So what else is therefore the scene view? While there are a bunch of buttons here, basically you can toggle on and off the audio. You can use scene lighting. There are things for sky boxes. You can see how many objects there are and also toggle on the grid. So for example, right now we don't have a grid, and then we have a grid. So the grid can be really useful. And also sometimes it might be that the gizmos are turned off. So the gizmos, or basically, if I click on this little button here, you can see there are certain icons that you will see that simply helped you find certain things inside of the scene view. For example, the camera, right? It doesn't almost doesn't matter if I zoom out a bit, then the cameras still there. And if I zoom in a lot than the cameras even bigger, but it just shows you okay, there is the main camera or there's a camera and if we turn that off, then we don't see anything and we don't even know where the camera is in that instance. So the gizmos are basically for helping us see certain things that are visual aids. Big that you can only see inside of the scene view, right? And then there's also just a sort of tool box here. I rarely use this. And then you can also change the camera settings here. So this is the settings for the scene view camera. In this case. I would also say that I don't usually use that. You can also search for something up here. But there are a lot of search bars, actually, there's one here, there's one here. So we can search in a lot of ways. So this is the scene window. Basically. You can also have different modes at the top left here. And those basically won't do anything at the moment if we have things in here. So this is also more about, I would say, the 3D perspective. So shaded simply means that if we have, if we have a cube in here, I can just add one real quick so that we can just see this as an example. So right now we have a black cube in here as you can see. And then if I do a wireframe, see this as a wireframe. And then a shaded wireframe simply means that we both see the wireframe under the shaded mode. We also have different things that we can do render paths. We can have the alpha channel overdraw MIP map. So those are simply like different rendering ideas, so to speak. For example, use I usually keep it at shaded. That is the one that makes the most sense. And in 2D, the differences there are actually not that important anyway. So at the very top, we also have a few tools that we can use. So I've said right-clicking or middle mouse clicking, we can move. We can also just simply selected this hand tool and then move with the left mouse button as a click. That also works. We have the Move tool. The move tool basically is if I have a certain game objects selected, for example, the camera, then these arrows will appear and with those Eigen basically move the camera around. And then at the right side here you can see that the position of the camera actually changes. Like I said, in this case, because we are in 2D, we are going to be only need the x direction in this direction and the y direction and this direction. And yeah, the, yeah, that's basically that. Then we have the rotation. So this is the rotate tool. We can basically rotate around this angle, right? So we can rotate around the, this would be the z-axis, right? Because the z-axis is the one that goes into the, into the computer itself. And then we can also basically tilted in this direction. But usually z-axis is the only rotation we need in two-dimensions, three-dimensions, we would, of course, we could rotate around every axis. We also have the scaling tool. So this won't do anything for the camera in this case, because the camera, the scale of the picture of the camera is controlled differently than the scale of the object itself. So this only really applies to different objects, but in this case we can scale this with this tool. And then this is my basically favorite tool, direct tool. Because when we have, especially in two-dimensions, we can basically have the ability to size something up or down with the sides. It's very similar to something you would see if you turn on transfer mode in Photoshop for any of you who, like who understands what that is. That is something, but we're going to see that later down the line as well. And move, rotate and scale objects. So this simply puts all three of them together in one. I personally don't prefer this view. Some people actually really like this because then they can do whatever they want to. We also have the editor tool. However, we don't have any custom tools here. So this really doesn't do anything for us. I personally keep my unity almost exclusively in wrecked in the rect tool and move around like I said, with the right or the middle mouse button, usually the right mouse button and zoom in and out like that. Yeah, that's basically the gist of it. You can also go to these buttons by a person Q, W, E, R, T, and then the z been ah, that's actually the y been. Yeah, exactly. So q0, QWERTY basically is these these buttons that also works, but yeah, it's also enough if you simply click on them. So let's switch tabs here and look at the game view. Currently, as you can see, there's basically nothing here because we have nothing inside of the game right now. This simply is whatever you would see when you play the game. And this is also what starts up. So if we hit the start button up here, the Play button, this is also what we see, so it automatically switches to the game view once we have started the game. And the game view, like I said, is what you would definitely like. Basically one-to-one example of what you would see inside of the game once you would start it, there are certain things we can do. We can basically have different displays here. Now. Right now we only have display one. We can set the resolution currently, as you can see it. Two, for k, we can also just say, well actually let's put it at full HD. That's going to be fine. We can scale it up. So this simply zooms in the picture without doing any fancy like Zoom techniques or someone like that. It's literally just zooms in. If we hit maximize on play, once we play, the window gets maximized here, this can be really useful if you want to see, you know, like almost all of the details because this is almost full screen. And then there's mute audio should be self-explanatory. The Muse the audio. We can look at stats that are running and we can also turn on the gizmos here. And those are basically the same gizmos that we have, the scene view. But this is the game view. There's actually not that much to it. Yeah, let's just continue with the hierarchy hierarchy. Let's also switched back to the scene view. The hierarchy basically are all of the things that are in the current scene. Currently we are in the sample scene. This is a scene that gets created when we start a new Unity project. And as you can see, we basically only have the main camera here as a component. We can add new components by going to this little plus button, for example. So we can have predefined things that we can create or we can right-click into year and also have the same. Things that we might want to create. So for example, we can create an empty object. And this empty object literally has no, It only has a position, rotation, and scale. And it doesn't have a, let's say visual marking of any kind. So we don't even know where this is when we could add this. And then, for example, change things. But right now we're not going to add this and we're just going to keep it like this. By the way, we, if the scene changes, right? So if we change the scene, so if we move this, then you will see a little story here and a little store at the top. And the store can, oh boy, you can basically save the changes by simply using Control S or going to File and then Save here. And, um, I'll probably use that multiple times throughout. And just like with almost any other program, we can go and undo or redo stuff with Control Z. That's simply undoes things and then Control Y basically switches back and reduce them. So that's, should be almost self-explanatory, right? Then the hierarchy, if we select something in here, it also gets selected in the scene view and it also pops up something in the inspector. The inspector is one of the big things which we're going to look at, like even in more detail when we look at scripts because that's where it gets very interesting. However, what is to be said about the inspector is that it basically, for each of our GameObjects that exists inside of our scene, we get additional information which we can also manipulate. So for example, for the position, I can basically change this. And as you can see on the left, it actually changes in the scene as well. So this is very important and these are sort of, these are grouped into their functionality. So for example, this camera obviously has sort of a camera component associated with it where we can change different things that are associated with the camera. And the transform simply means that this is the positioning and the rotational scale. So this is what sort of the, let's say the physical manifestation of this object. And every object always has a transform components. So these are the individual components. We're not gonna talk about Add Component right now. That is something that we're going to see later down the line. However, we can, of course, add components to our individual objects. Let's quickly look at the console as well. So the console has two main parts. Here. We have already seen if you've watched the C sharp introduction, then you will have seen this multiple times. There are basically outputs. If we do debug dot log or debug, debug dot log warning, then those are displayed here. If we select them, then we can see sort of a trace down here. And this can also be expanded or moved down. We have a few buttons, this clears the console. We can collapse it, we can pause on errors, and then we also have a few things that we can do. As you can see, target selection. I don't really use this. This is for, if we really go crazy with our debugging, not really needed to. We can also filter for on basically normal, just logs, warnings and errors. And that is basically the entire console. It's not that crazy. And like with almost all of the other things, we're going to look into those like even More later down the line, the project view is basically the folders and directories that we have for our project. Currently, inside of our assets folder, we have a scenes folder, and inside of that we have the sample scene. This is the scene that gets created in the beginning of the end when we create a new project here, this is simply the scene that gets created. And that is all what we have in here. Going for. Going forward, we will create a few more folders. And I will also basically show you my personal folder structure that I use. That is of course something that is completely up to you. You can either follow it or don't follow it. That's just a suggestion. Same with the basic layout of the, of the entire screen here. That's something that you might want to follow or not. Let's quickly also talk about the right buttons here, just for completion, this is collaborate. This simply means that if you want to collaborate with multiple people with Unity collaborate, you can do it with this. I wouldn't worry about this right now because let's do the basics first. Let's get rolling with the unity concept and omega1 basically talk about collaborating. The managed services simply means that there are services. So if I click on this, the service window pops up and those are specific services that I could basically enable here for this particular game. Like the collaboration not needed, I can basically close this services window by middle mouse clicking and then it disappears. I can also right-click and I believe I can close tab as well. The account simply is the account that I'm logged in on. So your Unity account layers are the layers that exists. That's something that we are going to talk about later down the line as well. And in the layout simply as the layout of my Unity. So I can, for example, change it. I could change it a belief that then gets reloaded. So I don't want to actually do that, but I have my own KJ layout here. Like I said, I have this and I believe I can also make it available. So I can actually save this to a file and I will have the layout available. You should have this by now. It should have been downloadable in the beginning of the course. So yeah, yeah, that is basically it. I mean, the only other things are the start, the stop, and the step button. The step button simply puts whatever we have gotten here. So if we put this on and then we stop for example. So this pause button actually, and then we can step like frame by frame through a particular scene with this button. Of course, right now it, it doesn't do anything because, well, there's nothing here. So there's nothing to see are those are these three buttons. And then if any of those particular things are not here, you can always go to Window and look at all of those different windows that are there. So the scene, you know, the game, the inspector that we've seen, hierarchy, project console, those are basically the most important ones that should be there almost always. And then everything else is something that we are going to look at in some detail and some not details. And so we're going to look into like really well. And some of the other things are way more advanced that we don't really need to make, let's say simple games or even a little bit more complex games. But yeah, that is basically all that I wanted to tell you for the unity layout, it's a little bit more comprehensive. But, and there's of course, more to learn and the applications of that. But I just wanted to, you to be at least somewhat feel comfortable inside of this layout so you know, okay, I like vaguely know where it is. Okay, the hierarchy shows me all of the objects in the scene and then the project has basically the folder structure and so on and so forth. So, yeah, that is basically the unity layout. And the editor explained, I hope you found this useful like always. If there are any questions, feel free to ask and I'll be sure to respond. And yeah. 45. (Unity Basics) Unity Folder Structure: All right, welcome back to the basic unity introduction here for the unity course. And in this lecture we're going to take a look at the basic folder structure. Basically that I use personally. It's I think, I don't know, it sort of evolved over the years. It's not really that complicated or crazy to explain, and it should be fairly straightforward as well. So inside of our project view right here, we have the assets folder. And this assets folder. That's basically where we will have every thing that our game has or scripts. We will have our scenes in there, we will have our pictures and images and sprites. All of it is going to go inside of this assets folder, the Packages folder here. We can basically for right now ignore this. We will not use any packages for the foreseeable future. However, the assets folder, That's where we're going to create our own folders inside of it. And we're going to basically will make our folder structure here. And this is simply right-clicking on the Assets folder, create and then Folder. And the first folder we're going to create is going to be called. So inside of those, of course, all of the scripts will go in the future. And then we will create a folder called sprites. So instead of there, all of the sprites will go. And then two other photos that are quite important that we can also create already is the Resources folder. Now it is very important that this is actually written correctly because that is one of the other folders that is sort of where we will be able to input and output stuff, Let's say. So this is a very easy folder to be read from unity. Let's just keep it at that for now. We're going to look at that later as well. And then one thing we're also going to create is the Prefabs folder. We're going to talk about what prefabs are as well in a future lecture right now, we're basically building up sort of the foundation. And then we're going to add to those individual followers continuously down the line. Especially of course, the scripts folder is going to be the one where we are going to basically create a whole bunch of scripts that are, you know, deca have a plethora of functionality and will basically show each of the individual, individual functionalities that we're going to take a look at in this basic unity introduction. So those are basically all of the folders that are interesting. One thing to mention for the scripts is that if I have, for example, different namespaces, I've already explained this in the C sharp to C sharp part. I have different namespaces and are basically mirror the namespaces in sort of this scripts folder. And what we can do is basically, we can go into here and instead of the project settings under the sea shore project duration, make a root namespace. Now inside of our basic unity introduction, we're not gonna do this, however, when we create our own game. So when we make the first game there, we're definitely going to do that. Because then the scripts folder actually will mirror this. In this case, the scripts folder is a little better served by having the separated because the lectures that are going to come are basically independent from each other. So you could, for example, jumped from lecture to lecture 5 without missing anything. If lecture for is something that you have already seen or know about. Yeah, so that is the basic project structure, nothing too fancy or too crazy about it. There are a couple of more, well basically folders that might join later down the line. Probably when we look at more intermediate and advanced concepts, then more folders will join. However, those are basically the photos that we need for the basic introduction and for the first game that we are going to create. So yeah, nothing too exciting. But now finally, we can basically start, and in the next lecture we're finally going to start reading a script and actually seeing a little bit what can, what unity can basically offer. So once again, I hope you found it useful if there are any questions, always feel free to ask and I'll be sure to respond. And yeah. 46. (Unity Basics) Scripts and The Inspector: All right, welcome back to the basic unit introduction here for the unity course. And in this lecture, we're going to take a look at where both the inspector and scripts in general. So we're gonna take a look at if you are one script and how that manifests. And then we're also going to see how this looks inside of the Inspector. For that, we're going to create our first script here. And we're once again right-click on the scripts folder, create, and then C-sharp script. We can then rename this. We're going to name this health. So this is the, we're going to basically make a health class in this case. And we're also going to create a new scene for this. So I basically want each of the different lectures to have a scene associated with it. So we're going to make right-click on scenes once again create, and then down here to scene. And this is going to be basically three. So L3, this would be scripts. You can of course name this whatever you want to. You don't have to follow the scripts even like the individual individual scenes like that. You can do whatever you like to. I just think that this is the tidiest. And this will then also translate into the app downloaded content. So you can of course also download the entire basic unit introduction as a package, import it, and then you will have almost the same structure as that. So first thing that we're going to do is we're going to create a new empty object in here. So create a right-click inside of the Hierarchy. Create Empty. This is now an empty game object. We're just going to call this health. Just for the sake of argument. I personally do one other thing. I always position my empty GameObjects at position 0, 0, 0. There is literally no reason to do this. I just hate seeing like these really crooked numbers in this position. This is why I do this. And you don't have to do it, but I do it. So, yeah. And right now that this is created and position, we can basically take the script left-click hold and then drag it over here. And as you can see, I can actually get an indicator here. And if I let loose, and we can see health script is now basically a component of this GameObject. And the great thing is after we've saved here, the great thing is that we can basically now manipulate this script. And this will now run inside of our gate. So we can either double-click here or double-click here. Let's just click here. And then for me, a visual Studio will open. It will open on a different, different screen. So I'm just going to plop it over, they go. And this is a new script basically formed. And this is how it looks like. We get a start method and we get an update methods. So those are two of the things that get pre-generated. And we can also see that this health script, this help health class. Inherits from mono behavior. Mono behavior, as you can see, is the base class from which every Unity scripts derives. So if you want a unit test script wherever the start method works and the update method works, then this needs to basically inherit from moral behavior. And what is also important if I quickly look at this mono behaviors also, the thing that you need to basically put a script on a GameObject here. So otherwise this won't work. So if I have a script where I don't have this mono behavior, the inheritance, I can't actually attached to anything. So what we're going to do is we're going to create a few new, basically fields and variables here. So not inside of our method but above it. So basically as part of this class, we're going to click Create a Public Health. And we're gonna set it equal to a 100 and then a public int manner equal to a 100. So this is something that a health class might manage with a health, a health variable and a manner variable. And we're also going to make a private variable integer could experience. And that's also going to be a 100 just for the sake of argument right now. Now we're going to keep this like it is and look back into Unity. So we're going to have some reloading here. Now. We will. This is a warning that doesn't really concern us right now. It simply says, Hey, we've created like a field, a variable that we've never used. So this is like something that is useless basically, because we don't use it. I would really say that this is a warning that can almost always be ignored, especially in the beginning. We're just doing we're trying out a few things and yeah, so most of the time, this can be ignored if you're really working on a project and you get this like with almost everything that you create, then this simply signifies a, maybe there are some things that some fields or some variables that could be deleted. But in this case right now, it doesn't concern us who we can actually clear the console. If we now look at our health game object here and a half script, you can see something has appeared, a health variable here and a man of variable here. So there are two fields that have appeared with their basic values that we have put in here. And I mean, that's pretty cool, right? So that's actually something that has just happened without us doing anything. But if I'm declaring and initializing those variables, That's pretty cool. But if we see the spurious variable is actually not there. And the reason for that is because we have made it private. So the access modifiers in this case actually do matter for our visibility inside of the Inspector. But for that, we can do the following. We can put the basically brackets in here and type in serialized field within this will basically serialize this field. Now we will also no longer get basically the era or the warning, Hey, this isn't used because now it is used and it is used by the inspector. And as you can see, now the experience up, don't worry about it. Now the experience variable here shows up as well. So this is a way in which we can make private variables visible for the Inspector specifically. Yeah, and that is the basics here. We can also, if we now start this, nothing will happen because we don't have anything exciting in here. But what we can do is, for example, we can do health minus equals 20, for example. And then just for the sake of argument, if I can figure out how to type 0 in the update method. We could put in experienced plus equals one, for example, just so that we have something to show. And let's just, let's just look at this. And then we can actually see this change here. And let's just start. And as you can see, now the experience, as you can see, it's going really, really fast because currently are FBS, is that like a thousand or somewhere around that? We just stop quickly or our pause the game. Then what we can do is we can actually go frame by frame. And then as you can see, this actually only gets increased by one each frame, like it is supposed to. And it resets once we have stopped the game. Because this is basically not persistent, the data in here reverts back to what we have, set it inside of our script basically. So yeah, that is a basic overview of the script and the, the inspector. We have in the C sharp introduction seen that the start method basically something that just happens at the start, that is exactly true. So once we start the scene, everything inside of here gets executed. And then after that is done, the update method gets called every frame. So this is frame dependent. And then we will add something here. We will in futures also see different ways where we can do things time-dependent. So we can basically say, Hey, we're going to wait a minute for this or, or a second or somebody like that. And yeah, that is the basic overview of this. I hope you found it useful like always, if there are any questions, feel free to ask and I'll be sure to respond. And yeah. 47. (Unity Basics) Kenny Assets & The Asset Store for our Games: All right, welcome back to the Unity basic introduction here for the UD course. And this lecture, we find ourselves outside of unity. I know crazy. And this is basically something I wanted to show you for assets that you might want to use. And for one example of assets that we are going to use. So Kenny assets are basically a bunch of assets and they are all free to use, right? So there are over nine sides, as you can see with a bunch of stuff. As you can see, there are different 2D and also 3D assets here also some audio assets. And if we, for example, just go to the next page, as you can see, there's a variety of things and they all are crazy cool. They look really nice. And like I said, they can be used. They are under a universal license, so they are you can use them for commercial purposes or any purpose that you would like. And for our basic introduction here, so for the basics of unity, we're going to use the playing cards here. They are actually they offer us everything that we need really. And I basically just want a particular image that we can use to do stuff with that looks a little nicer than just, I don't know, like a black or white screen. And as you can see here, this is a cc, your inverse, well, you're free to use this in game in any project, personal or commercial. There's no need to ask permission. Giving attribution is not required by greatly appreciated. Of course, this is why I show you this number 1 because it's a great resource. And also because this is, I mean, it's amazing, right? It's never been easier really. And there are some really nice assets here that you can do amazing things with. And also, I will, of course, the playing cards, I will have those included as a download and also the link to the assets here is also as a resource available. And then there's one more thing, and that is the Unity Asset Store. You've probably seen this before already. But this is basically a well where assets are either sold or also could be downloaded for free. So there are some assets that are sold, and there are also some assets that are free. So if we filter by top three, as you can see there, there's a bunch of stuff here that is free to use and that you can also use in your game. We are, we will be focusing on the kenny acids, so we're going to use the kenny assets going forward. However, like I said, the Unity Asset Store can also be a great moment where you can basically get new assets as well. And yeah, that would basically be it. I just wanted to mention to you that we're going to use the kenny acids and that there are, there also even more places where you can go online. I think go open game artists, another place. So there are plenty of places. Rubber, we're going to keep it at the kenny assets. And that was just something I wanted to mention. Like I said, everything as a resource available. And yeah, that was already it for this lecture. I just wanted to quickly show this to you. I hope you found it useful if there are any questions like always feel free to ask and I'll be sure to respond. And yeah. 48. (Unity Basics) Scenes & Build Settings: All right, welcome back to the basic unity introduction here for the unity course. And in this lecture we're going to take a quick look at the build settings and making a build. So what is a build and what does that mean to make? To look at the build settings? Well, the idea is that a bill is basically an executable which you can, of your game, which you can run. And it has everything in it. It's basically the release of your game, almost like you would want it to be released. And there are some settings that we need to do in order for this to actually work. So there are a lot of settings actually, and we're going to take a look at later down the line as well. But one of the things that is very important are the build settings. So going to file and then build settings. And if I just quickly move this over here, as you can see, these are the build settings. There are a few things that you will see immediately. So we can basically look at what platform we want to publish this app. Usually PC, Mac and standalone is sort of the, I would say, the default. And then you can, if you have it, you can choose different target platforms and also even change the architecture here. Usually in the beginning you want to put in this as a development built because this is a development built. And then also very important is as you can see, there are scenes that you actually want to build. So when you create new scenes, then you actually want to keep in mind that you will have to add those in here when you build. So as you can see right now, I have seen slash sample scene that, that one is in there, but the L3 that is not in there. So I can simply drag it over and have it in here. And these 01 is basically the index. So there is actually a wave in which we can access this. So if we were to look at something like this, so there is actually way that we can access this by script basically. And yeah, so let's just quickly take a look at that so we can then build it. I'm not going to, because right now there's really, actually, you know what? Let's do it. Basically set out, okay, where do we want to build this? Usually I would say that inside of your Unity folder, you create a folder called builds. And then you, you choose that one. And the build is actually going to take a little while depending on how much is in there. Now, of course, I have basically nothing in here. There are no, No real sprites. There's no real assets. There's almost nothing in here. And just a second, I will show you the where this has popped up. So the basically here, there you go. So we get an EXE year that we could start an executable. Now it's going to start on the wrong screen, so I'm not going to do it right now. But overall, as you can see, there's everything in here. Level 01 are basically the data for each of these scenes there. And then we also have a resource folder. This is the one that I mentioned that had to be the right name. And then there's also a managed folder with a whole bunch of basically DLLs. Overall. This is also what you would basically take. So the EXE and the data folder, and those two would be the ones that you would have to ship basically to people for them to play your game. They're also Player Settings. I'm just going to quickly click this and show you, um, we're gonna go through those in a later while as well. Those are simply things like the product name, what company you have, what version, some icons and so on and so forth. There's a lots in here and we're going to cover a few of the project settings later. Like I said, right now, we will not really look at that because they are not as important as it might be, right? So this was the created, the Build, created a build. And let's just, for the sake of argument, create a new scene here. This would be L5 scenes, right? Because we're talking about scenes. Let's open this and then let's also create a new script. So this is just the test. Let's just call this the scenes scripts so important that it's scenes and not seen. Because I believe that if we were to name this, just seen them, we might clash with something. And inside of here we actually can use something. So we have to use a new namespace. This is Unity engine. No, that's not right. You know the engine that senior management. And with this, we can actually do all sorts of fun things. So for example, we have the scene manager. And the scene manager can basically do everything that we wanted to do. We can actually even create new scenes. We can get all scenes. We can get seen at a particular index, that is exactly the index instead of the build settings. We can also get it, get the scenes by name. We can load a new scene. So this is where we can basically change from one scene to the next. There's also two events you're even that we could subscribe to. And yeah, that's those are sort of some of the some other ones. Let's just do the following. Let's just make it so that immediately after starting, it loads a different scene. So it is going to load seen with index one. Is that correct? Let's just quickly check again. So that's one of the things where it's a little yeah, L3. That is exactly right. So that's fine then. Yeah. So idea here is that we of course have to attach this to a objects. So this is going to be a scene's objects, 000 000. This is just once again for me, because I really want this to be at position 0 000 scenes. So the script is now attached to this object. If I save and start now, this scene will change to seen L3. As you can see now we are in L3. We might have to expand this to see. And then we have our health script back. And this is running because we have basically started this C now. And if we close out of it, we're back at our original L5 SI. So that's a short little thing about scenes and the basically build settings and how to build your game. We're going to see this later down the line in a little bit more detail and a little bit more what goes into it. But overall, the scenes themselves are quite important. And yeah, that was basically it for this lecture. I hope you found it useful if there are any questions like always, feel free to ask and I'll be sure to respond. And yeah. 49. (Unity Basics) MonoBehavior in Unity: All right, welcome back to the basic unit introduction for the UD course. And in this lecture we're going to take a look at the mono behaviors script. So we have seen in the first lecture of this basic introduction that we had to have a script or a class inherit from the base class mono behavior in order for it to be a component inside of the inspector on our objects. And now we will look into what this model behavior basically allows us to do some examples and yams, basically some examples of what this is and what it does. So let us create a new scene. And this would be six, and this is the mono behavioral. And let's also open this scene, of course, create a new empty GameObject. Let's just call this E. Let's just call this example in this case, because I don't want it to be called mono behavior necessarily. I think you can. I believe that the names here are not that important to the cases because mono behavior is a keyword. And I do not believe that the names here are some old associate with it. But just to be safe, and we'll call this one the mono behavior example. So that we're not confusing the anything. And let's open it. And as you can see, once again, this year model behavior is exactly the base class. And like always, two of these methods are created, the start method and the update method. And there are actually already comments in here. So start method is exactly what it says. It is called before the first frame. So the idea is that this happens, everything inside of your happens at the very start. And the update method is simply something that gets called every frame. For this, the script must be enabled. That is something that we can enable and disable in the Inspector. We're going to see that shortly. And then we have a few other basic methods that we can call, for example, the awake method. So we can just type in awake and then press the Tab key to autocomplete it. The wait method allows us basically to have something called before the start method. So the awake method actually gets called when the script is being loaded. So this particular script in this case, is being loaded. And this happens by the way, when either the scene starts or when an inactive game object is basically reactivated, so to speak. So because we can toggle a specific game objects on and off. And this wake method gets called either, like I said, when the inactive game object is set to active again, where the scene is loaded for the first time. We also have different update methods. We have two different update methods. We have the fixed update down here, and we also have the late update. So the fixed up. It is basically an update method that is frame rate independent. And idea being here that usually the physics should be calculated inside of the fixed update method. Because as you can see here, this function is called every fixed frame rate frame if moral behavior is enabled. So if this is enabled, this script, then this is called in a fixed frame rate. Therefore frame rate independent. Why is it important that, that the physics are instead of this, instead of the update method? Well, the idea being that if you have a good computer or a better computer, let's say, then maybe a game will run for you for 60 frames per second. And therefore, update method is going to be get cold 60 times a second. And maybe someone who has a worst computer actually only gets 30 frames per second. And this then simply means that this only gets called 30 times. And if the physics is dependent on the frame rate, then everything would move faster for the person who has the better computer and slower for the person who has the worst computer. Therefore, the physics goes into the fixed update, can actually add a comment here as well. Physics, physics inside of here. So that's kind of important. That is the fixed up to it. And the late update is called also every frame. We can actually see this lead up to this court every frame, but it is called after the update method has been called a actually after all an update method ha, have been called. So this is the thing that runs last at the end of the frame and can be used basically if we have two things, if we're like, okay, the update method is going to go and then the fixed update might go. And then we want something that at the very end, then the late update can go a personally I've not used it a lot of times, but I also wanted to show it because it can be quite important. And then there's one more thing that I wanted to show and that is the destroy method, the onDestroy method. Let's see if it has a thing. This gets called when the moral behavior will be destroyed. So the idea is that we can basically call a destroy a method that then destroys this particular, either this particular model behavior and basically removes it from a game object. Or we can also destroy an entire object and this then gets cold. So this method is exactly what gets called when we are about to destroy something. This might, for example, save some data, or it might output a message, or it might have another event call that we want to relay, for example, to the, to the UI. So maybe you have 10 enemies and we actually show that number in the top of the screen and in the UI. And then each time this onDestroy gets cold, maybe we want to see an enemy has been destroyed. So we update the UI with that. That would be an example. So let us add, if you the logs here, so debugged with the awake method in this case. And then let's just copy this upward explained. I can basically mark something here so I can select it. I press Control C and then go in here and press Control V to paste it in. And this is the start method. We also have the update. So let's put this here. Let's actually put the fixed update here because it's sort of, you know, it's not really before the normal update, but it's it's I think that that makes more sense. And then the layer that is at the end. So this is the update method. And we're going to also copy this over for the late update. And then last but not least, the onDestroy we will add. We can actually see this. We're going to see this, so basically destroyed. And let's actually take a look at that first and then we will see something else as well. Also, do not forget to add this to our game object here. This is one of the things that will probably happen to some where you will start it and nothing happens. It's because you have not added to the thing to your object, right? And as you can see clearly, the update in the late update are called every frame, right? And fixed update, as you can see, is called weigh less because it doesn't matter what our frame rate is up here. This gets called everywhere the same. So in theory, this number should basically rise exactly the same time as your number. And these two might be completely different for some, for some of you who might have a better computer, it's going to be way faster. And for some of you who might have a not-so-good computer, this might be way, way less red and as you can see, awake, then the stored update fires, then the fixed update, then the update and at last, the late update. And we can also go frame by frame. And as you can see, that we are actually getting new ones. And as you can see, now it's all the same right now, because right now we're actually going frame by frame. And the FPS is, will basically mean it's 0. And then I go frame by frame. Therefore, they're all in sync. Right? The other thing I wanted to show you, because what we've not seen yet is the one we've not seen yet is the destroyer. And the destroy method we can actually call. We're going to do or we are going to destroy this object. What we're going to do is we're going to have a new private void. And we're just going to call this just the test method. Because why not? And this test method is actually going to do two things. One thing, it's going to output something. It's just going to say, Hey, that's pretty cool. And the second thing that it will do is it will destroy this object. So as you can see, destroy is a method that we can call. And this destroy method takes an object. So we can literally put anything inside of this. And it actually already suggests that either want the Game Object Transform to destroy the game object to be destroyed. So this then destroys exactly this one. So this destroys at this example here. And we will see this shortly. But what we will do is we don't want this to happen immediately. What we want is we want this to happen after a fixed set of time. And for that we can use the invoke method. And the invoke method is a mono behavior method that as you can see, invokes the method, the method name in times of seconds. So if we do invoke and then we call the method name is test method. So let's copy this over because the name has to match exactly very important. And let's just say four seconds. So after four seconds, with this invoke, the test method is called, which will print out, hey, that's pretty cool, and then destroy the game object. Therefore, also outputting this onDestroy method, as well as stopping all of the update methods because they're associated with this particular object. So that's a lot once, Let's just see what will happen here. So if we stored it once again, what we've seen before, let me, let me make this a little bit bigger. And as you can see, hey, that's pretty cool. Basically destroyed and then the count has stopped, as well as the object no longer being there. So it has been destroyed here. And if we now basically stop this, the object is back again. Because this is exactly like we've seen before. The data basically resets for the when we stop it. And yeah, that is the idea of having a few, so a few mono behavior tricks so to speak. We can also look into some other. So if we put in this dots, then we can actually see there is a whole bunch of stuff that we can call. And if you have a few methods here as well as of course, a few different types of properties. And yeah, those are basically some of the things that we can do. We can of course, also look into mono behavior itself. I believe if we press Control. So if you hold Control and then click on moral behavior, we can actually see the metadata here. So those are basically the different types of methods that are able to be cold. And yeah, but right now, that's not too interesting. Right now I think that we've seen actually quite a few things already. Basically destroy an object and a few other things all associated with this mono behavior. And yeah, that would actually be it for this method, mono behavior is a very crucial part of this unity framework. So there's definitely a, it's an important thing. So to understand this is really important. So like always, but in this case, especially if there are any questions like always feel free to ask and I'll be sure to respond. And yeah. 50. (Unity Basics) Short Maths: Vectors: All right, This is just a short little addendum I made to explain vectors and the math behind them. This is really useful to actually understand. And while we're not going to go into crazy detail, we're going to look at a few things so that you hopefully can grasp the basic concept of vectors. So first we're going to start with something. Everyone should be familiar with the number line. Now as you can see, the line goes from 0 to five, and of course beyond that as well. But for our purposes, this is all we need. You could imagine yourself being somewhere on that line to know your location. You would only need to know one number, the number you're sending on, right? So this would be a one-dimensional line in this case, because only one numbers needed to know where you are. Let's add the negative numbers as well. Is this still one-dimensional? Yes, it is because we still only need to specify one number to know where we are. It can be negative or positive, but was still only one number. What does this have to do with vectors? You might ask, well, we can represent that number as a vector. So the two then becomes an arrow from 0 to 20 in this case, and often other cases is called the origin. We can have different vectors. Let's see some examples here. We have a vector with value2, value3, and value negative three. If I were to ask you to add the numbers 23 together, you'd say, well it's five. Well let's see what happens when we add the vectors together. Here we have a vector with value2 and here with value three. How can we add them together? We could imagine the vector with value3 traveling down the first vector. And after it's made that journal look what we end up at five. So two plus three equals five. The same thing can be done with subtraction or rather negative numbers and vectors. So 5 plus minus three is equal to two. This might seem completely obvious to you because this is how you add and subtract numbers every day. But what if we go one dimension higher into the second dimension? Now we have two number lines. This one is traditionally called the y axis, points upwards and as vertical. The other one is called the x-axis, and it's pointing to the right and is horizontal. Looking at the same example we had before, the two would now be written as 2 0, because now we need two numbers to identify where we are on this grid. We go two steps into the x-direction and 0 steps into the y direction. But let's say we want to end up here. Well, we need to go five steps into the x-direction. In three steps into the y-direction, we're going to call this vector a equals 5, 3 with value 53. And we might want to add another vector on this, possibly be equals minus 2 and 2. We can take exactly the same trip before I simply sliding b along vector a, we can get to our destination C equals 3 five. And as you can see now, the addition and subtraction is simply an addition for each number of the vector independent of each other. So if you take the x value and add or subtract them. And if we take the y values and add up, subtract them, whatever it is, the sum, Those are the new values of the new vector. Multiplication is just stretching the vector. So if we have 2, 3 year and we multiply it by two, and we just stretch the vector so it becomes 46. And division just make some shorter. Now for our purposes, we're actually be using vectors in three-dimensions, but it's just as easy as in two-dimensions. Thank you for listening to this lecture on vectors. I believe it is an important part of mathematics to understand, especially when trying to develop a game no matter what engine or system you're using. And if there are any questions, of course, always feel free to ask and I'll be sure to respond. And yeah. 51. (Unity Basics) Transforms and Vectors: All right, let's continue the basic unit introduction here for the unity course. And in this lecture we're going to take a look at transforms. So we've seen a few things, the mono behavior, and now we're going to take a look at some of the constituent parts, as well as if we click on one of our GameObjects here, we can see we have this transform when we had the position, the rotation on the scale. And we're going to take a look at that in a little bit more detail. So let's create a new scene here. So this scene is going to be L for transforms. And let's open it and off-screen. It's simply called transforms as well. Transforms, very important that it's with the S. So we have transformed. Otherwise, we're probably going to have an issue with the actual transform script. So or part. So let's do spread from transformed zeros 0000 at the transform scripts here. And then we can simply double-click to start it. And then we can think about this. We have seen this already. So let's debug dot log exactly this, this dot transform. So this is the transform attached to this game object. So simply will return the actual transform component. So this one here. So let's see how this looks, how this actually outputs. And as you can see, it doesn't do anything. So we actually have to go in a little bit better than this. So this simply says, right, this is like a transformer class. Now, that doesn't really get us anywhere. This transform, however, has a few components, this being the position. So this is a vector of three. It has the rotation, which is a quaternio. I'm going to say what that is in just a little bit. And then there's also the scale, which is divided in the local and losses scale. And this is also a vector three. So let's do something like that. Maybe. Yeah, local and lossy scale. And so first of all, the vectors, we've seen this in the last lecture. What a vector is in this case, these are three-dimensional vectors. However, the two-dimensional vectors are functioning basically the same way, just with the last axis not being important. What a quaternion is, is it is actually a four-dimensional, it is four-dimensional construct to represent rotations in three-dimensional space. Now that sounds incredibly complicated at first thought. And it can be quite complicated. But the good thing is that the rotation can also be converted into a vector three, basically, because most of the rotation can be done in Euler angles, that is simply a mathematical way of expressing the rotations as well. You've made, might've heard of it when you maybe with a plane, there's the yaw and pitch. And that is something that can also be described with that. And rotation like that then works. You take basically a particular axis. So for example, you say we're going to basically take a point and stick it through the x axis and then rotate around that. And that is the way that this rotation also basically functions. However, in our case, the rotation, we're going to look at that maybe in a little bit more detail as well. But right now, the important thing is that in 2D, only really the Z rotation matters to us. Because the Y rotation would be in this plane, which or rather in this plane would just make any sense. And the expectation would be in this plane which doesn't make any sense. Only going around like this really makes sense for us. Anything else in 2D doesn't really matter. So let's actually go back here and debug log each of those things. So this dot transform, dot position. And we can copy this with Control C and paste it Control V, get the rotation here and get the local scale in this case. And let's, why not also get the other scale? So if we put in scale, as you can see, there are two of them. There's the local scale and the lossy scale. There are actually nicely comments there. So we can actually see the world space position of the transform. We have a quaternion that stirs the stores the rotation of the transform in world space. We also have the scale of the transform relative to the game objects. Parents, I will explain what that means in a little while. And this is the global scale of the object. So when we look at this, output, this and see what we actually will get. And the first thing is this, how the vectors basically look, right? So it's three components, just like here. So the position is going to be 000, 000, the rotation position is 000. And then one, like I said, a quaternion is basically a four-dimensional vector that expresses the rotations for us right now. Let's not think too deeply about it. Let's just think about it. Okay, We have four numbers that somehow represent a rotation. But we can also do it with these three numbers. And then this might change accordingly. The scale, both local and lossy is the same right now, because this is simply a, a game object that is at the root. So what we can do basically is if I put in a new empty, so I have this selected, right-click this, say Create Empty than it go. It's going to create this game object as a, as a, basically a child for this game object. So this is the child object so to speak. And this is now, it basically has two scales. Because if we were to scale this parent, then the child would scale with it. And if we were to scale just the child. Just the child gets scaled. So if I were to put in the scale to 22. And then as we will see, if I start this and first of all, we're going to have 22 and both of those, because the, the parent, that's fine. However, if we disable the transform script on this one, go to the child script and put the same transform script on this one. Even though the scale here is 1, 1, 1. We start this. You will see that the local scale is 111 because this is scale itself. However, the lossy scale in terms of how the world looks at this is two to two. Because the this gets basically yeah. Added. I believe that it is multiplicative, right. So that's yeah. So it's multiplicative. So the, so if this is three times as big in any direction, and this is also three times as big, of course. That makes sense. That's basically the idea of local scale and lossy scale. And there is also one last thing which would be the local position. There's also the local rotation. And once again, this is relative to the transform of the parent and the local position is relative to the transform of the parents. Let's just take a quick look at that. And let's actually like a quickly add the this because otherwise we're just going to have crazy numbers out there and we don't we're not even going to know what those are. So this is the position, this is the rotation. And just for the hell of it will add the local rotation as well. Because, why not? If we're here, then we can quickly look at this. So this is the local rotation that we want. And then this is going to be the local scale. We're going to quickly turn this over. So we're going to put this down here because we always have the local, the bottom. So let's make this a habit. There you go. All right, so we have the position, then we're gonna put the local position out, then the rotation than the local rotation, the scale and the local scale. So let's quickly take a look at this. Let's just start it and see what we will see. So the position is 000, 000 local position zeros. That is makes sense because both the transform as well as the child have depositions zeros, therefore, nothing changed the rotation. Is that the same because that is exactly what we had. And then the losses, the losses scale. So scale compared to the world is three. Local scale from itself is one. So let's, for example, turn this 90 degrees in the z direction and then the child, we could, for example, actually let's then also move this five up. Let's actually only move to up. Then what we're going to see is that the local scale on the local position will not change, as you can see, because locally this child is still right here. So local is basically the axis of this. And then in terms of world position, so the normal position is now at 0 to 0, because this child, if we look at this one, is located right here. So even though locally, so if this would be the root. This one is at 000, 000 because it's exactly the same position as this transform in times of the world, It is moved. And same with the rotation. As you can see, this is now a little bit different here. Like I said, the quaternion. You don't need to understand them right now. Just note that this is different than this rotation Basically. Yeah, and that's sort of the whole idea here. It's a little Can't get a little crazy. Usually. Simply what you must realize is that if you have child objects and children, then they can work a little bit different than normal objects. But usually it is, which we can also see here. We can set actually move the rotation and the local rotation, same as with the local position and the normal position. The only thing that we cannot set is the lossy scale. We can only set at the local scale. Now for objects that are, that don't have a parents of where the parent is basically the root. This doesn't matter. You always want to set the local scale anyway. And just so that we have done here, what we're going to do is we're going to just quickly do a very like the easiest movement that we can. And this is going to be this dot-dot-dot transform translate. So this is a method that we can call on this transform. And as you can see, we actually have a lot of methods that we can call. So there's a lot of things. So there you go. So that as you can see, there's a lot of things on this transform that we could call. And right now we're going to look at translate. And what this does, as you can see, moves the transform in the direction and the distance of translation. So we're going to move this. If we can look at this, this needs a vector three translation and can also take a space relative to. This, simply means that it will move along a certain vector. We're going to give it a vector two dot, right? So this simply is the 0 vector, so one in the X direction and 0 in the y-direction. And we're going to times this by a times a times Time.deltaTime. And this delta time is basically completion time in seconds since the last frame. Idea being that we want this to not be, to not move this at an incredible speed. But we want this to be toned down a bit. Basically. Let's just see what this will do. We will actually, for the purposes of this, we're going to disable the child object and the script here. I'm going to turn it on for this transforms. Because that's a more interesting right now. And yeah, let's just see, so this should change the position. And it should change this exposition. Let's actually also disable the rotation here because otherwise it will get a little bit funky. So if we look at this, as you can see, it now moves into the x-direction. And if we go into the scene view, we can see that it actually is moving slowly but surely away. And yeah, that is, like I said, a very, very basic and simple movement that we can do. Of course, in theory, what you can do is you can also take your own vectors in here so you can create a new vector because the distance they are is important. So how big the vector is important? But yeah, overall that is a basic overview of the transform component, let's say. So this is the most basic of components that every game object always has. So this is always present in any script that has the mono behavior as a base class, you should be able to do this dot transform and change the positioning or the scale or something like that. And as you can see, there are some other things, child count, you can get children. There is a way of getting components and there's also a way of rotating this object. So there's a few things like you, like usual, I would probably suggest taking a quick look at some of those things, but of course, a lot of them we're also going to take a look at in future lectures. And then a real application we'll see once we actually start making a while, basically a real game, right? A real game as a game where we can place. So that's, that's kind of exciting, but we're building up the very important things. So this is another one of those things that is actually quite important, transforms a crucial part, basically signifying where in the world a particular object is. So once again, if there are any questions, feel free to ask and I'll be sure to respond. Hand. Yeah. 52. (Unity Basics) GameObjects in Unity: All right, welcome back to the basic unit introduction here for the unity course. And in this lecture we're going to take a look at a game objects. So we have talked about this or I've talked about this for a while now, I've always called the basically constituent elements of the scene game objects. And this is exactly what those are. And we're going to take a look at them now in more detail. So let's create a new scene here called El Nine GameObjects. And then we will of course, also create a new script and we'll call this game objects as well. One important again with the S at the end, because otherwise we might run into some issues with the name. So a new empty GameObject is needed. Also, let's call this game objects and 000, 000. Once again, this is just for me because I really need this to be 0. I don't know why, but I want my empty game object to be at position 0. Now before we go into the script, we will actually need one more thing. And that is something to basically visualize our very nice a game object. So we will actually add something to it so that we can see this. So let us do this as following. I'm going to quickly have, I have a folder on the different on, on another screen and I'm just going to drag in to hear a PNG. So this is going to be a PNG file instead of the sprites. But this of course is available as a resource. And this particular thing is, as you can see in the Inspector, we now have this texture 2D instead of here. It actually has already seen this as a sprite. And there's actually really nothing that we need to change here so we can just keep it like this. We are going to in a future lecture go into the sprite, basically a Sprite Editor and how this works in a lecture and see what we can see there. But right now, we're going to do is we're actually going to add this as a game object. So we can simply take this and drag it into our scene. And just like this, it creates a new gameObject as you can see. And this is a well then simply situated here. What we're going to do is because this is a little small. We're just going to increase the scale here to something like five times five. And what will, you will also see is that it is a little blurry. We can fix that by changing this filter mode to point and then clicking Apply, and then it is no longer blurry. I will explain these things like I said a little later. Instead of a sprite, right now, we don't need to really concern ourselves with that, but now we actually have something. So let's also centroid at 000 and then move it up a little bit like probably like three. Yeah, that's good. So now it is at the top of the screen. And if we switch to our game view, this is now what we would see inside of the game. So we would see this ace of hearts basically floating here at the top. And we will be able to do a few cool things with this. We're going to rename this to cart because it is a card. And we're going to, we'll just see what we can see. So right now this is a object with a transform component, the sprite renderer component. Just like with the spread some salts, we're going to take a look at the renderer in a little while. Right now. We just need to know that, okay, this is basically they are so that we have a visual for this object. This of course being an empty object, we don't have that, however, we have the script on here. And what we're going to do is we're going to double-click this and actually start to program something right now. So the first thing that we want is we want a new field here, and that is going to be a private game object called card. And this is the cool thing because like I said, instead of the hierarchy, the individual things are game objects in there. And we can reference those by simply using a new variable of the type of game objects. So this is simply a class will, because this is a private world, make this a serialized fields so that we can actually see this inside of the spectrum. And then instead of the start method, the question really becomes, well, where is this called right now is just going to be assigned to it. Well, let's just take a look. So as you can see right now, there is no game object on here. And if I were to do something with this card, then what would happen is that it would simply not work because this is null. So the, it has not been assigned because this is, as you can see, num means there is no game object here. Now what I can do, and this is the really cool thing about the Inspector. I could actually drag this in here. And as you can see, it actually sees that, Oh, this is a game object. And if I put it in here, I can see that this court is now referenced inside of this particular variable. However, we usually don't want this because not always, it's not always a great idea to assign things via the inspector. Sometimes it can be fine, but I also wanted to show you how you could do this inside of itself. There are multiple different ways and one of them is basically one of the easiest. So what we can do is we can just say cord is equal to game object. So the name of the class dot find rather. And then inside of this method call, we can call, we can put in a name. In this case, this would be called because this is the name of the object. We can just check this again. Yep, this is the name of the object is called card, and this is what needs to get in there. So this is a static method from gameObject that returns a gameObject, as you can see, finds a gameObject by name and returns it. So this will look through the entire scene that we have Open currently. Search for the object with the name given here and return it. If it finds it. If it doesn't find it, of course, it's still going to be null. So let's just see if it actually finds this by doing something like card dot transform dot position. So we will simply get the position of the chord that we have just seen there. And yeah, let's just see if that actually works or if it doesn't. Because right now, of course the court, the court doesn't have any script associated with it. We are now getting this, this game object via this script here and taking a look at, so let's just store this and see what happens. So the first thing that we can see is that this card variable has actually filled. So it has found the card with gameObject dot find. And we also see that 0, 3, 0 has been output and this is exactly the position of the cart. So everything has worked exactly like we wanted it to. Which is pretty cool. So this is one way in which we can look for a game objects and then yeah, Even, even manipulate them, right? So we've seen the transforms last time. How we can manipulate those, changing the position. And of course we could, for example, do this in this as well. But I wanted to show something else because there's something else that's really interesting and that is spawning new game object. So this is all sort of a part of game objects. And what we can do is we can basically make a new game object variable here. So game object and set this equal to instantiate. Instantiate is one of the, one of actually object methods. And then we simply give it a, an original object, which is this chord. So this might be a little weird. What are we doing here? Well, this instantiate method simply creates a new gameObject based on a given game object that we give it a sort of as a template. This can also be called a prefab. And we're going to look at prefabs in a little, little like a week later while. Now I just wanted to basically quickly show you that we can sort of spawn new GameObjects. And this new gameObject now is of course saved in this game object variable. And they are, we can set the position, for example, at new vector 3 and then something like 0, minus three. And minus three, f ends in 0, something like that. And yeah, Let's just do that and see if that works. So in the beginning, we should see a new card appear with a name card clone. Exactly. And this is at position 0 minus 3 0. We're going to take a look at the instantiates a method in a while in more detail later down the line as well. I just wanted to mention it quickly because this is also a very big part of the game objects. And overall, it is going to be the GameObjects. That is the main thing that we're going to talk about. So it's always going to be made GameObjects. It's always going to be components and it's always going to be scripts. And yeah, those are sort of the building blocks. Idea is that we have different types of components and GameObjects can basically take almost any type of component onto them. Scripts or a particular component transforms. And like we've seen the sprite renderer, right? That has the ability to show us something like an image. And there are so many more in sort of these components here, right? So those are all of the different groups. And then for each of those, There's a lot of them. So we're going to go piece by piece, you know, little by little. We're going to learn more and more. And hopefully at some point then we will be able to make a small little game. Let's see. That would be a great idea if that would actually work. So that is the gist of game objects. It can be a little daunting at first because there is quite a bit to them. Now, of course only shown a few things. If we put in gameObject dot, we actually don't have fat, many different methods that we can call. So there are methods like in here. But what is interesting is that the, this call rate is exactly a GameObject. So this returns a game object. If we take a look at this. So the, let's go for the transform. There you go. And so the distort transform is exactly something for a component in this case. But the, this refers exactly to the game object. So we can also say this dot GameObject, and then we can get exactly the GameObject that this particular script is attached to. So this would be the script and then this dot GameObject returns the actual game object. As you can see that this component is attached to. And yeah, there are a lot more things and I'm pretty sure that a lot of them you're going to pick up as we go along. Because we could make an hour long lecture just about GameObjects. But that doesn't really get us anywhere because there are so many things that you need as sort of a prerequisite to understand other things. So sometimes it can be a little bit jumpy, but I think overall we're going to have a good through line to understand each particular part. But anyway, Enough said this was the lecture on a game objects. I hope you found it useful. And I would of course, really appreciate a review from you. Otherwise, if you have any questions like always, feel free to ask and I'll be sure to respond. And yeah. 53. (Unity Basics) Input Methods in Unity: All right, let's continue with the basic unity introduction here for the unity course. And in this lecture, we're going to take a look at inputs. So inputs, basically if you press a key and then a certain thing happens. How can we do this in Unity? Well, let's figure this out. Let's create a new scene, L ten, called inputs and openness, like always creating an empty game object in here, also calling this inputs. And lets. After centering this at 000, 000, let's also create a new script of the name inputs. One could have guessed, but there you go. Now, we will not need the start method here. We only need the update method for this one. Because the update method will basically run every frame. And if we press a key, then something will happen. So how can we do this? Well, we put in an if statement and then we will call the input class dot, get key down. So this is the method that we want, so returns true during the frame, the user starts pressing a key, and this key is accessible by using key code dot. So key code is an enum. And inside of here, as you can see, they're all basically a whole bunch of different key codes. And let's just take for this one f. So press F to debug dot log. Rest FQ. I like it. So in theory, if everything works, this should be true once I press the F key. So I press it and this will get output once, because in this case it only gets true ones. So let's just see if that actually works. Also, making sure that the input script is on here. Very important. Right now, nothing and then F key, and there you go. Now what I can do is if I hold the Shift key, as you can see, it does not increase. I'm still holding the key down. You simply must trust me for this one. But indeed, this does not increase. And if I let it go, I did that on purpose. So maybe you have heard that. So let's see. There are of course, other things that we can do. And that is exactly right. So there's an input dot key and they get C0 simply also takes a key code. Let's also give them F here. Let's just copy this over and say pressing F key. And then just for completion, I'm just going to the other one. This is Get up. And that is called, that is then stopped pressing F key grid. So the key down is true once I start, once I press the key. For only ones get key, as you can see, returns true while the user hold down the key identified by the key, key called enum parameter. And they get keys true during the frame that the user releases to the key. So we have the ability to check whether or not a key has been pressed once. Or rather. Like. Let's just see what happens here. So I press F and keep it pressed. As you can see, pressing F key, it only, it actually stops if the focus is not no longer on the game. Because if you look at, so we can see if I do this and then I stop pressing because they stop pressing here. But you can see that this is now in focus because of this slightly blue line here. And if I move over here at some point it might, maybe because I click away, then the focus shifts and then of course this is no longer running. So this is most likely what happened here. That for some reason it yeah, there you go. Now the focus shifted and then this will stop of course. So that's one thing that's very important to realize as well. But nevertheless it still works very well. And as you can see, if I really like, try to like just click it once and still like 40, 7, 2, 4, 7, 1. So even they are because of course our frame rate is so real high. We press this a lot of times, even though I'm pressing it like for like barely like a second, we're still going absolutely crazy. So, yeah. Yeah, but that is a basic inputs. That's actually all that there is to them. It's just like very straightforward if statements. That's all that there really is. And those simply return booleans. So of course you can also chain those together, right? So input get key down with kicker f. And then if, for example, you could use some of the Boolean operators, some of the logic operators, the end, and then basically put those together with another key code. So yeah, that is the inputs very basic. And that actually allows you to already make some crazy cool stuff. And what we're going to see basically next pre-lecture is making a very simple movement script. Now, there is something that you can also maybe think of if you think back to our transforms, we had a very, very simple movement there. And if you now apply the inputs and basically what we had in the transforms lecture, maybe you can already figure out before watching the next lecture, how we might be able to create a very, very simple movements script. Yeah, but with that, I will leave you and I for now, for this inputs lecture, it was of course, one of the most important things for a game. I know that, like I'm always saying, well, this is one of the most important things, but this might not be important how exactly it works. But inputs itself is important for a game. So the inputs could probably have figured them out on their own. But nevertheless, this is the inputs lecture. And in the future there's a little bit more nuance. So might as well show you just quickly. So the input class already has, as you can see, way more stuff as well. So this isn't the only way you can get the input. There's quite a few things that you can do. But for now, this is the input that, you know, I was. I think that makes sense to show you. And then further down the line, if we ever need anything else, we're going to see that as well. Yeah, but for this, it is the end of the lecture. I hope you found it useful and like always, if there are any questions, feel free to ask and I'll be sure to respond. Hand. Yeah. 54. (Unity Basics) Creating a Very Simple Movement Script: All right, let's continue with the basic unity introduction here for the unity course. And in this lecture, we're going to create a very simple but yet effective movement script. And for that, of course, we are going to, first of all create once again a new scene. This would be L 11 movement, a movement. And let's immediately start this. And this time we're not going to create an empty GameObject, but we're once again going to simply take the heart and put it in here and actually size it up. Let's size it up to about four times its normal size. And started at y level two. And then we're also going to make a new script. This is going to be a script called where is it? No, I missed it. Apparently, there you go. Movement. Movement. Yes. And let's open this script up and see what we can see. So first of all, we're going to have a few things in here. The first thing is going to be a serialized field, is going to be a private float called speed. And we're going to set this to three. For the moment. We can of course change this up later down the line. Because with the serialized field, this is of course available to us in the inspector. And what we're also gonna do is we're going to create a private transform, which is just going to be my trend strands form. And this is simply going to be set to. So my transform is equal to this transform. We don't necessarily need to do this. However, in a later lecture, we're going to learn about gets component and why caching it like this is a very smart idea like this. Doing this is actually quite. And then we're going to create two different methods because we're going to start doing things in a way that is, let's say readable. At most, like that would be great. So we'll have a run method and a move method. Nope, normal move method. There you go. So this one, Let's just take the curly brackets here and then, and those two are, will be called inside of the update method. So r1 and then move. So this is something that is a good thing to think about. A usually it is best to separate each of the functionalities in your update method into like different methods. And then simply have them in here. Because now if I go into this code and see, oh, okay, first I will, I will call run and then I will move. This. You know, the naming might be a little bit different, but in our case I think this is going to be fine. Now this move method is going to have exactly what we have learned in basically the previous few lectures. So first of all, the input.txt gets key, not get key down, but get key. And then with a key note with a key code. So this is the enum keycode dot. Let's take the w. So w will move us up. So this will then do the following. I'm actually yeah, sure. Let's do it like this. Let's let's actually let's first of all do it like this. And then I'm going to show you another way of doing it. So my transform.py translate, oh, nope, translates. So this is the method call that we have used. Last time. This was the method call to basically move something. And we're going to put this in vector two dot. So this is the upwards direction with Time.deltaTime times speed. So this is basically the call that we're going to do, that we're going to make because then we're gonna move the way up. So 0, 1, x being 0, y being 1, delta times, once again for making it so that we don't, it basically makes this more or less like the fixed update. Not quite, but let's just call it that for the moment so that we don't have a crazy, crazy like big number. Let's also do WASD for the sake of argument S and D here. And then a would be the left, S would be vector down and a vector to write. So that's fine. And we will test this with this code for now and then we will refactor a little bit after we've tested. So let's take the movement script and add it to this chord. And then let's go in and see if this actually works. So if I press the Esc key, we move and if I keep it pressed, then it moves and the card indeed moves. Now what you will notice is that the diagonal movement is a bit faster than the normal movement. This is simply due to the IEP. This is due to the like adding because we are moving, let's say urban speed of three in this direction and the speed of three in this direction. And then in theory, we should be moving in a speed of six in the diagonal directions. Which of course is not really what we want. However, we are going to ignore this for the time being. First of all, what we're going to do is we're going to think about making this a tiny bit more readable. Now this is not the biggest thing and we don't necessarily need to do this. But as you can see, this is like a very like this is almost always the same, right? This, this call here. It's always my trends from retranslate. And the only thing that changes is this. And if we have that, It's actually fairly easy to once again make another method or this, so this would be, for example, move to could be the thing or we could, we could also just call it move again. Because we are going to have a perimeter in here that is going to be a vector to quote direction. And then we can basically just copy this over because this is, we're only going to use this ones. Put the direction in here. The speed is going to be taken, of course from up here, so that matters not. And then we can basically say Move to and then say vector to dot. This would be right. And then basically just switch this up. Like this, boop, boop, boop. And then just making sure that we have the correct ones here. This is left and this is down. They go, right. This is just one example. At the end of the day, there really isn't a like a right or wrong answer to this. However, I will say that I believe that this is probably better to read. We could also say maybe move in direction. This might actually be a better name. And if we want to change this name will be can do is we can hit Control R two times. So basically control RR. And then we can change this, so move in direction. And then this is even better to read. So this, I believe, is even better to read. So we can see, okay, if the key gets pressed, then move in direction vector dot-dot-dot. So we know our case. We're moving into the direction up. Actually like really nice to read. And overall I think a good method to basically refactor in this case, right? So what has it to do with this run as well? So we also have this run method here. And what we're gonna do here is we're basically going to do the following. So input.txt key down. So if we press the key ones, then what we're going to do is we're going to say heat or left shift, just for the sake of argument right now. Then we're going to set this speed to five. So basically, once I have pressed it once, then we are going to put the speed at 25. And then we're going to copy this and say, if we get key up, then we're going to reset it to three. So this simply makes it so that we can run. Basically. There are some, let's say, issues associated with it that we're going to look at as well. But let's just see if that works. So first of all, our normal movements still works. And then if I press the Shift key and move them, as you can see, I am faster than I was before. And then if I stop holding Shift, then it works so I can in bursts basically run. That's pretty good. Now, one of the things that, of course I could do. So right now, I have the Shift key pressed. And because it looks for the get up, I can basically click out of this window, stop pressing the shift key, go back in. And now I'm always running. We can also see this at here. The speed is five now. And now I'm always running. Now this is something that you need to think about as well. It's just a short little thing that I wanted to mention just for the moment. And now let's also think about the idea of the, the doubling. So the doubling happens because like I said, when we look at this, if I press both W and E, both of those directions are going to be moved in. And then basically the translate is going to both move into the direction of like right, with these additions. So let's just say for the sake of argument is going to move into or left rather. So it's going to move into direction minus 1, 0. It's also going to move into the direction 0, 1. And those basically get added. And the diagonal movement that then is faster, that because of the, just how the vectors work. Right? Fixing this diagonal is actually, I wouldn't say impossible for the translate. However, it is going to involve a little more finesse in this case. And this is something we're not going to do, especially because the Translate method actually is not always the best movement way, like there are better ways to ensure movement. And usually as well, the diagonal movement. If it, it doesn't really matter whether or not the diagonal movement is faster or not faster than of course, that is actually not of real concern. But right now we're not going to fix this because in this instance is actually isn't an issue. And also because of the fixed would actually go a little deeper into how this works and would make this a little bit more complicated. And this is supposed to be a very easy movement script that simply works. Now this is of course, a movement script that works for sort of a top-down views or sort of a Zelda view in this case. But this can be adapted to a platform type of u. Wait for the jumping and the different, let's say diagonal movements. So there's a different way with that. We can basically use the movement system or create a different movement system. Let's say that's, is something that we're going to take a look in a later lecture. However, rest assured, this will be looked at at a later date, right? So this was it for the very basic movement. Now you actually have a card basically that can move around, which is pretty cool. All things considered. So we've come quite a long way. And overall that was it for this lecture. I hope you found it useful like always. If there are any questions, feel free to ask and I'll be sure to respond. And yeah. 55. (Unity Basics) Mouse Input: All right, let's continue with the basic unity introduction here for the unity course. And in this lecture, we're going to take a look at a mouse inputs. So we've already seen normal inputs and then a little bit of a movement script. Now we're going to see what basically the inputs could be with a mouse. And let's create a new scene for that, that is going to be L2. This is mouse, mouse inputs. And then of course also a new script. This is also going to be called mouse inputs rate. Okay, let's immediately hook this up to an empty GameObject, also called Desmos inputs. Why not? And then centroid zeros 0000, just for my own pleasure this time. And let's open the mouse input script and see what we can see. So first of all, let's go through the different buttons. So we have input, dot, get mouse button down. It's almost like Unity. Listen to what I was saying. And instead of here, we actually have to specify the button by integer. So let's just see what those are. So debug dot log and let's just say Watson 0, just for the hell of it. And then let's add one to it and three, why not? And see which ones those are. So Button 1, 2, and 3. And let's just quickly try this out. So the script is attached to the gameObject. So let's just see. So if I do a left-click is 0, so left-click is about 1000. Right-click button one. And the middle mouse button is been too. Now, I actually don't have another button on my mouse, therefore, button three. Well, it doesn't exist for me in this case. If you have a mouse that has multiple buttons, so more than, let's say the left, the right and the middle mouse button, then you can actually access them also with simply increasing the the index given year. Now this you will probably have to try this. And I don't know how reliable it is when switching from mouse to mouse. So probably be careful if you go down this route. But yeah, yeah, and then we will have to look at something. So now we're going to take the mouse position, which is very interesting. So debug log input dot mouse position. And this is very interesting. However, the mouse position can be especially in the beginning, a little confusing. So let's just, let's just see the mouse position in action. So we will see the mouse position every time I basically click the left mouse button. So we're not going to constantly have it, the output in the console. But every time I basically left-click, we will have this. So if I go in the middle of the screen, we have the most position of 9635. 71 and say, okay, let's go at the very top of the screen. And there we have 0 and then like 1000 and something. So let's go at the bottom left of the screen. Try to go as far as donors we can, and then we have 0.514. So the idea here is that the bottom left of the screen is basically 00 and the top right of the screen, if I can manage to hit it, I yeah, basically hit it. It is basically the resolution. So 000. And then up here is basically the resolution, in our case, full HD. So 1920 by 10 ADP. And this is the normal mouse input, so the other mouse position rather. And we can however change this. So the issue being, well, I mean, maybe I want the actual coordinates of the world. So if I click here, I want 000 because this was 000. So how do I get this? And this is a little bit while I wouldn't say like necessarily only confusing, it can be a little bit weird. So this is something I also sometimes have to look up because there are different ways that we can basically project our mouse position onto something. And what we're going to use is we're going to use the camera for this. And we have not talked about the camera yet. However. And this is a very simple method that we can use. So we can use the camera script. So camera dot, this simply gets the main character of this particular scene. And then we will use dot screen to world point. And this will return a vector of three, as you can see and requires a position. So this position is that then of course, in this case, input dot mouse position. And this will, as you can see, transforms a point green space into world space. Where what space is defined as the coordinate system at the very top of your game hierarchy. So the screen position is exactly what is given here in pixels. So let bottom left 000, top right screen resolution. So width times height. And this then basically transforms those into the world space. So let's see what we can see there. Once again, we will get this when I left-click. So let's go to back to the 00. That's actually negative because I was out sort of the screen. So that actually also works. Let's try hand actually stay inside of the screen. Yeah, that's okay. So as you can see, somewhere along 000, we're at a minus eight, minus, let's say minus nine, minus five and minus 10. Now that should actually work out. Because once again, in sort of years, so the middle we are at 000 000. I almost hit the exact middle. That's, that's pretty good actually. So we remember that the camera is at position 0, 0 minus 10. This is where this minus 10 comes from, because we are basically in the plane where the cameras sits. So if I were to adjust this to minus 5 and click again, then all of a sudden we would be at minus five. The Z position simply corresponds to the z position of the camera. So that's kind of important to know just for your information. Now this is the screen to world point to point exactly. There is also one other thing. This could be fairly useful. This is also accessible via camera dot, and this is the screen to viewport point. This is input.txt mouse, mouse position, of course. And this one, if we take a look at this, is going to be the following. If we started again, then the viewport, if we try to go 000, we're not quite at 000. Let's try to get this leg properly. Actually, let's clear this up. This is the viewport. So this is 000, 000. The actual position was 0529 and then the world position somewhere in like minus 9 again. So we've seen this already wise, the zeros 0000. Well, up here, if I can get it to the very top is 11. So this is basically, as you can see, a sort of in the middle is 55 as 0.5.5. So the viewport is 00 at the very bottom and 11 at the very top. Might also be useful for some things, but those are sort of the main changes. I will also just quickly add the comments that I have here. So I've already prepared some comments for each of those so that we can actually think about this a little more. I've already explained this. Like I said, most vasopressors can be a little bit confusing because we have to sort of translate this from specific, you know, from the screen space to world space and so on. And there are also multiple other ones. So as you can see if I go here. So the screen, we also have uracil and we can go view ports to screen and so on and so forth. So we can change it up. We wanted to. This is why I said that sometimes I even I have to still look it up because at the end of the day, yeah, that's just sometimes how it is. However, normal mouse position at the bottom left, 00 at the top right, width times adsorbed with height is the the vector. For the screened worldview represents the coordinates instead of the world. So if we click in the middle of the card, we actually don't have a card right now and we can just test that out. Why not? So let's actually just pull a card in here. Why not? Then we can actually click this. So let's put this at, for example, 0, three and try to click in the middle of it. And then we should be able to see, let's try it and get really in the middle of that. Are they go 003, that, as you can see, and then negative 10, and this is what I was mentioning before. So the z position of the coordinate corresponds to the z position of the camera used. In our case, we use the main camera of this scene. Therefore, the Z position is at negative 10. And viewport, like I also said, 00 at the bottom left and one on one at the top right. So those are some of the mouse inputs. And reading the mouse position can be really useful for some things. Now, for clicking, let's say a different game objects, we can actually use a, a way easier method. We don't have to use this. And this is something we're going to see later as well. So we don't need to check basically always the mouse position inside of this node. The mouse position could be used for having a specific game object follow the mouse. Now this is actually something that you should probably already be able to do. So this is something that you might want to figure out. And yeah, but that was it for the mouse inputs lecture here. I hope you found it useful. If there are any questions like always, feel free to ask and I'll be sure to respond. And yeah. 56. (Unity Basics) The (Main) Camera: All right, let's continue with the basic unity introduction here for the unity course. And in this lecture we're going to take a quick look at the main camera. So we've already seen in the last lecture in the mouse inputs basically away with, in which we can take the mouse position and sort of converted into different types of points. So we've seen the world points. So screen to grow points and screen to view PowerPoints. And that was dependent on the camera. So those are one or two things. For example, the camera can do. There's also a few more. I can just quickly show you we're not going to create a new script for this. We're going to just look into the sort of the mouse input script. So camera.capture basically has a few different things that we can use. And actually quite a few, as you can very clearly see, there's a lot of things, you know, the pixel wide, orthographic, what does that, all of that mean, we can reset the camera. So there's a bunch of methods that we can call as well. But most of this actually usually doesn't, isn't done by script. We actually make the changes inside of our scene here. So here we can actually basically use all of those things which we've just seen in the script. So there's a few things that we can do. So there's a clear flags. We have depth only, don't clear and Skybox. And if we hover over it, as you can clearly see, there is actually a really well thought out explanations for a lot of those things. So what I'm going to just quickly going to go through these things. So overall, color, I mean, that should be self-explanatory colors, just the background color that we have. Culling mask basically is as you can see, which layers of the camera renders. So there are different layers that something can have right here. And if you want something ignored, so for example, if we go to the ace of spades, this is the default layer here. And if we stop rendering the default layer, then as you can see in the main camera and also in the game, it is no longer there. So this is, for example, something that you could turn on and off. The projection is very interesting. So if we look into this here, so orthographic simply means that if I quickly switch actually in the scene view to the three-dimensional space, and I zoom out a bit. So with the right mouse button, I can sort of pan the camera around with the middle mouse button, I can move it. So then you can see this sort of box that extends to basically the infinite plane here. And this is the projection that is being done. So it is a one-to-one projection, no perspective. So usually maybe you've heard of this. The, There's a perspective. So things that are Neera, you would draw bigger than things that are further away. This simple perspective basically, now the orthographic actually just has everything at the same size. Just for show, I will actually quickly size this, scale, this up to like 44. So we can actually see this a little bit better. And then the main camera, if we look at it again, and I change this to perspective, then as you can see, now, this projection cone is actually way more like a normal camera would be, right? So sort of like. And it's not really noticeable in this case. However, the actual object here doesn't really change all that much because first of all, it is a flat 2D sprite. And also, we were not really needing to use these projection. The projection of perspective basically is needed if you want a three-dimensional game. That's the easiest way to think about this. There's also a field of view in this case, we are, as you can see, we can make the projection further along or bigger apart. So there is actually an f of v slider here. And there's some other things we can make this a physical camera. I gotta be honest, I have never really played around with this all that much. And clipping planes simply means that where is the distance when the cameras stops the rendering? So let's put in the orthographic size. Are we actually also put in the size. So the size simply means the size of the prediction as you can see. So making the smaller basically simply renders a smaller area it in there. The clipping planes simply means, okay, when does this stop rendering? So if I put this at negative nine, then it's really, really close to the camera. Now, this doesn't change because the orthographic projection is just, oh yeah, that's just a 2D surface. If I were to put perspective and of course now the, it's gone. And if I move the camera up a little bit and is huge as you can see. So that's actually a really good way of showing the distance doesn't matter for the scale of the object. Only the scale instead of here actually matters really. And the clipping plane simply means that as this gets closer to the camera, right now we're at 0.4 away from the camera, still there. But if I go at point minus 9, 7, then we are 0.3 away. So this is just at the cusp. Where are we still see it? And then at 98, so now it's the only 0.2 away from the camera, and then it stops rendering because it is too close to the camera. This is basically what this clipping plane here, my control. So if I put this at 1.1, then all of a sudden, as you can see, the card shows up again. So this is the clipping planes. Let's actually make this, we can click this lock key and then whatever I click, the Inspector stays where it is. So that's actually kinda useful. The viewport is, as you can see, the indicate where the screen and the camera view will be drawn. I'm usually also something I've not really needed all that much. Let's actually put the heart's back. Where's the camera or negative ten? And then this one is, oh sorry, I'm, of course that's, that makes sense. Because this has, keeps being the camera of course 0, and then this one is at negative 10. So there you go. Okay, now we can see the ace of spades again. And if we change this amine, we can just change this. As you can see, the screen simply gets, I mean, Negative wouldn't be the greatest idea. So the screen, as you can see, simply gets smaller and it's actually gets shifted. And then this one, we, I mean, you can make it bigger but doesn't work. And then you can also make it smaller here. And then on the y direction. And the same happens as well. Like I said, usually don't really use the Viewport Rect o that much. Same with almost all of the other things. Especially because usually they are not really needed for two-dimensional games. There are some, something said about the depth may be. However, overall, I would say that this is a good short overview, right? So this is just a quick little look at this. With me. Basically the main things that we need for the two-dimensional game development in this case, right? But also most of the things in the camera really don't need to be changed. The only thing that might want to be changes the size of the cameras. So how much it actually shows, maybe also the clipping planes, although a 0.310104, it usually is enough. So that was it for this lecture. Just a quick little short overview for the camera. If there are questions like, always, feel free to ask and I'll be sure to respond. And yeah. 57. (Unity Basics) GetComponent in Unity: All right, let's continue with the basic unity introduction here for the unity course. And in this lecture we're going to take a look at the Get component method, which is a central method basically used to get the components of GameObjects. So the one example of this that we've seen more or less was the transform. But we have access this transform component by simply using dot transform and accessing it via a particular property owner, the game object. However, there are other components here. For example, the sprite renderer, as we'll see here, that was able to basically show an image. We had particular scripts. Those would also be counted as components, or for example, which we've also seen the camera component. And we can access those from other GameObjects within our scripts. In the interim, I have put everything inside of neat little folders here. So we're going to create a new folder. This is going to be L 14 get component. Now l 13 is missing because in the last lecture of course, we simply looked at the main camera. There were no scripts associated with it. And we also want a new scene. So let's just make a new senior as well. L 14 gets component. And inside of the scripts, let's first of all open the scene. And then instead of the scripts, we're going to create two scripts this time. One is going to be the example script that you go and you can already open that. And then let's also create another script. And this is the getting components script where rather this is what we're calling it. All right, so inside of our example script, we're going to first of all, delete the update method. We don't need that. And then we're going to just declare some nice variables. So how about a, an integer test value of a 100? And then a public float, which is another value. Which is something someone like, I don't know, like 42.1337 shirts, f of course. And then let's also do a public camera. The camera as a variable, which in this case it's not initialize and we will initialize this inside of the start method by doing Camera Main. So this will simply save the main camera in here. And as is very clear, everything here is public. Otherwise, it is not accessible through another script. Because in this case, or rather, yeah, it's not accessible from another script because this simply. We'll get the class back, but we will see this shortly. Let's also think about inside of our getting components. Let's actually make a private game object here. So this is going to be the card. We're going to add a card shortly. And yeah, let's let's actually add the card first of all, and let's add a few things onto that. So once again, we can just take the ace of hearts here, put it in, Let's position it here, make it a little bit bigger so that we can actually see it. And then on here we're going to take the example script and put it onto the Onto the ace of hearts itself. So onto the card. Also going to rename this to court because that's just easier. And we're also so what we could do, of course, we could take the main camera and put it in Europe or already shown this that you can basically put it into the, into the inspector itself and set it like this. However, in the script we've of course set the camera in a way that uses the start method. So that is also fine. And then let's make a, an empty GameObject here. This is the getting components game object. Of course, once again centering it just so that everyone is happy here. And then getting the components is script that we want on this one. And now what we want is we want to somehow access these test values here from this script. So this could be, you could think of it like this. Maybe there's a health script that we want to change or there's a manuscript we want to trace, you know, or something like that. We simply want this, these values. We want to change them. And we also want to maybe even change the position of the card or something similar like that. Now, how do we do this? Well, first of all, we have the gameObject cord here. And let's just make this as a serialized field, just so that we can see what's going on here. Instead of the start method, we're going to use the game objective dot Find method, which allows us, which we've already seen, which allows us to simply find a man that's a particular object inside of the scene with the name, in this case card. Oh, once again, it's important that the name is correctly written. And now what we can do, we have found this course because this is of course, just for clarification, this game object that we are going to find, this has an example script attached to it as a, as a component. So we can do now is we can basically, and we don't necessarily need this, but you can say example script example. So this is simply a new instance of the example script. So that works totally fine because this is a normal class that we can have a normal variable off. And we can basically initialize and set it. So we can assign this to cars dot get component. As you can see, this is already highlighted here. So we can say get component and then this is where some people are a little bit confused. We have this Get component with the basically angle brackets. And those of course, signify a A generic. And people are like, I don't quite know what I put in here. Well, you put in here exactly what you want. So from the components, so if I want the example script component, I put in example script and then of course need to change, finish this with the parentheses here to signify that this is a method call. And this will then return. If the, this game object actually has the component that we have specified here, then it will return this and simply save it inside of our variable. Now if I look back at it, again, we can see that of course, the example script is definitely a component of this card. However, there's also the sprite renderer and that's also, for example, the transport. But there's a lot of other things that are not components of this. Which for example, we could say, well, I mean, I want health right now. The only reason why this doesn't work is because of this. So if I had an health variable here and I said, Well, give me the component of health. We could do this. However, of course this is not going to work because there's no component health onsite on this, on this particular game object. So this is how we can basically say, okay, give me this component, gets me this component, give me this component. And that's a really useful tool. And one of the biggest things that we eat basically have to do in order to get specific components of game objects. And one thing that is very important to mention is that the, this Get Component coal is very, can be very, very intensive in terms of usage of like CPU and time. So this is a, this is a costly coal. This is why you should always, always, always use this one's in the store method and cache this. Basically like this, and not keep calling get component, that component, cone get component on the same component. But you should always cached this like this. And let's just say debug dot log example.bam test value. As you can see now I can access those because this example is simply a known variable of type example script. And this is a normal class. We can think of this as a completely normal class. And then we can just copy this over. I can also say another value. And then for example, the camera. The camera, when the camera, yeah, there you go. So this works totally fine. And if we start this, the one we're going to see Is a 142 and null. And now the question comes, Wait, why this is null? Because the camera is set here? Well, the reason why this is no, is because of the script execution order. And that is something we're going to take a look at when we look at some of the settings. But in general, the script execution order is that of course, because we have two scripts in year 1, one of those scripts has to run before the other, Right? So because we can't really run them in parallel, especially think about it like this. We have a 120 scripts. I mean, we can't run them in parallel to scripts would be possible in theory, but That's not still not happening. So there's a few things that we can do to basically ensure that the variables have been set. We can, instead of using the str method, we can use the wait method, because the wait method always gets called before the start method. And this simply then ensures that the camera variable has been set. So let's try this and see if this still null or if we've actually master node. Now the main camera is set and everyone is happy. So that's pretty cool. And going forward, what you can also think about is, well, actually, what I want is I want to, I want to change the position of this cart. Well, we can do this. We can say transport. So we're saving the transform and say card Transform, Transform. And then instead of simply so we could do this in two ways. We could say card dot transform. So we can do it like this. In the background. This transform does nothing else. Then call the get component method with transform. So this is basically interchangeable. When we do this. There you go. So this is interchangeable, exactly the same thing. And it does exactly the same. Yeah, it has exactly the same outcome basically. So what we can do then is, for example say chords transform dot position, just output the position. And then in-between here, Let's change the position to, let's say a new vector 3, which is something like, I don't know, like one, F to F and F. Yes. Right. So we're just going to change the position of this core transform that we have gotten with the Get component as well. So let's actually do it like this. So also possible, same as get component. Component is and let's see if that works. If the court actually changes its position. And as you can see, the card has changed its position, 2, 1, 2. And if we look at the output, you can also see that first the position was 03 and then the position was 12. So the component method is a central part of this component-based design that Unity has inherent in itself. And it is simply possible to, with this method, gets basically all the components of a particular game object, access its variables, and also, well change them if need be. Yeah, this is actually a fairly easy way to access different components from different scripts. Overall. Like I said, this is definitely a core component and every other component that we're learning about can be accessed basically like this. And the great thing is, because that's what we've already seen with the camera, for example. All of the things that we see. So all of the particular things that we might be able to change here, the size or for the card, the example script, the test value to another value that camera. Those also can all be modified by exactly another script after we've gotten the component from there. So get component, incredibly useful, incredibly important tool for us in our toolbox to basically work with Unity, right? But that was it for this lecture. Like always, I hope you found it useful. That was actually quite a big topic at this point once again. But overall, I think that it went very well. And however, like always, if there are any questions, feel free to ask and I'll be sure to respond. And yeah. 58. (Unity Basics) Prefabs & Spawning new Objects: All right, let's continue with the basic unity introduction here for the unity course. And in this lecture we're going to take a look at prefabs and how to instantiate them. So first of all, what are prefabs? We'll prefabs are basically GameObjects that are therefore a for replication, so to speak. So there's sort of a template, so to speak, from which we can create new objects that are very much like those. And let's just create a new scene. First of all, once again, so seen 15 called prefabs. And then let's also start this immediately. A new folder here, L 15 prefabs. And we only need one script. And we'll call this the click spawner. Because what we're gonna do is with this. Once we click the mouse button, we're going to swan in a new card. So that's going to be very interesting. So let's just say we have the clicks Warner here. Click spawner. Once again at position 0, 0, 0. Of course. Also making sure that the components is on there. And then let's create a new card here. And we'll put this at 000, 000 as well. And we'll actually make this only about twice the size. Actually, let's keep it at 11, one with the size. And then we can think about doing something with this later down the line. And what we can do now is we can basically say, well card, so this is now a card object. And how do we make a prefab out of this? Well, the easiest way is simply to take this object right? Once we've basically set everything, how it should be. So this is the default positioning of a card. Then we say, okay, let's just drag it here to prefabs. And now, as you can see, this turns blue. And now down here we have a prefab asset. So the idea being that now we have this sort of template and all of the different values that we have set here or inside of this prefab. Now we can also open this prefab and see it instead of this sort of template screened, sort of the prefab screen and can change it in here. So we can change a few things like flip the, flip the picture or we can move it around. Or we could also add components. For example, now we're not gonna do this. To go back, we can simply press the Back arrow there. And in this particular instance of this prefab, they are connected. And you can see this by basically the blue. Underline here and there's some things that are marked as like they're bold. And the idea is that once we change something, we can, for example, say in this, as you can see overwrites to card in scene, what this means is that you basically change, you can change something in here. So I don't know the rotation. I mean this rotation doesn't make sense. So this rotation, for example. And with a select key, we can immediately select the prefab inside of our projects. We can also open it immediately. And right now, what this does is it overrides the card. What does that mean? Well, if we look at this one, nothing changed. This basically overwrites. It says, Okay, we're taking these values instead of these values here. There's a few things that we can do. So with a prefab, as you can see, we can unpacking and packing it, simply detaches it from the prefab. We can select the acid. There's a few things that we can do with prefabs. And what the most important thing is basically that we can, now here we can enter it into, enter into it again, as you can see. But the most important thing for the prefab that we can do is we can create new objects, all of those. So let's just delete this inside of our actual scene. And the prefab here, the one that we will create new cards. And we will do this by changing the clicker spawner script here. And inside of it, we will have a private GameObject because we always create new game objects called the court prefab. This is going to be a serialized field, very important so that we can actually access this because there's no other way that we can accesses. We can't use the gameObject dot find in this case because, well, there's no card instead of R. And sort of seeing here. So we have to do this another way. And the way we are going to do this is we're going to set this manually. So we're gonna say get most button down 0. Hopefully you remember this was the left mouse button. And what we're going to do is we're going to create a new game object here. So new card is equal to instantiate. And I'm going to say card prefab with this dot-dot-dot transform. And what this does is if we hover over this, we should actually be able to see, as you can see, this takes a transform as a parent. So this new game object that we are going to create with the Instantiate method call is going to be immediately assigned the parent of clicks Bonner. And then we also, because we have the new card variable here, we can change a few things there immediately. Soon, new card dot transform.py mission. And what we're going to do is we're going to actually make this a random position. So we're going to say random dot range between somewhere between negative 10, Let's say e1 plus 10. And the y is also going to be somewhere between a negative 10 and 10. Actually, let's, let's turn this down to seven because I don't I'm not a 100 percent sure where the where the borders are. But we will see this shortly as well. And yeah, we can of course also change all sorts of other things. If the card, now, thinking back about the last lecture with the Get component, of course, we can also call get component on here. And if there are any particularly important components on this chord, we could of course, also set those. So if this would have a health script, for example, we could change things on the health script as you can see. So for example, we could change the health if that was on the card, and so on and so forth. So this is sort of a way to initialize some values of certain objects. Right? Now, it's very important is that this court prefab, of course, has to be set, and therefore we have to actually drag this in here. This is the one time that we actually have to drag something in there. If we're using prefabs and we are creating objects from them, then this has to be sort of a more or less manual thing. And let's see if this works. So if I click on the screen, then a new card appears. And if we look at this one year card clone, and we can see that it actually does appear as a child of this click spawner. So some cards, because seven is definitely a little bit too far outside. So this is probably more like five is probably the, so five would probably be best. So let's get back to the clicks Boehner and say, okay is anywhere from negative five to five. This also does make sense because the main camera, of course, the size is set to five. So that actually checks out in a lot of waste. So let's just click around a few times. And as you can see, we're now getting a cluster of cards, just randomly generated and there's more and more and more cards and we're just spawning them in like crazy. But it works, it works very well. And this is a way in which we can basically create new objects, have them spawn inside of our game. And then of course, if they have particular scripts that are run, then those can run without any issues, without us having to do anything particularly crazy there. So, yeah, that is basically the idea of prefabs. They are incredibly useful tool to have a template from which we can then create new game objects. So some examples of this might include something like a like even a text message. You could have prefects like that. You could have Prefabs for enemies. This is like one of the classic examples, right? Would have an enemy prefab and then an enemy spawner, for example, and then simply spoiling them in as you go. Now one thing that is to mention is that the Instantiate method is of course, very CPU intensive or very costly again as well. So there's something called a object pooling that you could do. So the beginning of the game, you could create like a 1000 objects, stick them somewhere in the game world where they don't do anything and then basically just set their positioning and maybe enable a few things on them. But overall, that is something that's not, we're not going to worry about right now. I just wanted to mention this, that the Instantiate method, like we've seen last time with the Get component method, shouldn't really be like crazily used. So you shouldn't create like a 100 thousand new GameObjects like every frame or something crazy like that. So be very wary, especially if you try to use for loops inside of the update method. That is something that might not work out like you wanted to. But yeah, that was basically for creating new game objects with prefabs. Like always, I hope you found it useful. And if there are any questions, feel free to ask and I'll be sure to respond. And yeah. 59. (Unity Basics) Textures and Sprites: All right, let's continue with the basic unity introduction here for the unity course. And in this lecture, we're going to take a look at the sprites and especially in the spectra here. So we've seen, we've also already added to the ace of hearts as a sprite. And I've said that we're going to look at this later down the line and now is the time. So for this, I've actually opened the L4 to get components scripts so that we can see the actual sprite inside of the scene view here visually. And if we make changes to this, then we can basically no. Okay, What is what is happening? Why it's happening and yes. So first of all, let's go through from top to bottom. The texture type of Sprite is the one that we're basically going to use exclusively inside of this course. And as you can see, the question here is what will this texture be used for? Exactly, it's going to be a sprite. So this is the one that we're going to be using. The others really don't interest us at the moment. At least not for this course. Then the sprite mode. So the sprite mode is very interesting. We have single, multiple and polygon. So single and multiple other ones that are interesting to us. Single simply means that this is a single texture. This is a single sprite. This only one thing and multiple, which is something we're going to look at later down the line is where we have multiple a particular pictures in one file so that we can basically put in one file. And then we can separate this via the Sprite Editor, which we're going to take a look at in the next lecture in way more detail, pixels per unit. So what does that mean? Well, as you can see, how many pixels in the sprite corresponds to one unit in the world. This is the reason why we more or less has to scale up this chord in order for it to really fit in. Because the card actually is, I believe that the image is 64 by 64 pixels. So what we can do is we could set it to 64. And if I apply, what you will see is that the card has now gotten very much bigger because now it's 64 pixels for one unit of space. So the smaller this number, the basically the bigger the actual image gets. But usually, it depends on how big the image is. Usually I think that this should be put, let's quickly look this year so that I can click everywhere. Usually the this number should be somewhere around how big the images, especially if it's a square, that is the best the mesh type, types of sprites much generates. I have to be honest, this is something that I'm not a 100 percent familiar with. There is in my mind right now. Not really that much difference there. Extrude edges, how much empty space leaves us right around it, right? So this really is only important. See, in a generated mesh right now for us, not that important. The pivot, the pivot will just change it to, for example, the top right and apply this. And as you can see, all of a sudden this moves down. Because even though the card itself, if we unlock this again, the current itself is still at the same position right now. The pivot of this particular image, the sprite is not centered anymore, can be, can be really useful. I usually leave it at the center and change the game object itself. That's better. We'll generating physics, as you can see, is simply generates a default physics shape so that we can have, this can be on or off. I mean, depends on whether or not you need physics or not. Those are some advanced settings here. And alpha, of course, makes sure that if you have a PNG, that the Alpha is then basically taken into account. We can also look, let's lock this again. There we go. And we can also ignore the, some of the things. So the alpha can be non-transparent, for example. And, and now it's non-transparent and we can just say, well, whatever. So then the Alpha in this case is not transparent. But where you want this to be transparent. And there's a few other things that we can do. Ignore the PNG file Gamma, we can enable read and write pixel data so that we can actually change with this particular image. And sprite could be useful. Although this is something that where you have to be careful because then you can basically also your sprites for forever. And you can also in theory, generate a mindmap here, which might be something that you want. Yeah, rap mode and filter mode. So the mode is basically when you have a, let's do this. If we have a, add this as a texture, then the red repeat mode simply repeats this image if we put it on somewhere. So if we were to put it on a surface and it's not big enough, then it would simply repeat. Plan would make it that it's ones I don't know why it always extends the advanced ones I apply. So that's kind of a kind of an interesting thing. Mirror per axis usually leave it at clamp that sum enough, that's good enough. And then the point that is the interesting things for the filter mode, because we have seen that the bi-linear is the one that we started with. An, if I apply, what we're going to see is that all of a sudden this gets very, very blurry. And the reason is because this is pixel art. And bi-linear is basically more or less, is smooths out edges. And we'll, in this case, we don't want edges smoothed out. Trilinear should make it not necessarily worse, but basically the same endpoint simply means there's no filter on the hashtag, no filter. And this will make your pixel art. You're beautiful. Down here are some interesting, basically settings that you can use for wins once this is published. So max size simply refers to the max size. So if I do 32, for example, as you can see, all of a sudden, oh my lambda that is not, I can't even see what's going on. If I put it at 16 thousand, it is sharp as a crisp. But I think that even 1022 or 128, even that is more than enough. 64 still enough because that's still enough to have everything in there over something like yeah, so then in the middle is probably going to be enough. We also have a resize algorithm. You can change the format of that. This is changed and you can also change the compression. This basically is these settings here can be changed. For example, maybe if you have a mobile game, what you would want is, well, actually let's make a low-quality and make a few less bits, for example. So you can change, oh, let's do this one 32-bit. Or we can say, well, alpha eight, so that's, and now everything's gone. Or just keep it at automatic. That also works. There is a few things that we can change your, because maybe in certain locations where we want to publish this game, we actually want the size to be less. So on a PC, there's no reason not to have the biggest size for the files, because whether or not a game is three gigabytes or eight gigabytes. It doesn't matter for on the PC, usually on a phone. That is a huge difference, right? So the difference between a game on a phone that has our, let's say like 250 megabytes versus like four gigabytes is huge because while phones have in recent times gotten larger in terms of memory space, still four gigabytes for, let's say a casual game is way too much. So this is basically what, this is four. So this would be the default. And then here you can override something for particular, for basically particular BuildSettings. But once again, this is something that is as well a little bit more advanced. I wouldn't worry about this too much. Just making sure that if your picture is blurry, if your sweat it's blurry that it might either be the max size that you've put in. The compression might also have to do with it. And also the filter mode could be the cause of the issue, right? But that was it for the quick look at the texture here at this mode. Next thing we're going to take a look at is the Sprite Editor of this as basically a new window. And with that, we will also see the sprite mode of multiple. I hope you found this lecture useful like always. If there are any questions, feel free to ask and I'll be sure to respond. And yeah. 60. (Unity Basics) Sprite Editor: All right, let's continue with the basic unity introduction here for the unity course. And in this lecture we're going to take a look at the Sprite Editor. And with that, we're also going to import the multiple cards basically. So multiple sprites at the same time. We had the ace of hearts here as a singular texture or sprite for a long time now. And now we're going to take a look at it, the tile map itself. So let's just, I'm just going to copy this over here. So we'll just drag it in there. And as you can see, this is Cards large tile map. Currently, if I were to just place it here, it is one file with multiple cards, as you can see. And obviously this is not what we want if we were to import something, we want more than one card because this is now a single mode. So let's put this in multiple modes, change the pixels per unit to 64. And let's hope that first of all apply this, also make this point very important, the filter mode so that it looks good. And then let's get into the Sprite Editor. So if we open this by editor, we can see if I just get it from the other screen here, that we can basically do some things in here. We can zoom in and zoom out with the mouse button. Right-click, holding right-click. It makes us move this. And if we press left-click, then we have the sort of selection. However, if we stopped the selection, so we stopped pressing the left mouse button. And as you can see, it creates sort of a sprite here. And we can also change this around. We can make it bigger or smaller. And this basically represents a sprite on this particular image. Now, there's a few things that are really nice. So up here, we can look at few things. Customer like, we're not going to really look at this. So this is a having a custom outline. We want the Sprite Editor in this case. And the Sprite Editor can splice, which is really nice. So we can either do automatic. What this does. If I say slice, as you can see, it has created these different spreads here automatically. So that's really nice that, that works. Let's revert. So we can revert and now there's no sprites present anymore. We can also have different types. So we can say by, by size. And we can, because we know that these cards are 64 by 64, we'd say, okay, slice them 64 by 64. And then as you can see, if I don't move this, every card now is also in a sprite, but it is a little bit bigger. It has a little bit of room at the sides so that we could do this. Or if we revert once again, we can also do this by count. So if we know that, for example, this is, this would be 10, 11, 12, 13, 14. So we know that there's 14 rows and four columns. And we can slice, that's actually the wrong way around, of course, 144. There you go. Now, vowel. Now it works. And this would also work. So there's a few ways that we can do this. Of course, we can also change the pivot. There's a few things that we can do here. There's some padding, some offset. However, I think that the size in this case makes the most sense here. And then we have basically all, if I get down here or 56 cards in this case, because we also have two different ways of either this is a, an empty cart or we can also have this as the background to hover. This is, I think meant us the background. So yeah, that's pretty cool. So let's just apply. Once again, just to mention this, those are the cards from the kidney assets. And once we have applied this, we can see inside of our project, well, this is still just one title pack here, but we see this little arrow. And if we expand this, you can see each of these individual ones is one chord. So if for example, we also want to take out the ace of hearts, we could do it by doing this. And if we sizes up to four times four, then as you can see, it is literally exactly the same size. Because we'll, instead of this being a singular card, now it is part of this pack. And the great thing about this is, and we're going to look at this in the next lecture in a little bit more detail, the sprite renderer. What we can now do is we can basically say I want to change this and I want to change the sprite bam, and then the card has changed. And we're gonna, like I said, we're going to look at this in the next lecture in a little bit more detail what the sprite render has to offer. But this was basically it for a short little overview of the Sprite Editor. Now, there's a few more things of course that this can do. However, for now, this will definitely be way more than enough for us. And this incredibly useful tool, because now we don't have to necessarily have each of our sprites independently or in separate files, but we can have all of them in one file and cut them out either manually, by, automatically we can do it by count or even by sort of how many rows and how many columns. Right? So that was it for this lecture. I hope you found it useful like always. If there are any questions, feel free to ask and I'll be sure to respond. And yeah. 61. (Unity Basics) The Sprite Renderer: All right, let's continue with the basic unity introduction here for the unity course. And in this lecture we're going to take a look at it, the sprite renderer. So this is another component. And for that we're going to first of all create a new scene once more. So this is 18 sprite renderer. And then also create a new folder in here. Let sprite renderer. And the script we're going to create inside of here is going to be called the sprite renderer look. Of course the name here is more or less, chooses. If you want different name, you can, of course. And we're going to take a new card in here. We're going to take a card from this, our new tile map. Basically, once you can make it four by four, Let's actually place it in the middle of the screen at this point. And let's rename this to card because that's like a way better name and added the sprite renderer look to it. And yeah, let's see what we can see in this particular thing. So first of all, the sprite renderer is a simple component. So we can basically saves private sprite sprite renderer and just call this the sprite renderer. Sprite renderer. There you go. And we can get this by doing in the start method spread r1, r2 equals and then this dot get component. So we can also get components from the gameObject we are currently in. So where this script is attached to. And then we'll get to the sprite renderer. Like I've said, this is a very smart idea to do this. And we should actually basically always do this. Now let's think about something else. We're also going to have a private sprite array called sprites. And we will make this a 0 field of course, so that we can access this via the inspector. And if we take a look at this right now, and we can see is that we have a list. See, this is empty. But what we can do is we can just take the sprite tile map and drag it in here. Now, as you can see, this didn't work because we delete this array element. What we have to do is we actually have two. Luckily, we don't have to take everything one by one. We can look this up here. So at the top right of the inspector, we can look at this. Then we can basically select everything. So if we select one of the things, then hold, shift and select the top one and everything in-between gets selected. And if we then move this here, and as you can see, it now fills up with all of our cards. So that's really nice and really useful. And now, well now all of a sudden what we have is we have a list of sprites that we can access as an array. What could we do with this? Well, what we could for example, do is we can say, well, at start, I want this sprite renderer and the sprite that is inside of it. So this is the sprite that, that is being displayed. So the sprite render, I want this to be one of the cart sprites. So for example, I could say, well, I want this to be. The courts, but at index 4, or I could say, well, I actually want this to be a random run, random.randrange starting from 0 because of course, 0 is the first index all the way up to court spreads dot length. So, and then if you look at this, the max is exclusive. This is why we don't need to do length minus 1 because length is not taken but only length minus one is the range. So the minimum is inclusive and the maximum is exclusive, just so that, you know, right now, if we start this, we should see that this card actually changes its sprite onStart. Let's see if that actually works. And there you go. Now it is the six of clubs, I guess. And let's do it again. Now it's the five of clubs. I am not sure, actually. Three of hearts they go. And then one more time, just for the hell of argument, I guess that would be the seven of diamonds, right? And now, now this is really cool. We can do two more things. So what we're gonna do is we're gonna take the input here and get keydown, keycode dot space. So hit the space bar. What we're going to do is the sprite renderer dot sprite is basically exactly this. So we can actually copy this. Once again, this would be now, for example, something that we would put into a different, well, just a different method here. So this would be change to random sprite. We don't necessarily have to do this, especially because this is just a short little example. But because we have basically a quote this twice, there's a good point of doing this. Because now if you look at this now we're going to be like, okay, what happens if I press the Spacebar oh, changed to random sprite. Okay, That makes sense. And this is way more readable than if I have this in here. Because we definitely have to split this up. We can okay, random, okay, So the sum of the random, okay, I, I take a random sprite, but this one, I just read the name of the actual method and it's like, okay, that's, that makes sense. So get keydown, keycode dot return. So this would be the return key. We can also just change another one and we can, we can, we don't have to necessarily do return. Let's do, let's actually do. Let's do the C sharp, C key. Because what I wanna do here is I want the sprite renderer, sprite renderer dot color to change. And this can be done by using random dot color S, H, v. This simply returns a random color that you go at, which is pretty cool. So we see we can actually change the color of it. And with space, we can change it to a different card. And if I look into this sprite renderer again, once again, all of those things here. So all of those fields are basically available via the script. Despite of course, as well as the color here. Flipping this x and y, we can do this as well. The Draw mode, mask interaction, the pivot despite sort point rather. So the orange layer is something that's very important. So if we have this cardigan, so copy it by pressing Control C, Control V to paste it in. So now we have a new card here. And the ordering layer simply determines where this particular chord is. So if we just change this up for just the sake of argument here. So four of hearts, now, ace of hearts is now layer is 0. This one is at later 34. Therefore it is higher up, so it is above it. And if I reduce it, then as you can see, this changes as well. So that's something to consider and also to keep in mind. Very important. But enough said, right now, let's actually try this out here and see if this works. So we have our card here. And now this did choose a random card and I do believe in, actually did choose this one. We can actually try this by pressing the spacebar. I think that was a very lucky draw. I guess. So. Yeah, we can choose, we can just put the space bar and as you can see, it chooses a random card in there, which is really, really cool. And if I press C, then it changes its color randomly as well. Oh, that was very black. And then as you can see, there you go. So changes the color randomly as well. And if I press both of them at the same time that both of them change or I can just have a rave party. Let's go. I like it, That's pretty cool. So that is a very cool thing. The sprite renderer, mainly, I think that in my experience, the sprite that definitely changes quite a bit. So that that is something that is very important. The idea of changing the sprite and saving basically all of those sprites inside of a instead of an array. That also makes a lot of sense. The reason why I've chosen area here is because of course, once we set at once, we don't really need to change it. And the number of spreads doesn't change. Or rather, even if it changes, it doesn't change during the game. So while the game is running, we don't need to change this. We don't have to have a dynamic list here. Basically. This is why a is an array, works fine. You can of course also make a list. This doesn't matter. Either. One of those would be fine, right? But that would be it for this lecture looking at the sprite renderer. Of course, there's a few more things on this, but as usual, right now, this is a very good like starting off point for the sprite renderer can be really useful to change the sprite and also the color. That's kinda nice to look at that, right? Okay, So that was it for this lecture. Like always, I hope you found it useful. And if there are questions, always feel free to ask, I'll be sure to respond. And yeah. 62. (Unity Basics) 2D Collider: All right, let's continue with the basic unity introduction here for the unity course. And in this lecture we're going to take a look at box colliders or collaborative in general. And the way we're going to do this is first of all, of course, creating a new scene here. L 19 colliders called litres. They go, Let's open this up and let's also create a new folder here, et al. 19 colliders. And then instead of actually let's do create the script. And we're going to call this the collisions script. It's actually close out of this one. Let's open this up. The ego. Before we do anything inside of here, we're actually going to create sort of a nice scene here. Once again, for the resources I have a particular kenny assets once again. And we're actually going to create a little bit of a sort of 2D way of doing things. So let's just pull those sprites over here. So this would be the alien green front, the box crate. We have dirt left, MIT and right, and we have the lava here. Now in theory, those should be somewhere around probably 28. So let's first of all actually just mark all of those, select all of them, make all of them point. And then let's try 128 for the pixels per unit for right now. And let's just make a little platform here. Just for the sake of argument. We're not going to use this immediately, but we will use this shortly. So negative four and then the left negative four. And then we simply need to move this over by probably one that is exactly right, minus one. And then this one is plus one and a negative four. And then we have a little platform here, which is pretty nice. We can put the alien in here, which actually stands very tall. So negative 2.5 probably, yep. Now it's actually put on this platform perfectly. And then we also have the crate year, which is just going to float in the air at 2.5, no lepton 25, 2.5 and negative three. And then the lava is going to be here just so that we have it. We're actually going to make this a little bit bigger as well. So something like that. Let's do it. 2.52.2.5, 725. Oh man, that's way too big. 2.52.5 at negative two and negative three. Let's put it here. Yes, that's pretty good. So that's our scene right now. And what are we doing? What, what is, what is going on? Well, what we will do is the following. We will actually. Give the, this one. So we're first of all going to rename these things player. We're also going to make a empty one, which is going to be the ground in which we will just select those and drag them over here so that the ground is now no, no, no, I didn't center it. That's not that's not possible. I have to center this. Now. Now, now everything's fine. Where the ground is just in here. The lava is fine and this is just going to be a box. Okay, now what can we do? Well, the player is now going to actually get the the movement scripts that we have done a long, long time ago so that we can actually move him. And let's just see, this should work. So if I press WASD, I can actually move the player around. Now of course, I can just move them through these things because no, there's nothing there's nothing stopping me from doing so and also nothing happens. So that's kind of interesting. But what can we do to basically will enable us? Well, we have something that's actually before we go into the script, we have something, we have another component that we can use. And that is in sight of the, if Sophie finally select the player. And if we say add components, then what we have is we have a collider. Now this collider is instead of Physics 2D, and we're going to use the box collider in this case, we could also use capsule collider. That would probably work, but those are just basically different. The different shapes, the box collider is going to be fine. Now in our case, as you can see, the box collider actually gets put on, like on top of the entire image here, which is a little bit too big. So we would actually want the size to be a little bit different. So if I change this, then you can see that this green box around them changes. Let's do something like 1.25. And then the offset basically changes where this is located. And if we do something like negative point for maybe let's do one. Sorry, 35, 37, five, something like that. Just for the sake of argument right now. That is an okay box around this player character. And now it has a box collider. So that's pretty cool. Now. Does that get us anywhere? I mean, right now, not really because nothing else has a collider. So what we're going to do is we're going to select all of those dirt paths, your order platforms. And we're also going to add a box collider to those. And if I now expand those, then we can see that it has a few colliders in here. This is going to be fine. Because right now we only want to see from basically from how it looks if I were to move into it. So let's actually move them up a little bit. So negative two, so that he floats above the ground. Because right now our movement is actually not really a movement for 2D. It's rather a movement for like a top-down thing, but we're going to change that within time. Let's also just, just so that we have an added the box collider to both the lava and our box. And we'll tweak the settings there and a little bit. So now I can move around. And now what happens if I have a collider and the ground has a collider, what happens if I now go down? Let's see what happens. Nothing happens. And the question is, why does nothing happened? Because this has a collider and this has a collider and I thought that this would be sort of a collision. Yes, but we need one more thing because in order for the physics to work. And the thing that we need is under Physics 2D down here, and it's called the rigid body 2D. Now this has, as you can see, a lot of things also a lot of information. Let's just decrease the information that we see. And as you can see, there's a lot of things in here. And the first thing that we need to do, we're going to talk about this rigid body 2D in the next lecture in way more detail. Right now, the only thing that we need to do is basically put the gravity scale to 0. That is all that we need to do. And then basically just put this in and not look at it again. However, we do need this, otherwise, none of those things will work. But now if I try to move down, I get stuck. I get stuck on all of those things. Because now those collide. Now, what is really funny. What I can do is I can turn my guy around as you can see. And now everything is really weird. Let us has something to do with the rigid body as well. Basically, we can freeze rotation. We're going to worry about this, however, like I said in the next lecture. So the box collider, what can we do now? Why is this interesting? What is so, what can we do about it in script, right? So now we basically can collide with all of these things. But what does that really give us? What does that bring us? Well, you could imagine that if I go into the lava, that's going to hurt. And maybe if I touch the box, I just want to output in the console, Hey, you touched the box. Let's just say that those are the two things that I want. How can I do this? Well, there are methods for this, and those methods will be looked at in this collision script. So the collision script, we can use a method called on collision enter 2D. And as you can see, there are a few other ones on collision exit on collision stay, those should be more or less self-explanatory on collision enter simply means that this is called once. As you can see, once a collider 2D or a rigid body 2D begin to touch. And exit simply means when they stop touching and stay is called like each frame that they are touching. This gives you a collision 2D. And with this collision 2D, we actually have a lot of things that we can call here. As you can see, we can call collider, contact, contact counts or how many contexts there are. We can get the contact points. We can get the rigid body, the transform. We can get a lot of things. Right now what we want is the collider. And we want the name of the collider. And we will check whether or not this is a box. So we want to know whether or not this has collided with the box. And. Is the case. Then we will simply log out, hey, hue, touch, you touch the box. And that's all there is to it. So this is a way of doing the collision in 2D of course. So let's see if that actually has worked right in before we can see whether or not this works. We of course also have to add the collisions script here to our, to our player. That is very important. Don't forget that. And then let's see what happens. So if I touch the ground, nothing happens. If I touch the lava, nothing happens. However, if I touch the box, as you can see, hey, you touched a box. And each time I do this again, we increase this counter. However, if I keep doing it, it doesn't work because we have well called The, we've implemented the on collision enter 2D method and not to the stamen. And there's some other thing. So inside of the box collider, if we look at this. So if we just take a look at the larva for example, there's a few things that we can use. So edit collider simply, we can basically edit the collider in a little bit more detail. We don't need to do this at this moment. The physics material doesn't interest us at the moment. We can however, use this trigger and this is trigger is a very, very interesting thing because this is triggered simply physically removes the way that we can touch this. So I'm just going to show you this. So while the normal collider I collide with this, and now if this is a trigger, then as soon as I go into it, I don't collide with it because it's basically just a well, it's just a trigger. It's a particular zone in which if I enter, I can still still, something can happen. But I don't collide with it. And this would also be a, another particular method here. And this is on Trigger Stay to D for example. So there is, once again, of course, enter this, stay on this, the exit for this once again. Also very important. Make sure that you've used the 2D method if you're working with 2D, otherwise, it also won't work. And in this one we can basically almost do exactly the same. Now as you can see, there's a little bit of a weird thing. So this is still called collision or although you get a collider, I don't know why the why they still haven't fixed the auto naming of this, but they go. And then let's say collider dot name equals this would be the lava. And if that's the case, then for example, you can say you are now getting damaged. Damaged, they go right. And then inside of here, of course, what you could do is if you have a reference to health script, for example, you could say, hey, now you're losing health and then at some point you might die if you were in the lab or you immediately die when you're in the lava or something like that. But right now, the only thing that we want is while the player stays inside of the lava, we basically want you're getting damaged outputs. So let's see if that works. And of course it does. That is very good. Now, what is interesting is that why does it continue? And if I move out again, it continues. This is because of one of the settings instead of a rigid body, like I said, next lecture, we're going to fix this issue and a few other things. I'm also getting to take a look at the rigid body itself. But for now. And this is actually all that I wanted to show you for the colliders themselves. Overall, the colliders are an incredibly useful tool and so easy to really implement and work with. Same with basically the, the triggers here, which are an incredible tool to basically have, you know, different things happen at certain times without even having to be something to be seen. So of course, this trigger, we could also just don't have a sprite renderer on this and then this would still work. So there's a bunch of stuff that we can do with this, which is really nice. And yeah, that would be it for the colliders. Like always, I hope you found this useful. And of course I would really appreciate a review from you. Otherwise, if there are any questions like always feel free to ask and I'll be sure to respond. And yeah. 63. (Unity Basics) Rigidbody2D Basics: All right, let's continue with the basic unity introduction here for the unity course. And this lecture we're going to take a quick look at the rigid body 2D. So this is sort of a part of the physics system of unity. And we've seen this before. I said that we're going to last lecture that we have basically just ignored this and said, well, we need this for the colliding to work. But now we're going to take a look at it in a little bit more detail. So first things. First, the first thing we should do is we should talk about the constraints. The constraints should be fairly obvious. Freezing the rotation simply means that this particular game object, in our case, the player cannot rotate in the z direction. Now we can still rotate them manually, but the physics system can't rotate it. And we actually want to do this. Because what we've seen previously is that when the player, I'm actually collided with the box, then the player begin to rotate. And that is definitely not something that we want. Now, there are some different things that we can use here. So the body type is the first thing. And this is between didn't, dynamic, kinematic and static. And the main differences here is basically static simply means that it is not changing. Kinematic is moving and then dynamic is moving with a little more dynam, dynamism, see, I guess some more dynamics. I guess the mass is used, calculate the force later down the line because we can also apply force to a rigid body. And the gravity scale simply means well, gravity scale, but what you would expect, so a, if you have a gravity scale of 1 and mass, then you fall down when you start. So for example, if I were to do this and I don't move, as you can see, all of a sudden the player fell down. So if I move the player up, as you can see, the player falls down now and I can try to move up, but this doesn't really work because while I am changing my position, the gravity is actually pulling me down again so I can move left to right. That works fine. Down. Moving down makes no sense. And then moving up also doesn't really make sense because while I'm training my position, the physics system is sort of fighting against it. And this is basically also where the part where you could think about a jumping system. So this is sort of, of course a platform and now the left and right movement works totally fine. And now implementing a jumping might be something that would be possible because if you have a gravity scale, then I mean, this is almost a jump, but it's not quite a drum because I have to hold down the W key to keep moving upward basically. So there's probably a way to do this. But anyway, the rigid body, we had one issue where while we were inside of this and stop moving, all of a sudden, we were now no longer getting damaged. This is because of the sleeping mode. So the idea is that we start awake. But if we stop moving, then the physics system for the player just start sleeping. Basically. If we put this to never sleep, then what we will find is that once we go inside of here and we stay in here, then it will continue to basically damage us. Of course exactly what we wanted in this case. We don't want this to go to sleep in that moment, right? Some of those things like the mass, the linear, linear drag and the angular drag, or simply exactly those things in terms of physics. And in terms of physics components or, or physics values. They are. So the mass especially is of course used to calculate the force. So if I were to put force on this object, depending on the mass, it would change. So that is simply a very normal thing from physics itself. Basically, we have the interpellate is, as you can see, is the per frame update mode for the body. We can either interpolate or extrapolate or you can choose none. Usually I would say none is what you want. Interpolation simply means that the steps in between are calculated. Overall. I think that usually for most things that we're going to do inside of here, it actually doesn't matter all that much. Same with the collision detection. So discrete simply means that it is in discrete steps, so that it is in discrete steps. Continuous means that it is continuous, right? So let's take a quick look at the, basically the rigid body inside of scripts. So if we go to the, to our script which we had in here, the collisions than the rigid body can be accessed by either doing no, actually, it can only be accessed by doing good component and then Rigid, Rigid Body 2D. So we can save this inside of a Rigid Body 2D. This would be rigid body 2D equals list.rev get component. And then we can think about what we can do here. So for example, rigid body, 2D dot. And then as you can see, there's a bunch of stuff that we can do. So first of all, of course, we can and change all of the components that we've seen in the component inside of the inspector. We can of course, also change some other things and do some other really cool methods. Call some methods, for example, at force. So we could, for example, add force in a particular direction. So vector dot, for example, or let's say, Sure, let's do vector dot up for the moment. This will then add a force in this direction. So in y, one direction. If we were to say, for example, set the gravity scale to 0 again. Let's see what would happen now. Is you can see it is moving up very, very slowly. So this is the force up now. Now I can still move it about and I can still change it. The force still remains. Because if we look in the info here, you can actually see that the velocity is 0.02. And exactly So the, so the velocity is point 0 2. So basically point 0, 2. I think a second would be the velocity in that case. So if I then scale this up to be something like times 20, so that now I'm moving 20 times faster. Should be 0.4, I guess. And now are moving up quite a bit faster. Yep, point for that's great. And then as you can see now moving up quite fast, null of course, like I said, I can move down, no issue. But in this case, the force that was added there is, yeah, It stays basically. And this is pretty cool. We can of course also add torque. In theory, we can. What else is there? We can calculate the distance between this and a collider. As you can see, there's quite a bit of things that we can do. We can move position. So this moves the rigid body to a particular position. We can we can look at overlapping. So there's a lot of things as you can see that we can do. We can also call the wakeup so that it disables the sleeping state. But the ad force really is the very interesting thing. We can also, I believe, immediately set its velocity to something. So as you can see, that actually says this. So if I say velocity equals, I guess like I said, that was a 2D vector. It's a secret statement. Yes, this is a 2D vector, so this would be a new vector, 2 D, for example 0 and then 0.15. So instead of adding a force, we now set the velocity directly. Let's do this. So let's see. And now as you can see, the velocity now is 0.15. So those are all of the things that are in the info here, very important as well. But the reason why we wouldn't necessarily want to set the velocity on its own is because of course, the mass. If we add a force, the mass determines what the velocity is in the end. So sometimes you want to set the velocity, sometimes it's better to add the force really depends on where you wanna go with this, how much of the physics systems you want to use? Personally, I would say that it probably makes the most sense to not have too much of the physics system, but it really depends on what type of game you're trying to make. And one last thing that I just wanted to show, for example, is if we have, for example, some linear drag. I mean 50 is probably a little bit too much. Let's just put it at one for now. And I put a force onto it. Then what you will see is that the velocity decreases and all of a sudden at some point it is 0. Now it's okay. Now it's very slow, very slow, very slow. And then at some point it is so small that they're basically no longer moving. And this becomes 0. I mean, this is basically 0 already. Because the linear drag simply means that what we are, we have some drag right before we were basically just a thing floating in space without any resistance. And now we would put air resistance to it. So this is, as you can see, what it says. And no dampening 0 means no dampening. So this is something that you can control with, for example, the linear drag. And the same with Angular Drag simply for a rotation in that case, right? That would be it though for the rigid body overall, there's a few more cool things, of course it can do with it. But I think that as a general look at it, it's, it's pretty cool. And maybe The overall, in terms of an idea or maybe you have now an idea of how you might be able to basically add a sort of a jumping mechanic in-game. This would be something that you could, for example, try out. It's not necessarily needed, but it would be a good idea. Maybe you can think of something. But anyway, overall, this would be it for the rigid body 2D, sort of a short overview of it. Like always, I hope you found it useful. And if there are any questions remaining, then feel free to ask and I'll be sure to respond. And yeah. 64. (Unity Basics) Basic Unity UI Text: All right, let's continue with the basic unity introduction for the unity course. And in this lecture, we're going to take a quick look at a very, very basic UI text. And the reason why I want to show you the basic UI text is that you have a rough estimate of UI, at least how to display a certain texts. And then later down the line in another section, we're going to go take a deep dive into the UI. Look at every single component that there is, how to use them and things like that. I think that a basic UI text can already work wonders. And for that, we're going to create a new scene. Once again, l 21. If I don't if I'm not wrong and I don't think I am. Let's do simple UI text. Texts, the ego. And let's immediately open this. And then instead of the scripts folder, a new folder, L21, UI text, with a very easy C-sharp script called UI text. Who would have guessed, there's immediately start this. And let's create a new, basically text inside of our game. How can we do this? Well, in sort of a hierarchy, right-clicking. And then going to UI and then text. We're going to use the normal texts right now. Like I said, all of the other things as well as what this text Mesh pro means. I'm going to explain in future lectures right now. We're just going to deal with the normal text and how we can actually get this to be displayed. So now we have a new text and as you can see, some more things have been generated. One, the event system, we will need this, do not delete this, otherwise, some things might not work. And the Canvas and Canvas is basically, you could imagine a canvas basically as a, as a canvas that you would paint on. And in our case, we don't paint on this, but our UI is basically stamped on this canvas. Now if we zoom out a little bit, you will see that first of all, the text is giant and on the canvas is also very, very big. And we can change this by basically going here onto Canvas and then changing the render mode to screen space camera. And then taking the main camera and putting it into this render camera. And all of a sudden, the canvas gets put onto the size of the camera. And our text is at the bottom here. And we can resize it with the rect tool. This is the easiest way to do this. We can basically resize this and sort of put it animal-like up here, for example. And then make the font size bigger on the text itself. That is done here. And then all of a sudden, Let's do something like this. Center it and they, we go, now we have a new text. Overall. This is the only thing that we need to do in the Canvas itself. As you can see, there's quite a bunch more. Let's not worry about this for now. Let's actually only worry about the text itself. Where we can of course change the fund. In theory, we can change the font size, the style, the alignment. So all things that you can also do is for example, in Word. And of course, the color can also be changed to, let's make this sort of a white color. And if I go to the game and you can see that the new text appears there without issue. I can change the text here in this, in this text field. So for example to 100. And what I will do now is I will add the UI text as a component to the two exactly this text game object. And inside of it, we're going to see how I could change the text via script. So for me to change the script, change the actual UI via script, I will be using Unity engine WI. So this is a namespace that we need to be using. And then let's just, for example, make a private text variable called test text. And we will make this a serious field just so that we can see what's going on. And this is the UI, as you can see, the UI element, the Unity engine, wi dot text. And this is exactly this component here. In theory, this component here is this text. And what we can do is we can say if we wanted to set the texts, they are test, test.txt. So text is the string variable that actually gets displayed. And we can set this by doing, for example, if we want this to set to 300, if we do this, then it's going to say, that doesn't work because we actually have to say to string. Or we can of course say something like this 300 vehicle. That is, of course even easier. So we can set this to any string that we wanted to. And of course, there are also some other things that we can do so we can change the aligned the color. We can trace the font itself, can also change the font size. So basically, all of the things that we've seen inside of the actual component, we can change if your script as well. But right now the only thing that I actually want to do is basically to change this. To change the one hundred, two hundred, three hundred once I start. And we actually have to set this here. So as you can see, test texts, none right now. So what we can either do is just put in itself or inside of the script. Before we start, we can say it has texts as equal to this dot get component text. So making use of the debt component method once more to basically get the text in the beginning. And if we start this, you can see it turns to 300. Isn't that great? Right? And this is a very, very basic way of implementing a text and how we can change this. Once again, we can simply use the Get component method in order to basically access the text and then all of the variables associated with it. We're not going to look at too many of those things. Like I said, this is something that I just wanted to quickly mention. Quickly show you so that you can make very, very basic just UI text and nothing else really. Just so that we have this in our toolbox to look into, well, making our first game basically, right? But that was already it for this lecture. I hope you found useful like always, if there are any questions always have to ask and I'll be sure to respond. And yeah. 65. (Unity Basics) Basic Unity Debugging Tools: Or let's continue with the basic unity introduction here for the unity course. And in this lecture we're going to take a quick look at some debugging tools that you have inside of Unity. And let's just create a new scene, L22 debugging. Now, these debugging tools would be tools that use basically the Debug class. So this is a another folder, L22 debugging. And then a script here. Cool it, the debugging example. Let's open this and let's also make an empty game object called debugging. Centering it, of course, they go zeros 0000 and adding the debugging example script to it. And then let's see what we can see. So we're going to just output something. When I press here, we're going to use the key code dot d. So if I press D, then we will debug something. I think that that makes sense. And the first thing that we already know is of course, the debug dot log. This is something that we've already seen. You already know this one, right? This is should be self-explanatory, simply locks a message to the console. There is also the debug warning. Now we've seen a few warnings. So this could be, for example, a morning you write. And this is something we've seen a few times before with, for example, variables that had been assigned but not really cold anywhere else. But I don't believe that we've called or did a warning ourselves. And there's also look, era. This is the one thing that it always suggests that sometimes gets suggested before the log. I'm not sure why this has changed in recent, let's say unity versions, but whatever the case, those three, Let's do say here. This is an arrow. Of course. Arrow, there you go. And let's just see how this looks if we start this. So first of all, well, of course I need to press the button. That's why nothing happened. That that would of course explain this. D. And then as you can see, you already knew this one. I'm warning you, and this is an Arab. There's also, of course, filtering over the console. I've already explained this. And those three things are basically something that we can do and we can continue to press this. And as you can see, the number goes up. And this is really useful because of course you can, sort of, depending on what you want to express in your code, you can either pull out a warning or an error. And this is really nice for debugging purposes. However, what I do want to say is that all of the debugging tools are very expensive, so they should all be taken out when the real game is released or either commented out or just making sure that they're not in there anymore. I'm not sure actually, if they are cold during the game or if the debug is something that is only done instead of the editor, I'm not a 100 percent sure. But anyway, so. There's something else that we can do and that is a draw line. What is this? Well, this dot transform dot position. So we start at this position and we say, for example, we go from here from our position to the right. So vector three times five. And then we can also say, well, we want this to be colored red. And ten F means it stays for ten seconds. So this is pretty cool because what we can do is we can just draw a line. And while the, you might say, well, why would I want to draw a line? Let's see how this looks. It doesn't look like anything because the gizmos are not turned on. Let's turn on the gizmos and all of a sudden we see this red line. It stays there for 10 seconds and then goes away. As you can see, there you go. Why is this so cool? Why can we use this? Well, it's actually really useful because sometimes maybe what you want is you want to know what's going on with something. Maybe you want to know sort of whether something is moving towards or something like that. And then drawing a line with the debug tool can be really useful. Now I can draw a lot of lines of course, and they will all expire at some time. But yeah, so the draw line, incredibly useful could be. I mean, I've, I think it's really useful. That's why I wanted to show it. It is really cool. There's also the lock exception. If I can get it, lock exception, there you go. So in this we can for example, say system, a new System.out exception. And then this say, yeah, it's an exception. So this is just logging an exception basically. And then last but not least, what I also want to show you is the debug dot, dot. And this simply assert a particular bool conditions. So if I put in a true here, then nothing gets output. And we will simply ignore this. If I put in a false, we will see that assertion will be failed and we will have a reference with this line. So let's see how this looks. If I stored this again, press D, As you can see. So first of all, you already know this one. Then I'm warning you that we have an arrow, this is our own error. We can also look an exception. Exception. Yeah, it's an exception. And then assertion failed, debug dot assertion bool. So we can basically assert certain things and say, Hey, if this is correct, then continue. If this isn't, then stop can be useful for, Let's add debugging. And yeah, that's sort of the things that I wanted to show you. Of course, inside of the div, there are a few more things that you can look at, but overall, those are sort of the ones that I wanted to show you. If there's other things that you need, you could go, of course, look into the Debug class yourself and look at a few things, but those are sort of the ones that I found most useful for myself. And yeah, that would actually already be it for this lecture and this section. And I hope you found it useful as always. If you have any questions, feel free to ask and I'll be sure to respond. And yeah. 66. (Cheese Clicker) The Idea of "Cheese Clicker": All right, Welcome to the cheese clicker here for the unity course. And in this lecture, I just wanted to quickly show you what we are going to create in this section of the course. We want to create a cheese clicker. There's a sort of like Cookie Clicker, but with cheese. That's the idea I came up with. And because Cookie Clicker is a very easy concept to understand, I thought that then making it into cheese would then also make sense. And it would be hopefully easier to follow because the concept is so easy. However, we can still create a very well interesting systems with this. And we can also going to create who will. So in this case, this is already finished. In this case here, I wanted to show you this and let's just see how it plays. So the way it plays is we basically have the ability to create new buildings so we can build a clicker building and a milking station building. We also have upgrades that get generated that we have implemented. And if we click the cheese, then as you can see, the cheese number up here increases. And if we have enough cheese to build something, then the actual buttons here will also turn so that we can click it and then we can click, for example, the clicker. The number here would increase and this number will also increase. So the cost will increase, as well as the number of buildings that we have of this type. The clicker will generate for us one cheese per second. We can then, for example, by an upgrade down here, and then the clicker will all of a sudden get us to cheese per second. And when we have, for example, a milking station down here, this will generate us five cheese every two seconds. Right? So this is sort of how the game looks. We also have some cheats built in. So if I press plus, then we're going to increase the cheese. If a plus minus, then we're going to decrease the cheese. So that's pretty cool. And all of this will be built over the next few lectures. First of all, the cheese to click them are going to look at the buildings. We're going to add a simple UI to it that we can basically use. And then last, we're going to add the upgrade system. All basically in here. Like usual. The, both this as a package is available for you to download, as well as each of the sprites here are available as a resource. And yum, however you wish to use this. Basically, you can basically get the your, the entire project here, download it, and then look at the code while I'm writing it on, while I'm explaining it, or you can basically write it in parallel with me. There is of course, something for you to decide how you can best sort of understand this and how you can best see how this works. But overall, that will be it for this lecture. Now, I hope that you will have fun for the upcoming lectures where we actually create our own first game, the cheese clicker. And yeah, that would be it. And I hope you have fun in the upcoming lectures. And I would say, if there are any questions, of course, during the making of this game, then feel free to ask and I'll be sure to respond. And yeah. 67. (Cheese Clicker) Creating a Cheese to Click: All right, welcome to creating the cheese clicker here for the unity course. And in this lecture, we're going to make a cheese that we can click. And also a game object where we can store our cheese in. So basically a cheese storage, so to speak. And for that, the first thing I've already prepared, the scripts folder and the sprites folder here. This shouldn't be anything crazy or completely new to you. And let's actually take the cheese. So this is the resource sprite that I have. Basically as available as a resource. And we're going to change if you numbers here. So first of all, the pixels per unit is going to be a 150. We're going to make this filter mode point so that we have sort of a crisp image and the compression will be set to none because of this, some basic, it's not an arrow as a warning here. So then the compression none and then the warning will go away. Right? So now that we have our cheese, we can actually just drag it into our scene and now we have a cheese here. Let's locate this somewhere like 00, negative 0.5. Say that that's a good location for it. And we're going to rename the cheese to the cheese clicker because that's basically the trees that we're going to click. And we're also going to create two scripts. But before we do this, we're going to go to our project settings editor and then down to our root namespace and the root namespace. In this case it's going to be cheese clicker, right? So having this as a root space, namespace will then generate the namespace like you have probably seen inside of. Inside the namespace lecture inside the C sharp introduction, right? So let's create our C, C scripts. The first script we're going to create is the cheese Flickr. So this is the actual clicking of the cheese. And then we will immediately create another script. And this would be the, we can call this She's storage. I think that that's a good idea. And we know that okay, in sort of a cheese storage there, we store our cheese so to speak. And let's open this up. And once it's open, we can immediately switch back here to the cheese clicker. And now we have both of our files open. So let's think about what we need for the cheese clicker itself. So let's first of all be able to basically click the cheese. Well, there's actually a very nice thing that we can do. And that is going to be, we're first of all, we don't actually need either the start nor the update method here. And what we're going to use is two methods that are available because this is a mono behavior. And that will be on mouse down, as you can see. So on mouse down and then with tab we can basically autocomplete this and on mouse down, what this does, as you can see, is called when the user has pressed the mouse button while over the GUI element or collider. So this is a GUI element, this will be a collider. So therefore, what we're just gonna do right now is just increase. Basically, just so that we know that this works. And one thing that we're also going to do is we're going to say, we're going to have a new method here, which is going to resize the cheese. Because right now, actually, let's first of all look at this and then we're going to figure this out afterwards. So increased cheese. So when we click this cheese Clicker, then we want to increase the cheese. Now this is of course not implemented yet, but the, at least the output should work. So this cheese clicker, let's put the, not the storage but the cheese flicker on there and see if when we click it, whether or not we get a console output. So I and nothing happens. So that's, that's kinda weird. Why is that the case? Well, it did say that it needs a collider. So there's two ways that we can do this. We can either add a collider here, right? Going to Physics 2D box collider for example, or a polygon collider. Or we can do something else. So I will remove the script for just a second here. And what I can do is I can go up here, put in the brackets and say require component. So this basically says, Hey, this, this class, wherever this moral behavior is attached to the game object, requires also this component. And then I can say type of Collider who lighter too deep. And this will then add a collider as soon as I added this moral behavior to the actual, to the actual game object. So what we're going to see is if I add this now, as you can see, adding a component failed because we need either a box clutter or some of those things, and we need to add to that first. So if we now go in here and we're going to take the polygon collider and it's going to make basically the outline perfect here so that we can't really click outside of it. We're just going to keep it as it is and be fine with it. And once we added the polygon collider, we now add the cheese clicker, know Era, and know everything works totally fine. So this is basically to ensure that a certain script actually works by using this require component. Okay, let's try this out and see if when I click it, it works and it does. So if I click it, as you can see, an increase cheese gets printed out, which is really good. So we know that the mouse down works. Now, as you have seen, there's not really a visual indication there. And what we're going to do is we're actually going to basically re-size the cheese. And for that we're going to make a new private method here, private void resize cheese. And this is going to take a vector 3, which is going to be the new size. So the idea here being that we're going to basically just put in a vector in this method and then it's going to change this local scale equals new size, new size. And we're going to do this once in the beginning here, as soon as I started with the mouse down. So we're going to resize the cheese to basically, well, it's size is right now one, so this would be its original size. And then we're going to say something like 0.9, for example. This would be workable. And then we of course need this to grow again. Otherwise it won't work. So now then we can use the other mouse method. So this will be on mouse up. And once again, this is a method courtesy of the model behavior here, we're going to resize cheese with vector three dot one. So this will basically reset it to its original size 10, 11. And that actually should work already. So let's see if that works and we get a cool visual effect here. So what we'll do is, of course the scale will now change. So let's see if that actually is the case. And it is the case. If I keep it held down, then it works. And as soon as I release the button, then it works as well. Now what happens? For example, if I were to move out of sight of the screen, as you can see, it still works fairly well. I believe that there are ways that you can probably sort of cheat the system. I think if I now press, nope, if I press the Windows key, it still works very well. So that's actually really nice. And then now we get even visual indication of this. Of course, you can always change this upright. Maybe you want this to be a little more subtle. So then maybe you want to change it to like a 95 percent of its original size or something else. Overall, I think this is going to be fine. Right? Then let's do the following. Let's actually think about this. Well, now, we somehow want the cheese storage to be able to store cheese, right? So there's a few things that we need to do in software storage now. And yet the first thing, of course, is going to be a private int called cheese, right? So this cheese, there you go. And this is going to store how much cheese we have. Let's make this a serialized fields so we can actually see it inside of the constructor as well. And then we're going to make something that's well, maybe not a lot of you know, but this would be a, this is basically a C-sharp design pattern, and this is called the singleton pattern. The idea is that we have a static cheese storage variable here. We're going to call this the Mets, call this the cheese storage. And this will always be, well, the one that is inside of our game. How can we ensure this? Well, if the cheese storage, so this static variable is equal to null. So if there's nothing written inside of it, then we will simply said she's storage. So, so the static variable to this. And this will then ensure that number 1, there's o ever only one particular she's storage available. And then also that we can access this from anywhere, basically by using the class. So, so she storage, storage, maybe the name could be changed overall, I think that this is fine. She storage is probably going to be fine. Let's actually rename this so we can press Control R to rename this. Let's call this cheese storage instance because that actually is a better name for this. And then what I'm also going to add is also going to add three events here. So we've seen this very shortly at the end of the C sharp introduction. So we're first going to make a delegate, and this is going to be called on cheese amount change. So this is basically a a delegate. That is, they are if a cheese amount changes and then we're going to make three static events. So public static, static event. One of them cool. So all of them on cheese amount change. One of them called on cheese added. So this would be the one that gets called when there's more she's added. Then we're just going to copy this two times. One of them on She's removed, let's say could also be on cheese, subtracted, something like that. And then we're also going to have one on it. She's change, changed, they go. So idea being that we want to call this when we add a cheese, when we remove a cheese and this is going to be called on either one of those. I would say that this is some, once again, like I've said in the C-sharp introduction on events, you really don't have a negative on adding more events. I think that this is going to be fine and who knows what we want to add later down the line where we might need all of those events. This is why I added them. And yeah, so now let's think about what else do we need? Uh, so we want, basically, if we think about this to the public methods this time, right, which can be called and those would be and she's rate. So we went from somewhere to add a cheese with a particular amount, of course, right? So this I think, would make sense. But it's like a, I want a particular amount of cheese and this is then saved in this amount perimeter. And what would happen is this dot-dot-dot cheese would then just be plus equals to the amount. But that's, should be fairly easy to understand. And then of course, we also want to call the events here. And we can call these events with a particular thing and that is going to be on cheese added, for example, because their realities, and if we put in a question mark dot invoke and say cheese, then this question mark basically makes sure that there is at least one subscriber there, otherwise it will not fire. So this is basically the same as if I were to say, if she's added is unequal to null, and then say on she's added cheese. And I believe if I do this, then it's actually going to say, hey, we can simplify this to exactly this one. And as you can see, this is exactly the same. Well, we need to do the same here for on she's changed as well. And then we are actually happy with this. We're going to simply copy this over and then we're going to say this would be removed trees. That's then be this she's negative amount. And then instead of added, we have removed. Now currently of course we, in this scenario, we could remove trees that we don't have. So we could go negative. But we're not going to worry about this at the present moment. Right now, we're just going to add cheese any way with the clicking. So that's going to be fine. And now the last thing that we need to do is we need to somehow, well, have the add cheese method be called in-service cheeses, littler and clicker, and then we are fine. And we can do this by simply going in here and then saying, well, I know that I can get my cheese. Let's actually do this at the bottom right here. I can say, for example, cheese. Dot storage instance. So this is the instance. So this is basically the same thing I would be getting if I were to do game dot find cheap storage. But now because the static instance is saved inside of the class itself, we can just do it like this at cheese and then say one. And in the hopes that this works, that this would be pretty cool. So let's see, we don't need the debug anymore. And let's see if this actually works like intended. Okay, let's start this and see now first of all, of course, we need to add a cheese storage here. That would be pretty smart. So she's storage. And let's add this storage. Here they go. As you can see, 0 tree is currently in there. And let's hope that this increases when I click this. And it does, isn't that great? So it increases each time I click it and we're getting, she's like, no one has ever gotten cheese before by simply clicking this cheese on a scale? Not seen since. I don't know. I don't know when they started making cheese, but yeah. So that would actually be it for the clicking of the cheese. So we have each season that we can click now. We also have a cheese storage where we can add cheese and remove cheese. And now it really comes down to, you know, adding a few extras. So one of the extras that we're going to add immediately is just so that we can basically test this out is to sort of cheats. So instead of the update method of our cheese storage, we're going to do input it up, get key down. And then he Code dot keypad. I'm going to use keypad plus. So the plus on the keypad, them usually on the very right of your keyboard. What we're gonna do is we're going to say the instance dot add cheese. Let's say about 10. We're just going to add 10 cheese to it. And then we're going to copy this over. And what I'm going to say key, keypad, keep at minus. And then we're simply going to do dot remove cheese. And this would be 10. Now it's important we don't actually have to pass this a negative number here. We want to pass this a positive number, which you could of course also do is pass, add cheese, a negative number. And this would also work. Although of course then the cheese added would have kind of an issue here. So this would be something that you could add as well. So this won't be like absolutely completely solid, but I wanted to mention this. So there's very easily done with a an an if check in that case. But yeah. Yeah. So that would actually be it. Let's, um, let's see this in action the plus and the minus so that we can basically add and remove trees here without clicking the actual cheese. So let's click this a few times. And then let's say first the plus, and then I get 10 cheese immediately without an issue. And I can also remove cheese. And if you see this, then we can actually go into the negatives without an issue here. Then I can go back with the plus, basically just adding and removing cheese. This is good to add this just silver sort of for debugging purposes so that you can try out. Okay. I need, if you maybe if we want to add something that costs Sheets to do, then what we can do is basically just add a bunch of cheese. We're storage. And then we're going to be fine and we don't have to wait and click like 1000 times until we have 1000 cheese to do something. And then the number of course can also change. But yeah, that would be it for this lecture. Adding a cheese to click and then getting the cheese, storing it inside of our storage here. I hope you found this lecture useful like always, if there are any questions, feel free to ask. I'll be sure to respond. And yeah. 68. (Cheese Clicker) Creating Buildings to Build: All right, let's continue with our cheese clicker here for the unity course. And in this lecture we're going to add the ability to build the buildings that will generate us cheese without us having to do anything. So passive cheese, what could be better? I don't know. So let's think about this. We will first of all make a new folder inside of our scripts here called buildings. So this will just how is all of the scripts that our buildings are going to be in. And we're first of all going to create a new class called Building. So building there it is, yes. And this is going to be an abstract class. So let's open this up and let's think about this for a moment. So first of all, this will not inherit from a mono behavior. So this class will be sort of a, well just the data class. You could think about it like that. And we're also going to add the buildings here to our namespace as well. So this will all be inside of the buildings namespace. And the building is going to be an abstract class because we never want a specific building. We only want the inherited classes. So each time we're going to create a new building, we're gonna make it inherit from this building class. And so let's think about this. What do we really need for a building? What sort of the components of a building? The first thing we need is a cost rate. So we're going to make this have properties basically. So we're going to have a cost basis basically for this civic buildings. So this is how much cheese it will cost. We will also, if I'm just going to copy this property over, we're also going to have each He's gain. This is simply what we will gain in terms of trees. And then we will have a float property here, which we're going to call the time interval. And the idea here being that the time being here, The idea here being that we are going to simply have this time as you have this cheese gain each time interval basically. So those are the three basics that we need for a building. Maybe you can come up with a few more. But right now we're going to do it like this. And there are also some events that I was thinking of. One of the events would be, first of all, a delegate, public delegate, void. This is simply the building handler with a specific building. So building, building. And then we might have to events which are both from building handler. One of them is on building, so on building built. So this is basically when we are building something and then we also have on building cashflow that we're going to look at. So the cashflow basically is when we add the cheese gain. So those would be the two events that I came up with. Of course, there are probably some more that one can think of, but right now I think that those would suffice. And, and let's just think about a little bit more of this building class. So we're going to have a protected the constructor. Building with exactly those three properties here. So the cost, we're going to have the cheese gain and we're going to have the float time interval. And those will simply be set to exactly those properties. So this dot cost equals cost. This dot cheese gain is equal to cheese gain. And then this time interval is equal to time interval, time interval. This one, they go, right. And well, that's all fine. And well, there's one more thing that we need, of course, the public abstract void cashflow. So this is basically the abstract method that each of the inherited classes need to implement in order for them to be like proper buildings. Because we need basically this cashflow to be called each time. Well, exactly this happens. So when the time interval is done, then we are going to call this method. And each of the buildings will have a different sort of cashflow method. Whether or not that be maybe returning, simply returning ten cheese, or maybe there's some different parts. So maybe you have different buildings. And when you have one of those, one of building a and one of Building B, the sort of influence each other or later down the line when we create upgrades for specific buildings than these cashflow methods might change for specific buildings. That's why this is an abstract method in this case. So I think overall, that is sort of final ready. Now let's think about two more things. Maybe if we build multiple buildings, then we want sort of a modifier by which the cost increases. And because we have stored or cheese in sort of a CI, storage as an integer, we're probably going to have this be a modifier that is also an integer. And this is going to be the cost modifier of two. So we're just going to increase the price two times, once the actual building is built. We might also want a list of all buildings. So this is going to be a static list of type a building called a buildings. And this will be accessible via two specific things. One of them is going to be a property. So we're going to have actually a static property called list. So this is going to be a list of building called a building, Building note. Now that is going to be building in building instances. And that is going to have a get or a way of getting the buildings. And it's just going to return how buildings. However, this of course, he has an issue because maybe this is null because he up here, we haven't actually done anything with it. So we need a way of also initializing it. And for that we're going to make a private static list building method. So this is going to be buildings, building, which is, we're going to call construct all building instances. So the idea is that we're always only going to have one instance of a building and then add this to a list inside of our cheese storage, for example. So later, when we go there, we're going to have a list of buildings in here which are built. And inside of here we're basically only have one list. So this would be the list building. Result equals result. This correctly new list of building and then return result. And in-between here, we're going to add a building. So each time we add a new building, we would add this particular building right here. And let's then, for example, and also make it so that if buildings is equal to null, so if billings hasn't been set yet, then we're going to set it by just calling construct all building instances. Right? So for now this is probably a step up of complexity in this moment. Now there's a little things here, and this wasn't just, let's say, chosen at a whim. There's, of course a lot of thought went into this, let's say. And right now, we could think about, think about it like this. We have the abstract class building and we can then have a list of buildings. So let's, if we then have, for example, a clicker, we're going to make a clicker building which clicks automatically. Let's say. Most of you probably have played Cookie Clicker already. This is basically the first, yet the first thing that you can do there. And this Cookie Clicker building, basically, we will add via a new. So we're going to make a new class, have this inherit from building. And then we're going to add this to this list here. And then we have one instance of this and we'll never use new click I get. So this is basically, we'll have one instance here and then will always pass these instances to some list that we're going to make later down the line inside of our CI storage. And as cheese storage will then be basically needs to then call the cashflow of each of the buildings that we've given to the cheese storage. And then we will get our cheese profits, Let's say. So. Let's, so let's just make a new building here. So let's create a new class called the clicker. And let's open this up. Make sure that this is under buildings as well. And then this will actually inherit from building right here. And the first thing that we can see, of course, is potential fixes. So implement abstract class. So we need to implement this cashflow method, of course, otherwise it will not work. Right? And what we're gonna do is we're simply going to do the following. So every time this cashflow is. Cold. What we're gonna do is we're just going to say cheese storage, dot ci storage instance, add a cheese one right now. So we're going to make this very, let's say, easily done like this. And then also we're going to do is on building cashflow. Question mark invoke. And then this, because this is the building that is basically getting this cashflow. And we also need a, we need a read exactly the no parameter inside of the constructor. So we need a new constructor here. So public clicker with cost, the, sorry, the integer cheese gain, she's gain and the float time interval. And the great thing is that we can do now is we can just put a colon in here called base. So this is going to call the base time interval. Time interval they go, This is going to call the base constructor for the actual building. So inside of here, we actually don't need to do anything else. And this would be the building, how I would construct it. Of course, there is numerous ways in which we could do this differently. So for example, instead of calling the CI storage instance here, immediately, we could return an integer with how much cash flow this building generates. So this is not the only way that you can do this by any means. Like there are probably, I mean, like 1000 ways to Rome basically. So all, all roads lead to Rome. It is incredible how many ways you can do this is just one example of it. And let's see. If we go back to the CI storage. Basically here now we want a list of the buildings that have been built. So let's create a new list here. So let's make this a private list of type building. So we now need to use a buildings building. We can also simply do using She's clicker data buildings. That's probably a little bit easier now. And we can use all of the classes in there. And that should be fine as well. Right? Let's do all buildings. So let's let's do all built buildings. Yes, let's do this. And we will initialize this instead of the start method. So all built buildings equals new list of buildings, so that this is initialized. And then we can basically add to this particular list. Once we have a, well, once we build a building, now for that, we of course need a new method. I'm just going to call this a public void. Build, building, building. There you go. With an instance of a particular building. So building a new building. Building at this point already seems quite an interesting word. But I think that this is fine. And now there's a few things that we need to do, right? So think about this, okay, what do we need to do for to build a building? Well, we need to see, see if possible, right? So that's the first thing we need to do and that should be, well, this, we only need to see, okay, the cost of the actual building should be smaller than what the amount of cheese that we have. So what we can do is if new building dot cost is basically smaller or equal to the cheese that we have. Then we can build. So this is basically look like this. There you go, build. And then if that's not the case, then we can say something like don't build something like that, right? And so, yeah, I hope that that makes sense. So the idea is that if the building costs more, or in this case, costs less than the cheese that we have or is equal to exactly the cheese that we have, then we can build it. Otherwise we can't. Of course, we also need to subtract this. So there is some adhere maybe we could. I mean, basically, only thing that we need to do is we need to say, okay, remove cheese. So remove cheese in the height of new building cost, right? So we simply remove the cheese with exactly how much the building costs. Then we of course, want to add this building. So all buildings or build buildings now add a new building. So this should actually building the ego. So we're going to add this building given over in with this method and added into our lists here. And then what we're gonna do is we're gonna do the following. We're going to basically use something that we've not yet seen before, which is a co-routine. And that is going to be actually fairly straightforward. So we will remove the trees. We have added the new building, and now we need to somehow be able to have this. Have the time interval, check and add to our cheese balanced, so to speak, write. And the way that we can do this is we're going to define an a, an eye enumerator. I'm going to quickly explain after we've done this. So this is an I enumerate tour. So this one here, we're going to call this the building cash-flow with a particular building inside of your building as the parameter. And the great thing about this ion numerator is that we can do something called a yield return. Return. And then we can make a new weight four seconds. And this is the really cool thing. So we can wait for a particular amount of seconds. So this method takes a float for seconds. And what we can do now is because we are giving it a building. We can say building dot time interval. So it's going to wait exactly by the time interval of the particular building given here. And then after this is done, so if after this is done, then it's going to continue with this method. So it's going to wait here. In this particular method, everything else is still going to work, so it's sort of in parallel. This is going to wait until the seconds or over. And once those are over, this is going to continue. So we're going to say this is Building dot cashflow actually. Cashflow they go. And because this adds the cheese, like I said, in this case, we could also just simply return an integer and add the cheese here. Both of those would work. We're gonna do it like this for now. And that's totally fine. And then at the end of this, because what we're gonna do is we're going to only call this one's inside of itself. We're going to call this another time. So this would be, this is the start co-routine method. And inside of it, we simply call building cashflow building. And this exact thing we want to put in here as well. So this is a mono behave. This is of course new building. Now the ego. What is a co-routine sort of in what we say? So the idea of a coroutine is we have seen this, the invoke method to before. That was part of the model behavior. And the invoke method allowed us to basically call a particular method a certain number of times, you know, every x seconds, so to speak. And the coroutine is something very similar to this. Instead of a co-routine, if it's sort of a, you can think this is sort of an asynchronous method that can wait for a particular seconds. And then we can also, if we just take a look at this yield return new weight for end of frame fixed update. We can wait until, we can do wait awhile and then also with seconds real-time. So there's a few things that we can do with this. Right now. We're just going to use it basically, two will generate our cashflow. This is also something that could be done inside of the building itself. So we can add these spilling cashflow inside of the building itself and started in there. Right now, we have added here, and I think that this is also going to be fine. We will also make a debug dot log warning. Can't build because no cheese. So that's just a little message here. We know that, hey, we can't actually build this building. So overall, I do believe that this should be basically all that we need to do in order to build this building. Now, there's a few more things that we need to add. So number one, of course we need to add that the instance here. So inside of our result, add new clicker. So right here, we're going to add a new clicker. This is the only time we will actually ever call this new clicker here. And then we want to add this with particular cost, cheese gain and a time interval. So let's just say that this costs 10 and it will gain new one cheese per second. So this is what this means in this case. So cost is 10. 10, we have the gain would be one per second per 1 second. Let's just do it like this. Yeah, they go. And of course this is customizable. You can think about this because of course, this needs to be adjusted for balance, for example, right? If you have multiple buildings, then maybe they want to cast different and their gain could be different as well. And this is basically where you would, in our case here, the way I've built it and the way you will probably build it. This is the way we do it here. Of course, once again, there's a million ways to do this. And there's one last thing that we need to do because right now we're just getting the cost and we're not changing it. So there's multiple ways that we can do this. We can either say, well, we can change it here, or we could have another method in here. Let's actually do the following. Let's actually add a private int cos, rather this way, there you go. Private cost. Yes, exactly. And then we're going to, instead of instead of a building changing the cost here, actually we can change the constant, that's fine. We're going to change this property a little bit up. So this is going to be return a cost, right? So we're just going to return a cost here. And only setting, what we're going to do is we're going to say cost equals value. So this is just so that we have an extra private variable here. And then we can basically change this one up. So what we can do is now add a new method here which is going to be public, public integer, gets cost and increase cost. Let's just call it this. That's fine. So what we're gonna do is we're going to have the cost equals the actual costs here, returning this afterwards. And exactly, So we basically save this before we increase it. Then we're going to say, we can say cost is equal to, we can just say times equal the actual modifier, modifier. They go, right. And then if we call this, we both get the cost and also it increases. So let's do this inside of the storage in a sort of a cheese storage instead of here, just say remove cheese by the times of cost. We're actually going to say time, get costs and increase costs as well. Right? So as you can see, there's a lot of things going on here. It's it's quite a bit, but one step at a time, and I think that will be fine. So for right now, what we will do is we will simply add a, an input where we can basically build this building. And then we will make a new game object that we can, we can click. But right now let's just add a basically key code. So this would be keycode. See, let's say for Clicker of course. And when we press this, see, do we want to happen? Well, we want this built, a building to basically be called and then we now need a building there. Okay, let me think about this. Where can we get this building from? Well, we have a list of buildings here, right? And then we add to this, and this is public static. So in theory, if we think about this, we should be able to access these list of all the instances. And we know that the clicker right now is the first instance. So this would be basic or the first building inside of this list. So this should be doable by doing a building. So this is the class dot. And then we have building instances. This is the list. And then just getting the one at index 0. So this will return exactly this class here that we have created. And if everything works, then this is the clicker and the cost will be, well, ten. If we have these ten cheese, then we're going to build it. And then it's going to remove that, increase the cost of this building. We're going to add this to our list of buildings. And then also we're going to start the cashflow co-routine, which is going to run every second in our case. Well, let's hope that that actually works and that actually does what we wanted to do. There's a lot of things like a lot of interlocking parts in this case. And yeah, I guess that we can actually just start it and try this out. So the first thing that we do is of course we now have a 0 cheese. And if I press the C key, what we would expect is to say, Hey, I can't build a building because I don't have enough cheese. So let's see and can't build because node cheese. So that's pretty good and she's also doesn't increase on its own. So I can now press the plus key and I get myself ten cheese right here. And now the big thing is, does it work or does it not work? So I press C and well, it decreased the number of cheeses that we have. And as you can see now, our cheese is increasing by one every second. Now, the great thing is that earn before this. Well, that's actually just remove our ten Jesus again with the minus key. And if I see again right now, Well, as you can see two, so I still don't have enough money now or enough cheese now at ten, I should have enough. But as you can see, it doesn't work because I modify our increased right, so now it costs 20 cheese and if I press it now, as you can see, it built it and now we are actually getting to cheese per second, because now we have two of those clickers, click every second. Each of us basically getting us one cheese per second, right? That is great. That actually worked. I mean, totally fine. As you can very clearly see, we can have multiple buildings of the same type. And now adding a building, and this is basically what is one of the most important things when you do something like this, you always need to think about your ability to add more of the things that you want to add, right? So the usual issue could be, well, we could make this crazy complicated. And for some of them, for some of the ideas. If you see this the first time, you might be like, Wow, this is really a lot at once and I don't disagree. It is can be a lot in the beginning. But step-by-step, if you think about each of the individual parts that are not that complicated, just to put together, they can create something that is actually fairly complex. And yeah. Now, how would you add a new building if you were at this stage, how would you add a building? Well, you just need a new class here, right? So we can actually do this just for the sake of argument, just so that once you have sort of this ground with a fundamental things set up, how easy it could be to add a building. So let's make a new building and we're going to call this the milking station. Because that's I mean, that's what I came up with. I guess that's the best explanation I have. This of course, once again, inside of the buildings namespace and this will be a building. And the great thing now is that, well, we can sort of just the clicker here, just for a moment. This of course will be the building station here. And the cashflow, basically exactly the same, but maybe we want a different number of cheese or that's also an interesting thing. I actually added one here. This actually should be this dot. She's gained. It's not like that's not an issue that can run into, but that's fine. And then inside of here, we will do the same thing, this.tab cheese gain. And that's already it. So this is number one, step 1, step 2, adding this here so we can copy this and say milking station. And then we just need to know, okay, how much it's going to cost, how much are we going to get per second? So let's say this costs 25. And in this case what we're going to get is, let's say we're going to get five cheese, but only every two seconds. So then we can say cost is 25 to 50, five cheeses every two seconds. So of course that's actually a better value in the first case compared to the clicker. But yeah, that's pretty good. But of course you need to 25 cheeses to build it. In theory. If we now add a new sort of key that, so that we can build it. So let's just do m here. Now we know that the instance there is one. This of course, could also be a, this could also be a dictionary, right? Where you, instead of doing it with the inner, with the indices, you could do this with an enum. So you would have a building's enum and have each of the buildings in there as well and could access them like this would all work. The same idea basically. So now if I press M, I would envision it building a, a milking station now. Right. So let's see if we can actually get this done. And yeah, that was it for adding the actual new building. If you want special things happening with this particular building, of course, then it's a little bit more complicated. But right now this should work. So let's see if that actually does work. So first of all, pressing the M key, I don't, I don't have enough cheese for this. So let's get ourselves 30 cheese and then I'm going to press the empty set has subtracted 25. She's, and as you can see, every two seconds we're now going to get five cheese. So that works perfectly fine as well. And that's really nice. Now of course, we don't have any visual indicators yet. We don't really have a UI because we are not actually, we haven't talked about the UI really. We can think about adding just sort of simple text of course, because we've seen the adding of the simple texts, that, that would work. But overall, this does work already. So if I perceive a bunch of times now, now it doesn't work anymore because now it's costs me actually like 80 I think already because I've built too many. And now as you can see, the cheese is coming in just like that without even doing anything else. So that's pretty nice, That's pretty good. And yeah, that would be it for the lecture on how to add buildings. Once again, this is sort of one of the ways you could do it. I mean, there's probably a 1000 other ways that you can do it. But I'm actually fairly happy because this is very much expandable. And you can expand this. Of course, there are few things that you can add, especially one more or a few more buildings on your own. But yeah, that was it for this lecture. Next time we're going to add a GameObject that we can click to basically build our buildings. And this is something we're later down the line. I'm going to then turn into a UI. So we're going to add a few things here. Next lecture. And yeah, but that was it for this lecture. I hope you found it useful if there are some points where this has been a little confusing because we've jumped around a little bit from class to class and so on. Then do feel free to, number one, I would first of all say, you know, what should again, maybe think about this a little bit. Look at the class. If you download it or if you've programmed to simultaneously, then maybe look at a little bit, try to understand each of these steps and each of the methods that we've implemented and think about it like that. And if questions remain, of course, always feel free to ask and I'll be sure to respond. And yeah. 69. (Cheese Clicker) Making a Basic UI for Building Buildings: All right, let's continue with the cheese clicker here for the unity course. In this lecture, we're going to add a very simple UI, as well as the possibility of adding the buildings via a click on a game object. And those game objects are going to be UI elements, mainly buttons. And they will well then just function in a way where we can click each of them for each of the buildings that we have. And they will then basically spawn in a building. And they will also change. So will, they will display basically the cost and also how many buildings there are, each particular type. And we'll also have a text that displays how much cheese we have at the current moment. So basically h, he's counter, you could say, first thing, we want the cheese, cheese storage UI. So personally, I always end my UI scripts with UI. And then in the beginning, whatever they are. And this is going to be cheese decker you, I of course, as in terms of namespace, we will also be using Unity engine dot IM for this. First thing we need is a private text. Hold cheese. Let's just say, see, I can achieve storage texts. There you go. That's a, that's a mouthful, a go. And this will simply be while gotten in here. So this is going to be if cheese storage text is null, then we'll just set the storage linked to this dot get component text. So we're going to use the Get component on this script itself. And then it simply gets the component of the game object of type text that this particular script is attached to. And then we will go to cheese storage dot on cheese amount. So she's changed. So this is the idea. If the cheese changes, then we're going to call a particular method. This is going to be just change number method. That's going to call it. We don't need the update method here on this conveyor private void. Change a number with a new amount because this is exactly the this is exactly the method signature that we need for the cheese amount of change delegate here. And what this will simply do is it will get the cheese storage texts, texts equal to new amount that's toString. So we will simply change the text here each time the cheese changes. This is why I said that that is a good idea to add those events you never know when you will need them. Of course, you can always add them in later down the line as well. However, in this case, that's going to be fine. So let's think about this, adding a UI element here. So right-clicking inside of our hierarchy UI and then a text. Then of course, we need to change the canvas once again to screen space camera and drag the main camera over here. And then our text is down. They are very small and we're gonna make it a little bit bigger. And then also make it the actual text a little bit bigger, something like maybe 50. Ah, that's way too small. A 120, I love it. And we will have actually two texts, so we'll duplicate this Control D. This is going to be the cheese label, let's say. And that's going to be just cheese. And then the other one is the cheese storage text. Yeah, that's fine. It's going to be a 0 for now. And then we're going to also make this a little bit nicer looking. So we're going to do something like this. This is the cheese text. There you go. And then this one can also be a little bit smaller. They go, right? So now we have this. We will also make both of those white just so that we can see this a little bit better. Yeah, I think that that's fine. And then if this were yeah, so this works fairly well. And for this C cheese storage texts, we will simply add the UI script that we've made right here. There you go. Is this not advocate? Well, see the ego. It always opens the the material. They're kind of kind of noise a go. Okay. She's storage to I is now on there. And this should actually already work totally fine because we have added this event. And because this works via the event, everything should work immediately. This is, like I said, the delegates on the events really useful for the for expandability of your project. So adding this was fairly easy. So let's see if that actually works. So if I click this, as you can see, it increases to two. I can also cheat. So if I press the plus and the negative, this also works. And if I now were to, for example, add a clicker by pressing C, it will subtract this. And now every second it will update your as well. And this is much better than having this in sort of an update method where checks it each frame. Because we don't need to change the UI each frame because it doesn't change each frame. And that's sort of the idea why this events, the event, a delicate system in this case, is like incredibly superior to anything else that we could implement in that case. Right? And now we basically want to game objects that we can click instead of pressing C and pressing M to create new buildings you're writing, we're actually going to create a real UI for this in this case. So I'm going to sort of take a little bit to the future of what we're going to see a little bit later down the line. So some of those things might not be a 100 percent understandable, but I'm trying to explain them as best as I go along. So the first thing that we want is we want something that is called a building UI. So this building UI is basically going to be the class that will sort of, this will make sure that we know, okay, What type of buildings do we have and can build? And it will also enable and disable certain things from being built based on the cost. So for that, we have buttons. So there's a very easy way that we can do this. We're going to add something to our Canvas. So right-click UI and then we're going to add a panel down here. The panel is just sort of a background and we're going to add this to the side here. I like this. And then we're going to have to this panel. We're going to add crazy enough another panel and make this a little bit smaller right here. So I think that that's good. This would be the buildings panel. And this is then a building panels. So this is the panel of one particular building in this case. And we're also going to add a few assets here. So I have a clicker, I have a cow for the milking station, and I also have a barrel for something else that we might want to add. So this is the barrels, let's see here. So we have the a barrels which we actually want about a 500 pixels here, so that they are a little bit smaller also, of course not bi-linear electronic, fine, I think that are big enough. The cow and the clicker. So the clicker account should be 150. And let's keep it by linear as well because it's fairly big and the clicker that's 250 and this is definitely point. No compression. Yeah. So now we can sort of think about this. Okay, this is a panel for a particular building. And we can also think of this as a button. So we want to basically make this a button that we can click and then have this well built or building if this is possible. So right now, this is just a panel, but we can simply go to Add Component, go to your eye and add a button. And now this would be a button. And this can unclick, do something specific. And this is going to do whatever we actually tell it to do. But we don't want to add this manually. We want to add this with 0. We cannot manually, but we actually would want to probably add this with the actual script. In this case, we're going to add up this manually, so we're going to call this another script. So let's call this the Build UI. So it's a lot of different scripts, once again that we need, Let's actually close out of a few here right now because we don't actually need those at the moment. And this Build UI is basically going to be the one that determines, okay, what, what happens here, what building gets built. And we can basically just do something like this. We can basically give this a go. Let's actually do the following. So let's do this. We can just say public, void build. And this is going to get an, a particular index here. And this simply will do the following. So we're going to add, simply going to say cheese storage dot instance. So we're going to get the instance of the cheese storage and then we have the build building here. And then of course we need to give it a new building. But we can do this by, first of all, going here using She's clicker dot buildings. Also. Just making sure that this is under UI so that we have everything neat and tidy. And then inside of here we can just say a building. Dot building instances. Index, they go. So we can specify a particular index of a building which should be built inside of the key storage instance. So this is exactly the same thing. If we look at our cheese storage once this has reloaded, we can see that this is exactly what we've done here. So we've just called this in another script. That's all that we did. And then also the building instances that, that's actually all that we're really doing here. And we're doing this with this particular panel. So and then what we do is we added this Build UI to this panel here. Once this is actually added, Let's see. There you go. Now it is here. And then we can do is this onclick sort of field here. If we press this plus, then we can say, then we can look at this one and click on this dot there and say, Well, I want this to be the building UI. And now onclick, and then the building UI is going to get executed or something then there. And as you can see, and we actually don't have this because I of course, because we can't actually do the building UI, we actually, which is kinda weird, we actually have to add itself to it. So we actually have to take this building panel and drag it in here so that now the building panels in there. And then if we look here, the Build UI, and then built with a particular integer, in this case, 0 is exactly right because the first one is going to be the clicker. And now we're going to make this a little bit more visually appealing. So we're going to add a few things on here. So first of all, right-clicking the building Panel UI text, making this a little bit bigger here. And then let's say font-size 50. Yeah, that sounds about right. Let's make it a little bit bigger. 70, that's fine. This is going to be the clicker. And let's also center this sort of here. We could, for example, also add the amount of cost, sort of like that. But right now, let's actually just add the clicker for now so that we have something that we can click. And let's also add a nice little image. So this is in here image. And we can make this a little bit bigger. We can sort of scale it. Pressing old, we can scale it from the middle. And then I'm pressing shift. We can make that the specific What would you say resolution sticks and insert the image here. We can actually say sprite. So we can simply take the clicker, put it in there, and they go. Now we actually have this as a nice little MAN that we can click. And once we click this, we should create a new clicker. Let's just see if that actually is everything that we need to do. But I'm actually fairly certain that we, that this is now build UI. And yeah, so let's try this out. So this should work already. So right now if I click this, we should get, I don't have enough cheese. As you can see, coupled with no cheese. Let's actually cheat ourselves ten cheese. And if I click this again, we should see the cheese gets subtracted. And then the clicker built the goal and it works. Well, that's pretty cool. That actually does work already. Now the way and that's, that's pretty cool. Like I said, we can add a few more things to this right now. So let's actually, let's actually move this up a bit and then add a few more text here. So the first text that we're going to actually, let's just copy the clicker. So once again, selecting this and control a D2, simply copy this. Let's make a like a big number here. This is going to be the number of clickers that we have. So this would be the, let's say numbers, number, building, shirt number building. Why not? Then this would be the I'm building name label. So always make sure that you have a proper name here. Because if you look at this maybe then a little later down the line, then you're going to say, what was that? This is the building image. That's the number building this 0. And let's make this a little bit bigger. So let's make this like a 100. Yeah, that's great. Like a 100 000, making sure that this doesn't vanish. And then we can also add a cost. So this would be, once again, copying this year, we're duplicating a to D. This would then be the cost. And let's just add 0 here as well. Let's actually 10. So that's the cost that we know. Yet. Let's keep it like this for now. This, like I said, it does, it doesn't look like crazy cool or, you know, we don't really have any labels on there yet. But this is going to be fine. Let's then in our sight of our assets folder, add a new folder called prefabs. Now we've already seen this because what we're gonna do now is we're going to make a prefab of this building panel here. So we're just going to quickly scooted over there the ego building panel. And the great thing about this is that we can now simply add this again here. So and we have this twice. This would by the way, be the clicker Building panel. And this is now the milking building panel. Let's move the milking panel down a bit and change the things that we need to change here. So the first thing that we want to change is that the image, of course. So this is going to be the cow. Now, since the clicker here, we're going to have the cow. I mean, that isn't that amazing. And instead of the name here, we're going to have the milking station. So this is a little bit big, so let's increase the size here a little bit. And the goal, the cost also is going to start at 25. And now we somehow, somehow that's the, that's the real point here. We need to change the individual things in there. And how do we do this? Well, we're going to do this with this building UI that we have already created, but not used yet. And this once again, like I said, is, might be a little bit more complicated. Let's first of all do UI here so that we have this inside of the right namespace. And yeah, let's just start and I will go I will explain as we go along. So first of all, we'll have a dictionary of building. We're actually need to. Using that namespace as well. So this is going to be, she's flickered out of buildings. And this is going to be a dictionary from building to GameObject. And this is going to be building Bill thing to basically while building to building panel. Let's call it like that. Yeah, that's fine. We will initialize this inside of the start method with a new dictionary. So that's very well easily done. And then let's think about this. So we have a dictionary now. We can basically a change. A few things here. Why would we need dictionary? Well, the idea being that we will have a particular building that is being a particular panel that's being clicked on and that is associated with the building. We can also have the association the other way around basically. In our case, I'm actually not a 100 percent sure of that we need this yet, but it's good to actually have this on here already. And let's see, int I is equal to 0. I is equal to transform.py child count. So we're actually going to count the children. And then what we're gonna do is we're going to see buildings panel, a panel add. And we're going to see buildings building dot instances. I is equal to the transform.py child of I dot GameObject. Now this might seem absolutely crazy what we're doing here. But the actual idea of what we're doing is we're, we're going through the number of children that this particular game object has, and then adding the instances. So this is simply a building from our building instances with the same, let's say index here, then the child index. So idea being that if we add this building UI to the actual buildings, they go to this actual buildings panel. And we can think, well, it's children is once again, the clicker building panel and the milking building panel. So those are the children, the child 0. This is child one. Okay. That actually I sort of understand hopefully. And these are then simply associated with the building inside of our building instances list. So yeah, and now if we go back here, this is simply save in this dictionary. And that's really all there is to it. And what we're gonna do in the beginning here is we're going to go through this one more time. So we're going to say 0, I is smaller than. And now we're gonna go through the building instances count here. Which should be, so in theory, this count and this count should always be the same because for each building we will always have a different panel. And for every panel, of course, we will have a building associated with it. And we can then basically actually then we might as well go through this through the spilling panel, right? So. We can get this. And then with the brackets can say, okay, let me get the instances I. So why is this such a crazy construct? Well, we need to give this the actual building that is associated with it. There's a dictionary. We have to give it a building. And then we will get back a specific aim object. So we will actually get back the game object, the panel itself, and this panel, we will have to get the component of a button, right? And then we're gonna do is we're going to say the button of course, requires Unity engine, using Unity engine that UI it. And this button, we will just simply say interactable is equal to false. Now why do we do this? I mean, first of all, all also, we can simply do it in this one as well. So it's not like we have to do it here. This is just an example of how you would then access the dictionary basically. But yeah, so why do we set the interactable equals false? Well, so that we can interact with the actual with the actual button. Because we should only be able to interact with this button. And when we actually have enough cheese in the bank, right? Because that would be smart. The we have the warning and that's fine as well. But wouldn't it be great if we could only interact with the button and only build the actual building if we would have enough cheese in the bank. And this is basically what we want to implement right here. So we will have a few things that we will actually want. So the first thing is we basically have the building built buildings, so on building built rather is going to be added four to a or a specific method is added to this event. And this is going to be the update number of buildings. So this is, we're going to implement this method shortly. And then another method that we want, which is up to the update host. So those two things are going to update it inside of the eye. These are already updated inside of the update cost especially is updated inside of the buildings itself already. But now we want to visually see it. And then we also have the cheese storage dot on she's changed. So if the cheese amount changes, then we might want to update the clickability click ability. I think that that's written correctly. I hope so. Right? So those are three of the methods that we wanted to add here. So the first one, number of buildings, we can just basically right-click quick actions and then just say Generate method here. There we go. Let's also generate this method, and let's generate this method. Last but not least. There you go. And we always have this with the correct method signature as well. Let me actually turn this around a little bit because I, in my reference, in my references, I have this a little bit differently. So let's start actually at the very top. Update number of buildings. Well, how in the world can we update the number of buildings? So this is exactly this what we have here, right? So we have this number building text field that we want to add or change depending on. Many buildings that are of a particular type. How is that going to work? Let's just be real. That's crazy. Well, it actually is not too bad. What we're going to do is we're going to go do a foreach loop. And this for each loop is going to go through the key value pair. This is exactly what is stored inside of a dictionary here of building and gameObject. So we want to go through the key value pairs. So key-value pair, we're just going to call it like that inside of our buildings to building panels. So we're gonna go through the dictionary by with a foreach loop. And then we're gonna say if the actual key value pair that we have here, right and the left key equals the building that we're passing in. Then we can do stuff. Now, when is this true? This is true. So we're basically going to go through each of the building. We're gonna go through each of the panels that we have right now. We only have two panels, right? So we don't have that many panels, but we have two panels. And we're going to say, okay, if the new building that has been built is equal to some panels. So let's say we build a new milking station, then it's going to be equal to this panel and this panel that will then be we will have access to this panel, exactly this. So we have access to this panel by doing key-value pair value. Because we now know, okay, the building that was built was the milking station. This is equal to the key. Therefore, bam, Let's go. And what we're going to say is transform.py child 0. So this is a lot actually get component type text dot text. And then we're going to say, are we actually going to need to, of course, evaluate this number? So what we're gonna say is we're going to have a new number here, integer number. This is basically exactly this, right? So whatever is written in it already, that we don't need to save it anywhere else. So like this, adopt texts, of course. I'm going to explain this as well. So in parse simply takes a, a string and converts it into an integer if that is an actual integer, right? So instead of this text here, what we want is we want this to be, we have a 0 saved and we also need to be careful about the actual Aya. Of course. We also need to be careful about the actual position of this. So we're going to change this instead of a prefab again. And say, okay, the number of the building is actually at the top. So this would be a child 0. Then the label name is going to be Child 1. So with index one, then we will have the cost. And then the image is going to be at the end. Now the image doesn't change. Maybe we want the image to change at some point, but right now the image won't change. The only things that are sort of changeable is the cost of the building and the number of the building. So we're going to change this. And then as you can see, it actually also changed it here because those two GameObjects are associated with this prefab. And once we change the prefab, we'll also change those to game objects. Okay, let's think about this. So now we basically get exactly this. The first game object there. And the texts there is the number of is the number of objects. Of is equal to the number of buildings that are sort of inexistence. And then we're just simply going to say, well, this number should be just plus equal one. So we want to save, so we just want to increase this number by one and then save that back to exactly this. Once again, there is another way that we can do this. For example, we could simply save inside of a building a variable how many buildings of a specific type there are. But we don't really need to. This also works. Calculating this on the fly works as well. Now this is already it, this should already work. And I believe that we should actually be able to see this already. If I'm not mistaken. Now, the thing is, we're still going to get a actually not implemented exception. So let's actually not do this. Let's first of all get the update cost method in here as well. So this is going to be very similar to this. So let's actually copy this over just for the sake of argument. This will still remain the same. So the if, the if statement here is the same. And then the only thing we're gonna do here is the key value pair dot value, transform, dot get child. So this of course, is basically hard-coding the position of particular things. Because now we have, if we look at this again, we have this at 012. So the cost we know is at position 2. Therefore, we need to get child to. This, like I said, is hard-coding this in this instance, there would be probably a little bit, you could make it a little bit better. But right now, the expandability here really is, it's not that big of a deal. I would get component. So we want once again at the texts component of the cost text. And we're going to set this to building.com dot toString. So we're just building that has been built. Remember the update cost method is called every time a building has been built via the on building a built on building built event. And this update cost then has the building as a parameter. And we're simply going to set the text to the actual cost of the building after it has been built. Now, what is interesting is that we actually have not called this on building built event yet. We actually need to do this still. And this is done inside of the cheese storage right here. So we've added the building here, but we have actually not hold this yet. And this, this is actually as easy as simply saying Building dot on building built. Question mark, invoke with new building. There you go. That's all that we need to do. And now that is also cold. So that's actually very, very nice. So yeah, this was the built UI that worked out perfectly well as well. There's one more things for the Build UI that we actually do need to change and that is inside of our milking a building Panel. Oh, no, no, no, no, no, Don't move that you crazy. They go, we need to change this 0 to a one. Because of course, the Milking station is at index one and node at index 0. So that's kind of important. But after we've done this, let's think about the rest of the building UI. We have done the following. If we have built a building, we're going to call the update number of buildings. That worked out fine. We will also update the cost. And now, last but not least, we want to basically update the clickability here. And that is also going to be fairly easy. Once again, we will go through with a forEach method here. And in this case, we actually don't want the if statement. We don't need that. We only wants two, basically get the value and then basically do exactly the same that we've done here, right? So this is basically what we want. We want to get the component of gameObject. We can do this by simply saying, Well, value dot get Component button because we want the button and we want to change the intractability well to true, but only under certain condition. Now we can think what is the condition? Well, basically, we want to see the building itself. So this would be key-value pair dot, ky, dot cost. Smaller or equal to cheese. Cheese storage dot instance dot cheese. This is, I actually, can we not access how much cheese we have? Is this a, this is indeed a sorry, Let's go to the cheese storage here for a moment. Let's actually, just for the sake of argument, make this public right now. There's an easier way to do this. Actually, no, let's not do this. Let's do this. And let's simply make a public integer cheese. This will get return, return cheese. And this doesn't have a set at this moment because we're actually don't need to have this as a set. We only want to access the cheese there. So let's do this. She's, there you go. And now this is all great and well, but as you can clearly see, let's first of all, actually test this out and then we'll refactor a little bit of the code because probably a lot of you will say, I mean, I key-value pair, I don't know what is going on here at all. I'm very confused. I can understand this. Let's first of all try this out. We'll refactor this and then I guarantee you it will get way more. What will you say? Clear? It will get clearer. There you go. Okay. I believe that everything should have been done out. Now this is always, you know, let's, let's just see if everything works. If this is actually doable and let's see. So first of all, looks fine. We cannot click either of those, so that's really good, that, that's a good sign. Now if we add a 10 cheese by clicking the plus, let's see if this gets clickable. Now, as you can see, it actually did. So the update clickability definitely worked. We had this glow up and if I hover over it, it gets a little bit darker. I can actually just quickly maximize this. It's barely noticeable. But now I should be able to click this and it will add a 1 here. Remove the 10 cheese, we will make this, gets to 20 and we will add cheese continuously. So let's see if that works. And everything worked. Isn't that great? So that's pretty cool. We have now added a new Clicker building. Basically, we've also adjusted the price. And once we hit 20 here, this will light up again and we should be able to buy the next clicker. Let's see if that is the case. And there it is. We can buy up by the next clicker. And the same should go for the milking station. So once we had 25, there you go. And if I click this, then this also changes the price. We also add one to this, and now we will get the five cheese every two seconds for that as well. Yeah. And just to make sure that this works, they go to and then 40 works out really well and verify. So that's pretty cool in terms of a UI. So this actually works already. Let's also disabled the maximize on play because I don't necessarily want that each time. And yeah, So it works. But like I've already said, some of you might say, Well, I mean, that's all fine and well, but I, I don't know what's going on here. Okay. And now this is sort of a, I would say, just prettify this. So to make this a little bit more readable, we're going to actually add a few local variables here. The idea being that, well, okay, So we have this key value pair key and what does that even mean? I don't know. Okay, let's think about this. This is a building. So we can actually, if you have all this, we can see this is a building because of course this is the key from the, from our dictionary. And we can then simply say, okay, let's make this a building. This is the building in sort of our saved here. So the building inside of the as a parameter, that's the building that's being built. Or because this is called, the method is called on a building built. So this is the building. We can actually change this name. So let's rename this first control, RR. This is building to be built, let's say. Then we know, okay, this is the building to be built. And this is sort of like a safe building. Or how can we call this the key here? Well, this basically is just the sort of the building that we used for lookup, right? So let's just call this building for lookup right now. It's not the clearest name, but I think that it's going to be fine. And this is equal to key value pair Schottky, right? And then instead of using this, we can actually use this variable here. And then building for lookup, it's like Okay, Okay, So the key is the building for lookup. I understand that, that makes sense. Now, what is this value? I don't understand what this value is, right? So not an issue. This is a game object. And we remember the dictionary is the building to building panel. So this is simply a Gilbane Building panels. So we can say GameObject building bill doing panel is equal to key value, key value pair, dot value. And now we can go even further because we can see, well, we only ever use the transformer. We can actually get the transform of this as well. So we can say Transform and say basically the building panel, building panel transform is then equal to the building panel dot transform. And then instead of only replacing this, we can actually replace the entire thing here with this transform here as well. And now we will see that, well, I mean, we both get the 0th child here, so we can actually replace this as well and then even go further. We're actually always getting the same texts component. So in theory, we can get this as well. And I say yes, why not? So we can actually say text and say, This is the building panel. This would be the building panel number of building text. So this is a very long variable name, but don't get too crazy about it. Why not have this? And this would be this one here. So we can actually save this in there and then replace this with this, and replace this with this. Right? And now, while we can say, well, I mean, you can also just string this together. Yeah, but if we look at this right now we can see, okay, key-value pair of dot value is the billing panel, okay, of course that's the building panel that we've done. And then we get the transform of it. Okay? Yeah. Okay, the transform, That's basically what you can say. Well, okay, maybe this can be deleted and we can say, well, actually building panel. I mean, I know that what the building panel is. So let's get this one. So this because the transform and the gameObject are very similar to each other. So you can say, Okay, the building penalty transform, I'm going to get that, that's totally fine. And then the thing is then I'm going to get the text associated with it. What type of text is it? The building panel number of buildings texts? Yeah, of course, this is this tells me how many buildings of a particular building has been built. And then we just parse the text of this, and then we read a re-save the number that was in there plus one into it. And this is basically a very easy way, let's say to change this up and be L2, read this a little bit better. So let's do this one and let's also change this to building, to be built. Right? And then low key, but only in equals. We have the building transform here as well, but we only need it once. So we don't actually need to get the text in this case. I think that this would be totally fine. And this makes way more sense. You can, of course, also by the way, do the same with, for example, this cost here, right? So you can say, well, I mean, actually, when we think about this, what is this building to be built cost? What is this? This is actually the new cost that we want to have it. So we can just say new costs and we can actually immediately put this in a string. That's even better, new cost No.2 string. And then we can think about it and put it in here. So then it gets even easier to read. And we say new cost is equal to the actual building that's being built cost because that's already been updated for us. And then we know our case. We just take the actual texts, they are an updated with the new cost. Therefore, update cost makes sense. Update clickability, very similar to this. In this case, we can actually just get the building here. Actually we only the building we need the. A GameObject in this case. So we actually want to change this up a bit. So this is the game object, this is the building panel. And then at the end, instead of writing gameObject, we can also just GO and then say dot value. And then this one will put here. So the building panel gameObject dot get Component button intractability. We can also get the button immediately. I think this is fine for now. And then this whole ordeal here, we should definitely make a Boolean out of this one. So this is the Bool into trouble in terror act. Able they go. And then we can just put this in here. And, and this way. And then the great thing is that we can also just do take the building here, put this here, building for lookup, and then we can change this building for login dot cost. And then say interactable right here, the ego. And now it's way easier to read. I wanted to basically show you this as sort of a like a real example of how you can change the script or change the code, refactor the code. So it's a little bit easier to read. And now this is way easier to read because of course, key value pair, key. What is that? You have to remind yourself again, no, just put it into a variable, name it properly. And bam, you could, you should be able to read this easier than before. But it's still going to work, of course. Well, let's hope that it's still going to work. Let's just try it out for just a second time here. So first of that works right? If I add my cheese here, this works. If I add the clicker that does work, it's still updates. And once the 25 is hit, the milking station updates and this updates as well. Well, isn't that great? It's a works. We still get our cheese and we have added a very basic UI. Now was quite an ordeal. And there was a few things that we did here where this might be, wow, that's quite a bit of work, but yeah, that's what it is. So even simple games, they do require a bit of work and a lot of thinking about stuff, a lot of thinking about systems. But we have persevered through and now everything works and the game is coming to, well, it's coming along very well, right? So we have a nice UI that we can use. We can click it, we can get more and more cheese. As you can very clearly see it works very well. And let's see how they would go. And then it gets activated again. So that would be actually it for adding the, let's say basic UI for V cheese clicker. Overall. Once again, because those lectures are a bit more complicated and complex, you might want to look this up a few times. So you might want to look through this lecture another time, or you might want to get the source code and look through that as well. I will say for now though, this would be it if even after re-watching it and looking at a few parts, if you don't understand something, please do feel free to ask the search respond. And yeah. 70. (Cheese Clicker) Creating Upgrades: All right, let's continue with the cheese clicker here for the unity course. And in this lecture we're going to create a very, let's say, easy upgrade system that you can implement. Once again, taking inspiration from Cookie Clicker, where you can also get certain upgrades that are applied to specific buildings. And we're going to see if we can create something there. So first of all, let's create a new folder inside of our scripts folder called upgrades. And in there we will have the beautifully named upgrade script. So the folder being plural and the actual class being only singular. Now this will not be inheriting from moral behavior and it is going to be inside of upgrades. Well, without the semicolon Diego. And there's a bunch of things that we will need to add here. So let's go. So first of all, I've already sort of prepared a few ideas of an upgrade types that we're going to have and these are going to be saved in sight of An enum upgrade type. And those will be the bronze clicker. Will have the silver clicker. We have the gold clicker, the platinum, platinum Flickr, as well as the bronze milk. Of course, you could have guessed the silver milk. And if you know the other ones, you will get a cookie or other piece of cheese, platinum milk. There you go. Those are all of the upgrades types. We're going to make a very similar construction that we have done with the buildings. So where we have a private static list of type upgrade inside of here, which is going to be all upgrades. And then we will have this inside of a static property, which is also a list of upgrade called all upgrades, upgrades. And we will have a getter here that is going to do return all upgrades. And if that's not the case, then what we want is we want to generate those. So we're going to have another public static list of upgrade. Generate all upgrades, upgrades they ago. And this is then exactly the public is not written correctly. They go public static, generate all updates. And this is basically exactly the same that we've done with the list of buildings inside of the building class. So this is the result equals new list of buildings. Let's return this result. Go. And then we'll fill this soon enough. First of all, let's do the check here. So if the actual static variable is equal to null, then we, first of all have to set it with exactly the all upgrades method. Right? This is like I said, some of them we've already done it for the buildings themselves. So this shouldn't come as too crazy of a surprise. Now the big question comes, well, what type of things are inside of a lab grade? What is what is the what are the properties of an upgrade? Well, first of all, obviously we're going to have an upgrade type, right? And this is going to be a type of upgrade with a getter and a private set. Just why not? Then we also will have a public modifier. This is the modifier, modifier, the 0. This is the modifier that we're going to times were to multiply with the actual cheese gain that we will have. So this is the modifier of B, will have an that. Then we also of course have a cost associated with it. Private set here. And then one other thing, and that would be a public bool and that is called is a bot. So this simply checks whether or not this particular it has been bought as the upgrades that we will be creating here will only be able to be bought ones and then they are gone. And then for these things, of course, we also need a, we need to generate a very nice constructor. We can do this, of course, pressing Control dot control point. It's Control dots of course Generate, Constructor and type of. Those are exactly all of the things I want in here. And there's also one more thing that we want. Actually, I completely forgot about that. Wow, that's embarrassing. We need to know for what a building this is. So we actually wanted to start using the cheese clicker dot buildings namespace. And then we want a building hold for building. And this has a get and a private set again. And this is then in here as well. So building. And then for building, right? And we don't want is bought by the way, because that is something that is always false in the beginning. And then for building, it's going to be for building, for building, building. Okay. What is this? What is the thought process behind it? Well, of course, an upgrade is always specific for a specific to a type of building. This is why this has a building reference here. And the is bought simply says, okay, it's false in the beginning. And then once we buy it, so once the public void by method is cooled, and we're going to say is bought is equal to false. Rather true. Sorry, there you go. Of course, there you go. So once we buy this, this is bought. And with this board we basically check, okay, can we sort of we bought what we just wanted to have this Soviet we know, okay, this upgrade has been bought and this upward has not been bought. And in the future, for example, we could say, Hey, all bought upgrades and then easily filter for is bought in that, that would be one of the Of things that we can do. But now we can actually create those upgrades inside of this list here. Now what I will do is I will actually copy over. I actually will create one new upgrade here, and then I will copy over the rest of them because they are a little bit more complicated than the buildings. So we have results dot add, and then a new upgrade. And now instead of this upgrade, we first of all need an upgrade type bronze Clicker. Then we want the modifier, in this case, the motor Fire for example. Actually let's turn this over. So let's first of all get the cost and then the modifier, otherwise, the copying will not work. The cost, let's say the bronze costs 25 and it will actually double the things that we are going to get from the actual clicking. And then for what building? Well, we can get the buildings once again by doing building, a building instances. And then a 0 here. Because this of course works because this once again is the clicker and this is specifically for the clicker. And now we can actually just copy. This is actually fairly easy as well. And say silver clicker. This one then costs, let's say 500. So that's a way more of a cost. And then it also doubles the, it doubles the cheese gain. And then we have the gold clicker. This one costs 1000, 500. Those are, of course, arbitrary numbers, right? You can choose your own and change them as well. And this is going to be the platinum clicker with 5000 and this is going to times for it. Now, those are of course, multiplicative. So if I have the bronze and the silver clicker, we're going to get four times as many, as much cheese out of it. And then if I have this, then we're going to look at eight times and then we'll get 32 times if I have all of the upgrades. So those scale very fast actually. Now, the other ones I will actually get and we will do this in a different way. So, and we actually, as you can see, Collection is initialization. There you go, can be simplified. And we're just going to click this and we're going to see that this looks a little bit different than we've seen it before, but overall it shouldn't be too crazy. So we basically just have the in sort of an inline initialization here. Instead of adding those with the add method, we can just have this here. And then it makes my job a little bit easier by simply copying this over here. This is building instances. The copy didn't quite work. There you go. That's what it is, right? So once again, you can of course, choose your own upgrade to costs and modifiers here. In our case also the modifier would be an integer. Because we started with an interview. Of course, both can make it a float and then basically just have the result later. Either seal it or make it or florid, right? So that you can round it up or down. But right now I think that this is fine as an example, let's say. And the last thing, There's two last things that we want. Well, one of the things that we want is. And basically we want a static method that enables us to basically get the relevant modifiers. So this is the relevant modifier. And this is for a particular building in this case. So what did we, what did we want here? Well, basically, first of all, let's do modifier equals 1 and then return modifier. So the idea is that given a particular building, we wanted the modifier that is associated with it. So if we have the Bronze click on the silver Clicker, then if we give this method at the clicker building, then what we want to get back is basically the modifier that we need to apply to this in that case then for, so, for that we're going to make a new for-loop that goes through all upgrades, dot count. And once it goes through all of the optic up grades, what we're gonna do is we're going to ask, okay, if the actual upgrade that we're looking for right now, I actually couldn't shouldn't be. Yeah, let's do a foreach loop actually that is a little bit better. So this would be upgrade. Cooled, nonzero, sorry. Nope, still not right. Upgrade. Okay. Let's do that like this. Upgrade, upgrade in all upgrades Will operates the ego. I what we're going to say is if the upgrade is for building, so if we get the building and then we're going to, what we're gonna do is we're going to use the get type method. This simply, you can basically get, take the get's type method called equals on this and then say building dot gets type as well. And this then compares the type of type, the class actually so with this wood, so there's a system dot type, as you can see, which is the return type. And that simply a comparison of the class or the datatype, so to speak. So it compares whether or not this building that was being given is, for example, the clicker. And if those match, end, the upgrade is bought. So that's also kind of important. So that's where we asked whether or not spot. Then what we're gonna do is modify our times equals upgrade dot modifier. There you go. So then we will actually be able to multiply the modifier to it. Yeah, overall, I mean, this shouldn't be too crazy. We're just looking for the particular building. If the upgrades there have been bought and if they have been bought for this building, then we will simply add or not add this to the modifier, but multiply it to the modifier, right? And to also add this, so that this actually gets some working. We need to change the clicker and the milking station here. And this will actually not be too crazy. We actually just simply make a total she's gained here, and this is going to be the cheese gain that we have. So the sheepskin of the milking station, this case times. And then let's do using. Flickr dot upgrades, we need to be using that namespace. Then inside of here we can see upgraded taught, get relevant modifier for this. And this is why I like creative that method, because that makes it very easy to do this. And then we can just say total Cheese gain. And we can copy this over, put this in here, and then also say total Cheese gain. They go. And also making sure that we are using the correct namespace appeared. She's clicker dot upgrades. Right now the cashflow itself should work already. So modifying the cash-flow by the upgrades here should work totally fine. The only issue is that we can't buy the upgrades yet and we're for that we're going to make a new upgrade. You I actually now Let's do this. Just for the hell of it. So I hear you. I so this is the upgrade UI. I'm going to make this a little bit differently. I know that was a little bit too quick. Now he's going to open another visual Studio Instance. Just a second. A go. Let's close this again. Thank you. Then open this in the correct one, please. There you go. This is of course, under your eye and we'll definitely be using the cheese clicker dot upgrades namespace. Let me just quickly take a look here. So first thing that we're going to need is a public list of Sprite. So now we're going to actually have a sprites associated with it. Those of course, are available as a resource and we're going to see those shortly. Then we're going to have a dictionary similar to the buildings. We're going to have an upgrade to game object dictionary here. And we're also going to call it like this, upgrade to a two game object. Object. They go with a getter and a private sector. And then last but not least, we will have a public object which is going to be the upgrade UI prefab. But we will not have this with an underscore year, just like this. Okay, First of all, the upgrade game objects dictionary will be initialized here in the start method. And then we will have a. So what we're gonna do is before inside of the buildings panel, we actually added the particular penalty ourselves, so manually. And we're now going to basically have the particular ones generated this time. So we're gonna say panel, and we'll just add a little panel down here. And we're basically just going to generate those. So let's this would be the upgrade panel. Upgrade panel. There you go. Let's add the upgrade UI to it. And then let's also add the sprites. So let's do instead of our sprites a new folder. This will be the upgrades. Let's also make a new folder called building buildings, and simply add up all of our sprites to them. And inside of the upgrades, we're going to add all of the Golden things. Like I said, all of those are available as a resource. We copy those over and let me just quickly check, right? You actually don't need to change anything for them. As you can see, Bronx slip or wrong smelt machine, Flickr, that machine. Platinum and the silver as well. Yeah. So once again, those are of course, available as a resource. And then let's see, upgrade panel. So basically, we don't really want to create anything crazy year. And with creating, I'm really mean like we're going to create this. So the update UI itself shouldn't be too crazy. We would have to create this one. So we have the prefab and then we can basically put the prefab in there. So this is simply going to be an image of this one. So this is an image. Let's make this a little bit smaller. That's probably going to be fine. And then this image is going to be the upgrade UI. And this will also have a button associated with it. So this is going to be a button here. And I believe that that is already it basically. And then we simply need to change stuff on it. So the upgrade your islets, put this inside of the prefab here. So as a prefab, now, it is here. And we can then basically deleted and make sure that the upgrade UI prefab here is set inside of the script. And then I believe that this should be all of it. Then we simply need to create it by making a new method, private void create, upgrade UIs with a particular index here. Let's see. There you go. Because we want to call this method inside of a for loop. So basically gonna go through all of the particular upgrades that we have. Actually all of the upgrades in sort of the weekend actually already do this. So for loop with i and then this is upgrade, upgrades, dot count. So we're gonna go through all of the updates, upgrades, or hit up its diagonal. And we're going to say Create up, grade your eyes. I go. And inside of here we're going to create this. So game object 30, or let's say upgrade term is equal to instantiate these UI prefab with the help of this transform here. I'm going to say the upgrade is going to be. So first of all, get component image. We need the UI package here, of course. So using Unity engine wi, that would be very good. And then the image, we've not really seen this like I said before, but this is going to be fine. So the sprite here can be set up just like with the, basically the sprite sprite renderer. And then this would be the index. So we're just gonna get the sprite at a particular index here. And then we're going to do something that we've not seen before. And we're going to basically change what happens when we press the button. So before we've seen is we've just added the. A button functionality by if we look at this, if we look at this, There's also has a button. We added the onclick and we had the particular thing in here and cold a particular method or function there. But what we're gonna do now is we're actually going to do this via code. And to do this we're going to get the button component here. So button onclick. So this is exactly what we had there and movement of coal add listener. And so this ad listener, we need to add a new lambda expression. So this simply if I hover over this, as you can see, this is a unity action call. And we can do this as a lambda expression. So everything I put after this is basically what gets then. So upgrade all upgrades index dot by. So I want to call the method here for this particular update, one when this is clicked. And what I also want to do is I want to set the actual game object itself. So the upgrade is the game object set active to false so that it basically vanishes. And then last but not least, I want to upgrade to GameObject the dictionary. I want to add the actual upgrades to it. So first of all, I mean, yeah, that's fine. I mean, that's not too bad. All upgrades. Index here. Index. Oh, no, that's not quite right. Index a go. And then also the game object, which is called Upgrade. There you go. Right? That would be the creation of the UI. Now there's one thing that is a little, well, I wouldn't say an issue, but it's going to create all of the y's on top of each other, which of course isn't quite what we want. What we would want is of course e, have them sort of separated a little bit. So let's just try this out. Let me see that this should actually work already and at least generate those. Of course, we need to set the sprites here, and we need to set them in the correct order. So this is the bronze clicker. Let's do this. Clicker. And then the silver clicker. I believe that now this certainly doesn't work very well. So let's do it like say you go silver clicker, and then we have the gold clicker and then we have the platinum clicker. Yes, there you go. And then of course, the bronze medal machine, silver machine. We have the golden milk machine and then last but not least, platinum. There you go. So these of course need to be set as well. And then I believe that should at least generate the actual game objects. Let's see if that works already. It does create the game objects. Now as you can see, they are all at the same position. If we go into scene as you can see, we're on the same position. You would need to separate them sort of like this. That of course doesn't quite work out. This isn't quite what we want. But yeah, how does that work? So how can we do that? Well, we can, for example, say, well, let's do upgrade dot, transform dot position. And then basically just equal. Well, we can also just say plus equals new vector three. Let's say someone like Arnold, 15 F 0. Well, that also works. 0. There you go. Something like that. Let's see how that one looks, whether or not this would change it. But it's better to take the local position. Because of course we are currently under New transform. Let's see if that actually works. That will of course move everything in this case, because we need to times this by the index. So index times this. And this definitely needs to be a little bit more. So let's say something like 25. Now why, What is this? What are we doing? Well, basically depending on the index. So of course for the first upgrade we're going to have an index 0. So this is going to be at, the position itself is going to be at 000 000. And then the next term upgrade, the position is going to be at 25 000 and then index two is going to be 50 000, 000 and so on and so forth. Now this is definitely going to be off the, off this upper-right panel. We're going to basically okay, It's actually needs even a little bit more, but that's fine. We can basically try this out a little bit and find a number that works here. We have to do this, Let's say in such a little bit complicated manner because we've not yet seen how we can have the layout of a UI generate itself. This is something that we're going to see when we take a look at the actual, what we say at you a little bit in more depth. Right now. I think that this is going to be fine. It doesn't look the best, but it is functional in this moment. One more thing that we need to do in the upgrade UI here, we actually want this highlighted color to be a little bit more noticeable. So let's, let's actually add this here. Note that we don't need to add the server, that's fine. Let's just do normal colors, completely white. And then this highlighted color a little bit darker. And the rest of thing is going to be fine. Let's see if that adds a little bit more of an effect. Yeah, now we can actually see if we hover over those, what works. And then if I click on them, they actually should work already. Now. We can click them whenever, but it should work. So let's actually try this. So let's just get ourselves ten cheese at the clicker. And now of course, this is going to increase by one every second. And if I get the bronze Clicker, then this should now increase by two. And as you can see, it works perfectly. If I click this now it should increase by four and it does. No worries. And now I can, of course get the other clickers as well. And I was going to increase by 32, I believe it was every second. So that's pretty crazy. So as you can see, working really, really well. Now of course, what we still need is basically the check whether or not this can actually be bought. So the upgrade can still be bought. For that. Of course, the only thing that we really need to do is we were first of all, we want to set all of the each of those intact abilities to well, not being intractable. So we can just do Get Component button. At the third time here, we could almost think about taking this and making a variable out of it. At this moment, not going to do it because it's not. Necessary, but this would be something that would probably make sense. So we're just going to set the button to not being intractable. And then inside of here, we're going to say once again, when the cheese changed on cheats changed is going to be update, update, click mobility. And this is going to do exactly the same thing that we did in the, let's implement this generate method. Put this at the bottom here. The same thing that we did with the building UI on the Update clickability. So we're simply going to go through them quickly, going to copy this over because we've seen this basically already. We're just going to go through the key value pairs in the game objects here. And if this is interactable, then we will interact with it. If, if the interactable, if the cost is smaller or equal to the new amount of cheese that is available. And now this actually should work as well. Let's do the Buchla. We should actually be able to see this immediately. Yeah, now the color is disabled as you can see. And once I have my ten cheeses, actually I need to 25, I believe, for the first upgrade, then it turns red or it, you know, it turns normal so that we can actually click it. And once we click it, it is gone and now the clicker is here. But as you can see, it actually did not remove or cheese. Well, that is of course not what we wanted. We wanted to remove our cheese. So what we can do is we can either add it in here or we could add it inside of the Upgrade button. This will probably make the most sense. So we can say cheese storage, dot instance, dot, remove trees. And this would be this dot cost. And that is already it that we, all we really need to do because the bind method is being called anyway when we buy the upgrade and then cheese will get subtracted from that. Removed rather, yes. So let's, you know, or you can also just do the plus here, call this, and then the 25 trees is been removed. The upgrade, as you can see, the UI here has been set to activate basically because the upward has been bought, it's done. And yeah, that is basically how to add the upgrades. Overall, the game itself doesn't look too great, and there's a few more things, of course, that could be ironed out. But I believe that this is sort of what I would leave you with at this point. There is one more thing. There's the barrels, of course, which you could add. This is sort of a suggested exercise that I have as well where you add a few more of your own buildings and if you more of your own upgrades basically. But this is sort of the state I would leave you with this particular game. It can be played in its entirety. And maybe what we're gonna do is when we look at the UI, we might want to change a few things here. So we're probably going to take another look at both the upgrade and the buildings panel just so that those are ordered correctly. So at the end of the UI section of this course, but right now I would say that this is sort of it for the xi's clicker. I hope the entire building process was useful to you. I know that at some points it was it was a lot. So it's not like that's something that you may be able to digester immediately in its entirety. Especially if you're completely new to the Unity programming, then this is probably, you know, it was quite a bit. But rest assured what I would say is that best thing to do, you know, play around with what you have here. I would say that this is a great opportunity for you to just add a few buildings. Do some stuff that you wanna do. Think about, maybe some, some ideas that you, what you want to add. Maybe what you want to do is you're gonna add some more visuals to it. So if you add, you get clickers, then maybe actual like mouses appear. And if you have, if you click the milking station, maybe you want the sound to play or something like that. So there's so many things that you might be able to add here. And I want you to use this project basically as a very good introduction as sort of a, it is the sort of play, right? So you have a great foundation. I think that you can expand upon. And that's sort of what the idea of the cheese clicker really is. So this entire project basically. But yeah, that was it for this lecture and the cheese clicker itself, like I said, we're definitely going to return to this once more after we've made it through the UI and then we're going to make this a little bit. I wouldn't say prettier, but make it a little bit easier to basically sort the UI itself. But that would be it for this. And like always, I hope you found it useful. And if there are any questions, then feel free to ask and I'll be sure to respond. And yeah. 71. (Unity UI) Adding a Canvas: All right, Welcome to the Unity you, I introduction here for the unity course. And in this lecture, we're going to take a look at canvases or the Canvas game object, let's say. And first of all, of course, in a new project, as always, we're going to create our good old scripts folder. And then let's immediately put in a new folder, L1. Can this, let's just call it Canvas. That's fine. And there, Let's immediately do the script as well. Now the script is not going to be actually that interesting in this case, because usually this is just something I have personally seen. You don't really change canvases all that much. At least I don't really change a lot of things on Canvas via scripts. But I've prepared something here where we have a few comments later down the line after we're done with this. So the update method is not needed. And we're going to look into this soon enough. But right now what we're going to do is we're going to actually add a canvas to the scene. So let's, first of all, let's, let's rename this scene to L1 Canvas can this, and then reload this. So now we're at L1 Canvas and right-clicking UI and then adding a canvas down here. Now, we've seen a little bit of this already when we added the text in the very simple UI, look, let's say they are. We added the text and the Canvas was generated automatically. So that was something that was interesting. But now let's actually look at the Canvas canvas components here. What do we have? So first of all, we have the random mode. And there are three random modes available. Now. Previously we have actually put it to screen space camera. But what is screen space overlay? Well, of course the default that it starts with. And the idea is that you could put like head-up displays here. And this being an overlay mode basically. So we can zoom out a bit. As you can see, this is giant, right? So this is a giant canvas in this moment because it is exactly the size here. And just so that we have anything to look at, we can just add a text here, just otherwise we don't even see anything. Let's make like a giant text here in the middle so that at least we have something on the canvas that we might see. Now, as you can see here, the texts actually displays right layer in the middle of the camera. In this case, because the overlay is exactly that. It is an overlay onto the screen basically. That's why, you know, so swings like the heads up displays. Maybe when you played Minecraft, know the Tao, the little bar at the bottom, something like that, right? So head-up displays that you might use for showing some things, That's where the screens based overlay might work. The screen space camera, as soon as we're putting that in and shows choosing the main camera here. As I see, it gets very, very small. Also, what's very important in when you are in screen space overlay, you can't. Change the direct transform here so you can't resize the canvas itself. Here. However, here you also can write, so some things are done by the canvas. This is because of the scaling factor, which we're going to look at in a little while. And so right now nothing really has changed. As you can see, the idea of the overlays that this would work for every camera. And this one would only work for a particular camera that you are. Basically putting in here. Also the overlay, overlays over everything and the screen space camera. You can actually look this up. There you go. You can actually put the plane distance in there and also have an ordering layer there as well. So right. So those are all basically rendered at a certain distance to the camera. This personally is a preference of mine. I usually almost always use the screen space camera. There's also a world space and it will space, as you can see, we can now actually change the direct here. And if we go into the Canvas and we move it around, and you're going to see that, okay, the canvas is there. But if I now actually move the camera to the right, as you can see that Texas now sort of in world space. So now if we have this world space, then the actual canvas is a GameObject that is part of a world. You could, for example, imagine if you have enemies walking around and have like health bars or a name bar above their head. That would, for example, work with this world space random node. Right? Let's go back to the screen space here just for the sake of argument right now. And yeah, the rest should be almost self-explanatory. So the plane distance is just the distance of the, basically the y position. So this would once again take into account the clipping plane of the main camera, which we've already seen. But so if someone is nearer than 0.03.3, then it will not get rendered. So this is exactly this one. And the plane distance here, a 100 would be fine. In order in layer works with the sprite renderer as well. So if this is below a certain sprite renderer than a component of another game object, then it would be above that. If it's below this, then no, it would be below this. So this works exactly like that as well. You can also put in here additional trader channels. I have not really played around with this too much. And so right now, I wouldn't worry about it. The scaling, however, that's actually, there's one more thing, this pixel perfect. I almost forgot. That's actually kind of important. The pixel-perfect is, as you can see, it is available in both the screen spaces, but not in the world space, random mode. And the pixel-perfect is basically had the idea that the Canvas will align with the pixels perfectly. That's why it's pixel perfect. And if you enable this, basically can make certain elements sharper and prevent blurriness in the elements. However, what's really important is if you have sort of animation inside of your canvas. And Your elements, basically the UI elements, then it might be better if you disable it because it can be smooth or without it. Because if it has to align with the pixel perfectly, then the movement can sometimes be a little wonky. But usually that's fine. Yeah, that's that would be it for the canvas itself. Then comes the canvas scaler, which is really the bread and butter here. So the UI scaling mode, there are three of them as well, constant pixel size, we have scale with screen size and constant physical size. So why do we need to worry about the scaling of anything? Well, let's see this. So we have the game window here right now, right? If we, for example, were to take this out and if I can actually manage to, yeah, now I have this independently, so I can scale this right? And as you can see, well, that's all fine and well, the actual text stays there no matter what I do. So that's actually not too bad already. But what this has is this has a constant pixel size, so this will stay like this. And because the resolution here is this high, that's not an issue. But if we say let's go to three aspect. Now, this is our actual Let me see. Let's go. Yeah, low resolution. So as you can see now, well, it's the same pixel size, whatever the aspect is. So if we are at, Let's do no, no more low. So 1609 and 1610, well, it works a little bit better, but not really. So as you can see, depending on the size now, because now the aspect has to be the same. The actual texts, there is not really scaling very well to whatever we have. So if we have a phone display, I mean, then everything just, it doesn't work. So constant pixel size can be used, right? However, like I said, the UI elements that are below on this canvas basically maintain their pixel size regardless of what the screen does. It's so they won't basically they won't scale. The scale with screen size is very interesting. And they are, they basically scale with a certain reference resolution. So usually if you have one, 1920 by 1080 for example. And then all of a sudden, this one is very interesting because the aspect is always 16 to nine. But as you can, of course see, there you go. Now it actually scales with it. Now only after it has actually taken this. So you can see that this already works fairly well. You can also look at what it is supposed to match. So either the width or the height. You can also put it at 0.5 and then it's going to basically make it so that both matches the width and the height same. There. You can also put an expand and also put in shrink here if you want to. I usually keep it at, if I can get this to work, there you go. I usually keep it at 0.5 match with the screen match mode of width or height. Reference pixels is. Let's see if we can actually get either ego is a sprite, has the pixels per unit setting than one pixel in the sprite, we'll cover one unit in the UI. So that's actually should be very much self-explanatory. If you remember, we've looked at the sprites and there we were able to set basically the Our pixels per unit for some of our sprites. And the last one is constant physical size. So this means that it will actually look at centimeters, millimeters, inches points, or pick us on site on the screen. This means that it will take the original physical size. So you could literally take out a ruler, put it on your screen, and this is always going to take the same size. Now in their items won't really scale as well. But if you want, for example, something to be exactly like one inch by one inch, sort of on a mobile screen or even on a, on a PC screen, then this would be the mode you would need to choose. I personally think scale with screen size is the one that makes the most sense. It does still some funkiness, especially if we get into different aspects, right? Because right now we've taken an aspect 1920 by 1080, which would be 16 to nine. And if we were to go to 16 to 10, well, that would still work sort of. But if it's like crazy or aspects like if we have a free aspect here, then at some point, this is definitely going to fail, as you can see. So if we have like a more or less a smartphone, then, you know, it doesn't quite work if, you know, depending on what type of smartphone it might be. But yeah, overall, it's still basically the canvas scaler there. And let me put the game window back and put it back to, let's say 16 by 9 aspect. That's fine, right? So those are some of the things that we can do here. The best thing, you know, usually you also get good tooltips here as well. So that's actually also very nice. And I also have this once again, if I just open the actual script, I would definitely highly advise you to look at the script that is already been done. So that's provided in the, in the exported Package because this will have basically all of this inside of it as well. And then of course, we also needed the Canvas up here, the go. So just a few little tricks and tips and tricks basically. So there's a few things in here just so that you understand each of those things. We, of course, also still need to be using the Unity engine dot UI. There you go. And then the canvas scaler can also be accessible. Last thing, or multiple canvases. So there's a little bit of a debate going around basically. Okay. Is it better if you have multiple canvases or is it better if you have many? One canvas and everything is on there? Well, it depends, and this is the thing. So you can think about it like this. If an element changes, then the entire canvas has to be redrawn. So if I have like 1000 texts on this canvas and they change like every second, it doesn't matter, even if I have 1000 pictures in the change, they don't change. They still have to be redrawn. Therefore, it makes sense. You have multiple Canvases. I've taken it here. Therefore, it makes sense to split up dynamic and static elements onto different canvases. So if you have a UI that basically never changes, then you can put that on one Canvas. And then the UI where maybe you want to display your health or some sort of systems, then that would be something you would put on a canvas that does not change. So splitting up the dynamic and static UI elements, right? But that would already be it for this lecture. There's nothing really to, else to see. We can also just add this script to the canvas here. But there's no real point in trying this out. Just basically puts everything onto each of the possible modes here, just so that you can see that you could, for example, put this or change this via script. I personally have never done this really. It's always a thing that you basically put the canvas into whatever configuration you want to and then you leave it alone. But yeah, maybe your mileage may vary. So who knows? But that would already be it for the Canvas lecture. I hope you've found this useful and you learn something new. Like always. If there are any questions, feel free to ask. I'll be sure to respond. And yeah. 72. (Unity UI) Panels and Text: All right, let's continue with the Unity UI introduction here for the unity course. And in this lecture we're going to take a look at panels and text. So what we've already seen in terms of texts was a, you know, adding the text and then changing it via script. And the panels we have added what we've not really talked about those. So let's take a look at that. First of all, we're not going to create a new scene, but we're going to duplicate this Control D while selecting it. And then we can do L2 panels text. Sure, why not. And then also double-click to basically open it. And instead of the scripts folder, we are going make a new folder, L2 panels text inside of that as well. Of course, a new script. We're also going to call this panel's text, right? And then let's actually open this as well. And let's close the canvas example script. We don't need that anymore. We won't need the update method once again. And inside of here we can actually already started using the Unity engine wi namespace, because that's the namespace that we're definitely going to need because we will use the text example. Let's do example text. That's fine. And then we're going to see how this works in a little while. But first, let's go back to our canvas here. Let's just delete this text. Why not? And then let's add a new UI element. And that is going to be a panel down here. So a panel is basically just a backdrop with a certain background image here. And some certain, some specific already, you know, filled out values for certain variables here that So the color is already put an at only a 100 in terms of opacity. So there's a few things that are put in here. And it's basically should act as sort of a backdrop, right? So if I want to say I want to have like a UI down here, then I could put it here. And then as you can see now I have sort of a visual marker here, a background. And that's basically what the panels are used for because now if I add a new element, the new UI element to work to the panel itself, then it gets added as a child to the panel. And as you can see now, it is basically I wouldn't say that it's dependent on the panel. I can also put it out there, but that's sort of a good way of how you should structure your general UI. You should have a few panels and then basically have their children always on top of them. Right? What we can do is we can do a few cool things low. And that would be the following. So what I want to show you is that now we've put it down here. And with all of the previous scaling and all of that. Well, what might happen is that this will scale with it. So that's pretty cool. If we have that free aspect. Now it's gone, I guess. Well, that's not that's not the best thing. If I can get the game window outside of here, then what we're going to see is that, you know, it sort of works, but it also sort of doesn't work like always. So that's a little weird, right? So with the texts that worked fairly well, but now if we have a free aspect, that's going to be a little beer, and that's where the Rect Transform comes in. I just want to quickly show this. There's a lot of things that we can basically put in here. But as you can see, this is absolutely maddening. Read this looks crazy. And I agree with you because we can also hold Shift and hold Alt to basically have two different things. So we can shift also sets the pivot and ought also sets the positioning. So we can basically make it so that it is anchored to a certain point. Now in our case, what we would want is we would want this to be anchored to the bottom right? Because to the bottom point sort of gets to be the, what would you say? It gets to be the, the anchor and also the reference point, right? So, so this becomes a reference point. So if I were to set, for example, this as well as the pivot to the bottom, right. So nothing right now has changed. You're going to be like them, okay, that nothing has changed. But if I were to now take this game window once again outside, now as you can see, even if I rescale this, it's going to stay at the bottom of the screen. And that's sort of also one of the things. And it's going to scale with the actual screen. So that's one of the ways that you can also facilitated the correct placement of your UI elements. At this doesn't have to be panels, can also be texts and all of the other things. And of course, if I now were to, for example, if I hold Alt, then the position will also be set. And if I put the position at, for example, the top-left, as you can see now it gets put at the top left of its first parent. So it doesn't get, the text itself, doesn't get put to the top-left of the canvas, but to the top-left of the panel. So that's also very important to note about these anchors. I wouldn't say that we're going to look at that too much longer. Overall. They can be a little daunting because this could be like, Oh my God, I don't even know what's going on here. Totally understandable. But I wouldn't worry about it too much. And for now, I just wanted to mention that you can basically anchor the game object to a specific part of the screen basically. Well, let's continue with the rest of the panel will, this is basically an image as you can see. So this has simply an image component. Particular backgrounds. So this is the background, the panel background, and it has a predefined color. And then all of the other things that an image also has. So that's basically what the panel is and the text which we've already seen. There are a lot of things that should be familiar to you if you've used a word processing program like Word for example, or I don't know, like Google Docs. You can set a font. You can change the font style, the size, even the line spacing can be changed. So let's make this a little bit bigger. For example, the line spacing can be changed, which of course doesn't do anything because we only have one line at this point. We have an alignment for the text itself. We can also say best-fit. Then it's going to basically resize the font size to whatever we want it to be. We can specify a minimum and a maximum size. We can also change the color of the actual text. Now, this, of course, also can all be changed via a script. So let's just put the panels text onto the actual game object itself. And let's open it. And just for the sake of argument, let's say example text is equal to this dot get component text. So there the component method is once again use the example text dot txt. So this is 1 second I just the changing the text via a script which we've already seen before, where we change the text from 100 to 300. And of course what we can also change the color. And then here we could, for example, say random dot color HSV, and then have this be actually, let's just put in the update method here as well. If input schottky down keycode dot c. And then we can basically just change the color again. In this moment, I'm not actually going to extract this to a different method. I just wanted to show that this is, for example, something we could also do. Now changed vertex. We are screen. If I press the C key, then the, the color of the text will change as well. So that's pretty cool, actually. Kinda funny. Yeah, but this is the normal way that we can basically access the elements or the properties of this particular component. And yeah, that would actually already be it for the normal text and the panels. And in the next lecture we're actually going to take a look at a better text even. And this is going to be text Mesh Pro, which I would advise you to use instead of the normal texts because sometimes the normal texts can be a little bit. Well, I mean, I would just say that it doesn't have as many options. That is something we're going to see in the next lecture. For now, That was it for text and panels. Like I said, panels are actually nothing too complicated there. Just an image that should sort of be used as a background and the text. Well, we've seen some of this already. And the rest is basically just normally accessible via a script. And some of the things. For example, the best fit can be really useful to yet to resize the text as you go along, right? So that was it for this lecture. I hope like always you found it useful. And if there are any questions, feel free to ask and I'll be sure to respond. And yeah. 73. (Unity UI) TextMashPro for Better Text: All right, let's continue the Unity UI introduction here for the unity course. And in this lecture we're going to take a look at text Mesh Pro. This is basically a package that comes with Unity itself, where you couldn't have amine way better control over your text. So let's just duplicated this panel's text scene once again, control D while having it selected. And L3 is going to be, let's do text Mesh pro. Yeah, TMP, txt mesh probe. And let's also open it, making sure that this is actually the scene that we're working on. And let's just add a new text Mesh pro to the, to the candidates. So right-click on the canvas UI. And instead of choosing text, we're going to choose text, text Mesh probe. And what should happen is that a particular window year should open this TMP importer we're going to import are the essentials. So you simply click this button and then it's going to do something, maybe open Visual Studio, but that's actually not needed. And there you go. So now it should be imported. As you can see down here, text Mesh Pro. And we can actually close this again. And now we have this text in and then in parentheses TMP here. And as you can see, this UI text looks a little bit different. So this is not part of it, but this is part of it. Quite a few things, as you can see that are different. So first of all, we have a bit more twos for font size. We also have a few more fond assets themselves. Those come with materials. Those are, we are going to like quickly ignore for the moment. There's also some textiles that we could choose. For example, headings, particular headings. Here. We can have quotes, they are title and stuff like that. There are main settings. Those are mainly the font. We can have the font-style write italics underlined. We can even have it a through line, everything in a big uppercase, everything in lowercase, something like that. Size also works just the way that the auto size works. It's a little I don't know. It's not as good here. You have to sometimes make the inspector a little bit bigger so that you can choose the Min and the max properly. Vertex color, once again, is simply the, the actual, let's actually disable the gizmos for a moment is simply the the color of the text. In this case, then there's also color gradient. So we can actually put in gradients here as well. So I don't know something like green at the top left and then we have like a red they are. And then like a blue they are. So as you can see, we can make some crazy effects here. If need be. There's also vertical gradient and a horizontal gradient or just a single one, right? We can override the tax. I am actually not a 100 percent sure whether the color setting override the color tag. I never played around with that one. So I can't even really say what that element is used for the spacing options. So basically if I have something written here, I can also probably do this. So I actually have a normal editor here. And then the spacing, spacing between the characters. We have the spacing between the words themselves. We have the spacing between paragraphs and I'm spacing between the lines as well. So alignment options are basically all the same. We also have the justified option, a flush option, and even a geometric center option. So there's a few more here as well, as well as having baseline, midline and the cap line if that is needed. So if you need way more, basically, control over your text than text Mesh Pro is a must. Wrapping mode simply means, okay, does it, how does this wrap? So right now That doesn't do anything. But if I enable it now, as you can see, it automatically wraps around to the next line here. Same with the overflow. There's a few things that you can do with the overflow have ellipses, they are masking, doesn't do anything truncates, so it just doesn't show it. So there's a few things there that you can do. And then horizontal mapping. So what does that look like? Actually doesn't change anything at this moment. But what is really interesting is now the extra settings here. So there's margins that you can put in. So basically the margin in terms of the GameObject itself and there's some geometric sorting. I don't actually believe that this does anything, nope. And what is interesting, however, is the rich text. I would definitely use the Rich Text, their overall, that's sort of the interesting things in the extra settings. What is very interesting here is also the material. So the material, we're not gonna go too much into it, but the material that basically also changes some of the, some of the text itself. So for example, the color here can also be chosen with the material itself. And what you can also do now is have an outline which is really, really cool. So you can, for example, have an outline here, as you can see, now this text actually has an outline or an underlay. I believe that that's sort of the shadow, I believe. Let's see if I can. Yeah, there you go. So you're going to actually have a shadow on your text as well. There you go. That would be the underlay, right? So there's a few things that you can do with this material, which you can change as well. So the overall, the text Mesh projects gives you enormous control over your text. And also what it usually is a little bit sharper inside of the game. So if we were to just, let's make this a little bit bigger here. Usually it is readable. A little bit more readable, right? Let's also just for the sake of argument, re-open the panels text here and I'm just going to add the text Mesh Pro, well, idea to it. So usually we have used the text this we cannot eat longer use for other textbooks probe we need to be using TMP Pro or TM Pro. This is the namespace that we need to be using. And to get the text we need to be using TMP underscore text. So this is the TMP txt. Basically, let's do it like this. Tmp txt. Actually let's do it like this. Yeah, that's better. But overall that the text itself is basically almost the same. So as you can see, we can choose the color of the gradient, enable and disable it. We can change the font and dot txt once again is simply the string that is associated with the texts. So changing text is the same. There you go. So that's all that we really need to know about that important that we don't use the text class anymore but the TMP underscore tax class. But if you keep that in mind than anything else is really the same, we can still change basically all of those things in here, like we would like to write and that would already be it for this lecture. Just a quick Show that the text Mesh pro text is basically a superior in almost every way to the text. However, if you really only need to use like symbol things, or you really only want to debug a few things in terms of a UI text, then the normal texts will also suffice for that. But yeah, the TMP txt will give you a lot more control over how your text look, right? So that was it for this lecture. Like always, I hope you found it useful and you learn something new. If there are any questions like always feel free to ask and I'll be sure to respond. And yeah. 74. (Unity UI) Adding Images to our UI: All right, let's continue with the Unity UI introduction here for the unity course. And in this lecture we're going to take a look at the UI images or how to add images to your eye. We've seen this as well in a very short moment when we are making our UI for the cheese clicker. So what we're gonna do is we're going to, first of all add a new folder here, and that's going to be our sprites folder. We're going to add the clicker. For example. You of course, can also add a different element here. So you can add a different asset. And I'm going to just set the filter mode to point and the compression to none. And then what I can do is, for example, on this panel, first of all, of course, let's duplicate the scene. This would be L4 images. Let's open this up and let's on our panel at a new UI element. And that would be the image here. And there it is, the image. And it's going to be crazy, but it's actually fairly similar to the sprite renderer. So if we just put this in here, the sprite, as you can see, there it is. And I mean, that's basically it. I mean, I don't wanna be too crazy about it, but overall, this is basically, you can resize it here as well. So if we go image, now we can resize it. Have it be, you know, craziness or just normal. Now, we can also, of course, change the color. So this is sort of an overlay color on top of whatever the actual sprite is. And that's really the only interesting thing for images. We will take a look at a new script as well. So L4, I didn't get that one L4 new folder. There you go. L4. That would be images. And then this would be the image. Let's do image example, right? That's a good name. Example. Yes. Let's also add that to the image itself. They go and then let's open it up and see what we can see. Well, the idea here is that once again, we have, for example, first of all, we need the, we need to be using the Unity engine that you know, not accessibility in this case, but UI. There you go. And we then, for example, have a private image, the UI image, for example, the example image here. And then we could also have a sprite for example, but we actually don't need that. We have that already. Example image is equal to this dot get component image. So this is how we get the image component. This shouldn't be too surprising at all, because once again, the image here they go. The image here is once again, just a normal component and it is actually very easily accessible. So how can we change these sprite? Well, we just do dot sprite. That's all that it is. This is exactly the field that we need to access in order to change the spread. So it's basically almost exactly the same as the sprite renderer. So the image itself is really not that complicated at all. And there's one interesting thing, and that would be the raw image. So if I add the raw image here, if we look at this right now and do this one so we unlock it. So as you can see, the raw image here is a little bit different because instead of taking a sprite, this takes texture. So if you, for example, and this is something that we're not going to look at in detail, but I wanted to mention this. So if you, for example, have a camera that you want to feed in, so, so a webcam, then you could no, I mean even a basically a movie, this could be displayed on a raw image because this can be translated to a texture. We're not gonna go into detail with that, but that is sort of the, one of the things where the raw image would make more sense. And as you can see, so we could still put the clicker in here. So that's not an issue. But now this would be a texture, right? But overall, that would actually already be it for the images. I know that that's not anything crazy or too. Yeah, interesting. But that's how you add an image to your UI. Just like with everything else on the UI, you can center it. Do anything that you want with the rector, transform, move it around and all of that jazz. But overall it is a very, very similar to the sprite renderer. Right? And that would be it for this lecture. Like I said, a little bit of a shorter one. But that's not too bad because images are, at least in terms of UI after we've seen the sprite renderer. Not that complicated, right? I hope, I still hope you found this useful. If there are any questions remaining, then please feel free to ask and I'll be sure to respond. And yeah. 75. (Unity UI) Clicking Buttons can be Fun: All right, let's continue with Unity UI introduction here for the unity course. And in this lecture, we're going to take a look at buttons. So we've already seen a button component last time in the cheese clicker, where we made some buttons that we were able to click. And now we're actually going to add a normal button from right here. So right-click on the panel, for example, u, i, and then choose the button. We're going to use the normal button or the text Mesh Pro for this example here. And yeah, so once this is actually added here, we can basically resize it like any other normal object basically. And the interesting component on this button is basically the bun component right down here. Now we've seen a little bit of this already, but not too much. The text that is displayed on the button is another texts component below it, basically as a child. And we can make this bigger. And for example, say Click Me, Something like that, right? Let's make this best-fit. There you go. So now it says Click Me If we look into the game there it is, there's the button. And we can actually have a few things that we can basically put in. So number one, we can set whether or not this is intractable. So if it's not interactable, basically gets this, gets the disabled color that is notified here. Let's just see the disabled color here. So we can also say, oh, well we want to make it red, but I think that it makes sense to have this sort of grayed out. That's what most people would expect for a disabled button. There is also when we turn it on again, we have the normal color. Then we have a color that is highlighted. So if we hover over it, then that gets changed to this color is while I'm pressing down the mouse key, for example. The selected color is if, for example, we're moving with the arrow keys on the keyboard, because we can basically select different types of UI elements with the, uh, keys there as well. We also have a color multiplier and a fade duration. We can also actually change the transition, so we can actually have a particular animation associated with it. We can even change the sprite itself. So if you have different sprites prepared for the button, then you can also do that as well. And the navigation here, that is exactly what is basically, therefore the arrow keys on your keyboard so you can switch between certain buttons, for example. So if I were to duplicate this button Control D, and I will put it here, then we can actually look at navigation visualized. And as you can see, if I press the right arrow, I would switch to this one. If I left arrives would switch to this one right now those are the only interactable, you know, buttons that there are. So that's what the visualization would show that. But then we also have of course, the onclick, which is the one thing we're actually going to take a quick little look at. So let's see that that's a great, We actually have not changed The we've doubled the scene and change something. Unbelievable, That is not something that we can do. So let's actually do the actual image here, L5 buttons. We're going to reload this and then the duplicated scene we're just going to take like it is. And that's going to be fine as well. So the L5 buttons, what can we do here? Let's create a new script, L5 buttons. And we're actually going to create a two scripts in this instance here. One of them is just a button. So I'm going to show a few things that we can do in the scripts with buttons. And then there's another script, this is just the example output. Let's say, let's call it something like that. And let's create a new empty object here, which is going to be the example output. And put that at 000 and put the example output script on there. And then if we go down to the panel button, add the buttons script onto that one. The ego, there it is. And yet Let's open both of those and actually see what we can do here. So the first one is going to be, Let's do look at the example output. Let's close the other ones. Inside of here. We're actually only going to have a public void. And then let's say an output, output something that's the name of the method. And this method is simply going to basically log, I have output something, I have output something, something. There you go. And this is basically the thing that we could add to this button. So if look at the button again, then we can manually add an on-click event. That happens if we put a plus in. And here we can actually put in everything so that we can either put it in, as you can see, we can put in scripts, we can put in different, almost every object we can basically pull in there. But what we want to put in is this example, output GameObject. And if we put that in there, then we can access all of its functions. So for example, the game object functions, we can change the name. We can either set it activ activated or deactivated. So that's also kind of useful for some things where you don't need to necessarily make new methods for that. We can set the transform so we can actually do a few things here as well. And also we can access the component example output script, which then also has the output Something method here that we can basically put on there, right? So if we now click this as you can see, I have output something. So the method on this example, output is actually being called no problems. Now, there's another way where we can add new functionality to a button via the script. And we're going to take a look at that right now in the button script, in sort of the Bund script. First of all, of course, we need to be using the Unity engine dot UI framework, UI framework, or rather namespace that you go. And then we can actually just yet Let's just do a private button. So this is the button, let's say. And that one is going to be set to this dot get Component button. So that's one scan the this component or the component method shining through and the button. We can then basically have this onclick and this is a click event as you can see. And we can add listeners to it. Inside of here. As you can see, the parameters should be a unity Events, Unity action. And we can basically do this by making a lambda expression here. So for example, we could say debug dot log and then something like four noises. Why not? Let's get a little funnier year. Why I wouldn't be right. So this would then in turn have just simply call this. We can also, if we have another method in here, you can also say private. Let's say avoid Testing button or something like that. Debug dot log. Once again look something like I pressed the button. And we can also add this by doing on-click listener. And then we can simply put in testing button as sort of just the name of the method without it having been in a method call. So don't put in the parentheses here, but just the actual name of the method. And this also works. So this is then going to call this method when the actual button is clicked. So let's see if that works. So what we should expect see is we want to see I have output something for noises and then the IF clicked the button. So let's see if that actually is the case. We, by the way, cannot see the onclick changes here. But what we can't see is the four noises and the I press the button. So those are then being called no issues by the button click. And this is basically the ad listener here. Can be incredibly useful if you want to set the different functionalities for button, maybe depending on whether or not something is opened or closed or even if you have different, you know, control panels or something like that. So there's some functionality and some usefulness for this, definitely. But overall, that is actually already it for the button. It's not that exciting. Once again, there's of course a few things where we can change the colors and sort of something like that and the intractability. But we've also seen the changes of both the intractability and a little bit for the adding of new listeners. They are in the cheese clicker. And overall that would be good for the button. It, there's nothing too crazy about it. It's basically just a UI element that you can click. And that would be it for this lecture like always, I hope you found it useful and you learn something new. If there are any questions, of course, like always, feel free to ask and I'll be sure to respond. And yeah. 76. (Unity UI) Toggles and Sliders: All right, let's continue the Unity UI introduction here for the unity course. And in this lecture we're going to take a look at toggles and sliders. So first of all, let's duplicate our L5 seen up to make it L six total sliders. And let's also, yeah, actually we don't need to create any scripts for this because those, well, I mean, most of this is actually going to be fairly self-explanatory. And you're going to access the particular component parts, the component fields and properties. Every thing else we've seen so far, So, yeah, inside of the canvas, let's first of all add a new panel here. So down here a panel. And let's put this to the right side of the screen. So panel, Let's put it also turn it back on the gizmos that, that would be kinda useful a ego. And yeah, that's fine. We can also move the text away a little bit. And then onset of this panel, we have two UI elements to add. One of the ones is going to be the toggle first. So let's make this a little bit bigger and I'm going to take a look at that. And then let's also immediately add her the sliders. And we can actually make that bigger and immediately see something. So that's pretty cool. So let's take a look at the toggle first. So the toggle, the actual game object has the total component to it. We're going to take a look at that in a little while. But first let's take a look at the background of the checkmark and the label. So the label is a normal text object, which is usually what shows you what this particular toggle does. Now, we can just size this up so that we can actually see what is going on here. Same with the background and the checkmark. Those are both those are both just an image. Basically. Both the background and the checkmark, just an image that you could possibly replace even. You can of course also scale this one up. So first of all, let's say sizing the, sizing the background, and then the checkmark can also be sized X2. Let's hit this one. And then if we hit the Alt key while we're resizing it, then we can resize it from all different angles. It depends on whether or not you want such a big toggle mark. But of course that is something that you could, for example, do. And so that's basically just the check mark in the background there just to very easily to understand images. And the label will, like I said, is just the text. And then the toggle is the one that is interesting. So once again, interactable so we can actually enable and disable it. The transition is the same. We can either attended by a color or we can change the sprite or have an animation associated with it. So this is basically everything that we've seen in the button already. The difference here is just that we have an unknown value changed. Basically method that is called when the value changes. But this is actually also an event that you could, for example, subscribe to that we've seen with our own events. This is one of those events in theory that we could do that with. And here we can simply add as well. So for example, example output. Once again, when it changes, we can, for example, say on the toggle and function example output and then say output something. This of course, also works if we have the method that we're wanted to call. If that actually has a Boolean parameter, then it's going to also pass the Boolean parameter that we are changing it, the toggle into. So that's pretty cool. Is on is basically exactly the boolean that we want to check for. So is on, makes a tick appear, and then if it isn't, then in this case the is on Boolean is false and there is no tick there. So let's just use the toggle once or twice. So as you can see, I can click this and as you can see, I have output something. And then if we change again, this will happen once more because right now we are only looking for on value change. So we only looking if this value actually changes from true to false or from false to true. So for example, if we change the label, this could, for example, be something like a perma death option. As an example, when it comes to the slider, this letter is, I would say, sort of around the same complexity. It's a little more complex. So we have once again an image. This is simply the background image of the slider. I would advise to keep this as sort of the same length. The fill area at the fill area will be shown once we actually move this handle, handle, slight area and the handle, basically the handle we can move it, which you should not move the handle independently of the slider. Because the slider here, when we take a look at the value here, if we change this and as you can see, the slider actually changes. And the really cool thing about this slider here is we can actually say, Okay, first of all, what direction does it go from right to left, left to right, top to bottom, or bottom to top and then top to bottom. We're going to keep it at left to right. Now once again, all of the usual things that are able to be done, interactable transition the colors, you know, that's, that's sort of thing. And the Min and max value other things that are really interesting. Because the idea here is that if we basically move this about, we can, for example, say, well, we want the minimum value to be 0 and the maximum value to be a 100, for example, right? Then you can change this. And as you can see now that number changes here from 0 to something like that. And we can also say, well, we wanted this to be only whole numbers or we don't want this to be whole numbers. So then you could, for example, I believe that if I put in 10.5, then that would work. If I have whole numbers, then only integers are the basically the thing that would work on the value here. So that's pretty cool. We can actually say we can also go negative, right? That works fine. So that's actually really cool for sending different values for this. So this could, for example, be A1 and FMV or something like that. If we want a text for this, then we would have to add it ourselves. But that shouldn't be an issue. So we can, for example, just say UI text and then add it to here, to the back there and then make it a little bit bigger. Say something like f of v for example. And then we have a text here. So that's, that would also work as an example. And yeah, we can also change this. So inside of our game, when we have this, if we select the slider and you can see right now the value is 35. And if I click on this and actually change it, and as you can see that slider, the value changes as well. I can also I believe, okay, Scroll willing does not work like that, but you can use the arrow keys to basically move left to right for the value. And once again, there is another event here that you could subscribe. So on value changed. And this gives you the value with it as a parameter. So in theory, you could have an ya'll method that has, that evaluates the change here. And if it's something particular, then something might happen there. Right? And that would actually basically it for the toggles and the sliders. I think that they are mainly useful in options menus. Outside of that, I'm not a 100 percent sure where you would use them, but I believe that a lot of people might come up with some other creative ways in which you could or should be able to use those, right? But that will be it for this lecture like always, I hope you found it useful and you learn something new. If there are any questions, like always, feel free to ask and I'll be sure to respond. And yeah. 77. (Unity UI) Layout in Unity: All right, let's continue with the Unity UI introduction here for the unity course. And in this lecture we're going to take a look at layouts. So this is basically where we take a look at well, layouts and how to sort of automate the layout of your UI. And for that, I have already created L7 layout as a scene, so you can do that as well. And to that, we're going to add a new canvas here. Of course, this canvas is going to be under world space camera, main camera. And then we will also make sure that it has the same scalar here. So scale with screen size, 1920 to 10, 80, and 85, and the reference pixels, we're going to set it to 200, just for the hell of it. Right? And now we're going to add a panel. Let's see, there you go. And then we're going to duplicate this panel three times so that we have three panels. And all of those three panels are gonna go as children of the first panel. And the, this one, we're just going to re-size the panel. Number one, we're going to resize and put it here. And then we're going to resize this one as well. Doesn't have to necessarily be the same size. Just similar. And we're going to put that in the middle right here. And then we're going to take the last panel and do something very similar. So that we have three panels now next to each other. And suddenly like this, that works out very well. Let's actually scale this up a bit so that they are sort of the same size, doesn't like I said, and I have to be the same size because we're going to change the sizes anyway. The first one we're going to look at is the vertical layout. So I'm going to call this the vertical layout. And what's pretty cool there is that we can basically have a certain type of layout group in onto those panels. First of all, we're going to create sort of a, a new, well I'm sort of say like a display. So we're going to add a new panel here. And we're going to make this like some like that so that it's sort of centered. And then on this one, we're going to add a few more details. So for example, a new image. So you could think about this, maybe like this is maybe a selection screen for a particular items or something like that. So we have an image here. We're not going to fill it, we're just going to keep it like it is. I mean, we could fill it with a clicker, I guess. Not like this, but like this. So we can, for example, put the clicker in there. Why not? And then on the panel we're also going to add a new text. So we're going to have maybe a text at the top, which is going to be something like really cool, really cool item, right? And then let's make this a little bit bigger so that we can actually read it properly. Let's do best fit. Yeah, that's good. And then we're going to duplicate this text and maybe have a description here. So we're just going to use something like Lorem Ipsum for this one. So there you go. Right, So now we have basically a cool little panel here. Might be an item panel or something like that, which we would want to, well have this displayed in a vertical manner. So we want this to be displayed like this. And then the next one here and the next one here. Of course, we can duplicate this Control D and then move the second one down a bit. And so on and so forth. But it doesn't really work quite as well as we would like to. And therefore, what we can do is we can simply put a layout on this panel here. And that's what we're going to do. So we're going to go to Add Component, um, and then to lay out right here. And then we're going to use the vertical layout on this one. Now first of all, as you can see, everything breaks here. Don't worry about that. We're going to use, we're going to do that and fix that in a short while. So we can go back here and as you can see, some values are driven by vertical layout group. So this means that this basically changes. Now we can actually change this back. So let's go to the item panel here, right? Uh, traded back a little bit. We can, however, as you can see, change its position. We can change the size here, but we can change the position now the size actually doesn't matter right now how it looks. Because we're going to also say use child scale, that basically the child, if we actually, that's not the scale, its size. There you go. So if we do that, so if we say control child size, then it will size up to exactly the size of its parent. So the panel here is going to size up to its parent. And now the cool thing with the layout group and the vertical layer group for this as well, we can say a padding. Padding is basically the space between the child and its parent borders, so to speak. So if I do left here, as you can see, it gets smaller on the left. So we can for example, say 15, 15, 15, and 15. So now it's going to be moved in to the middle. And sort of 15. The spacing can also be predefined. So let's put in a 15. And if you now were to duplicate this item panel, look what happens. They automatically layout that, lay themselves out here with a 15 spacing between them and everywhere from the border of we also have a 15 Yup. Unit. Basically spacing or padding. In that case. The child alignment simply says, Okay, where do we start with this alignment? In this case, it doesn't really matter. Where might matter is if you put in lower so then we would count from the bottom to the top basically. But upper-left would be fine. Reverse arrangement simply reverses the order of this, the scaling and the size, like I said. So if you put the size in, for example, for the height, right now, nothing changes here, but we can expand this. So we can force the child to expand. And this is often what we wanted to do. Because if we now add more, as you can see, now at some point, it gets a little too crowded. But for, for example, actually works out really well and it looks really nice. So this would be the vertical layout. Now, next, next one is the grid layout also usable? Often, lets actually copy one of those item panels and paste it in here. Onto the grid layout and make sure that it actually is sort of centered in here. And we're going to make this a little bit. So we're actually put the description sort of here. And then the, you have something like that. So let's put that here and then the knot rotate it though. And then the title text is going to go up at the top and maybe make this a little bit smaller as well, something like that. And yeah, we're gonna see if that works as well. So maybe a little less text and, or a little smaller of an image. And that's okay. Now onto the grid layout. So once again, under layout we can simply say grid layout. It will immediately re-size the item panel here. And we're going to worry about that in a little while because right now here, this cell size is exactly what it does. So it makes this a particular size. Let's first of all, look at the padding again, that's the panning once again is exactly the same. So if I say 15, 15, 15, and 15 then is going to have padding to the border of the parent. Basically, the cell size is exactly specifies the size of each of the cells. So for example, we could say something like, well, maybe a 150 is enough, but why it needs to be like 200. And that could, that could work, right? So we can, for example, make this a little bit smaller as well. So we can make this a little bit smaller, right? Then this would fit and make this a little bit smaller. It's going to be hard to read right now, but this is of course, just an example anyway. So there you go. So that wouldn't, would work in theory. And then if we were to add a new item panel, we can immediately see that it gets added here to the right. And if we add another one on this side, there's not enough space. So it gets added to the next row, so to speak. And if I expand this a little bit, then as you can see, now it actually does get added to the same row there. So that's pretty cool. We can also have some spacing. So this is the spacing between the actual elements, the layout elements. We can have a different start corners. So for example, we can start at the lower left or we can start at the lower right. Now this actually doesn't work. I'm not quite a 100 percent sure why that is. I'll because the alignment there you go. So the alignment actually also makes sure where this starts, a horizontal or vertical, right? So we can first fill the columns and then the rows or a column by column, or we can go row by row. And the flexible constraints can also be flexible. So flexible simply means that whatever fits, it fits in. If the constraint is fixed column count, then we can say, okay, we only have this many columns, or we can have a fixed row count. And then we can basically change how many rows there are or how many columns they have to be. So there's actually a lot to play around with with the grid layout. I can only really, I would say advice to play around with it a little bit. The grid layout is one of my favorites and it works really, really well. So if I just copy over some of them and I'm going to say I actually, I really don't like the spacing of those. I can just add the spacing here and everything just does what it does. So that's, I find this pretty cool. And it's also really great because when you generate UI elements, then the idea is that they automatically gets laid out in a way that works. And the last one would be the horizontal layout. Layout. Let's also copy over one of those and put it in here. And the horizontal layout shouldn't surprise anyone, is also on Layout under horizontal layout. And this one simply means, so if I add another one, then they get added in a horizontal way. So there's no grid in this case. So you could also, for example, expand these to be something like a no, there you go, this one to be like a really long. For example. Let's delete that one and make this one again. And then we could say for the horizontal layout, once again, padding the same spacing is the same between those. And we can reverse the, we can control the size, right? That also works. So controlling the size once again, mix this expands to be the entire size. Spacing should be self-explanatory out padding rather at this point, spacing or everything here should actually be self-explanatory. If we've seen both the vertical and at the grid layout, they're all very similar but do slightly different things, right? And that would be it for the layout. Lecture here. Layout is incredibly useful, especially if you have sort of UI Prefabs that you instantiate on your UI. For example, if you have, I don't know, like 10 items, then you want an example of 10 items here, 10 choices that you can click. And maybe if you want, if you have 20 items, well, then you want to 20 of those, and they should be laid out in a particular manner, then you can basically facilitate that with, for example, the, either the vertical, the grid layout or the horizontal layout. So incredibly useful tool to automatically lay out UI elements, right, and that would be it for this lecture. I hope you found it useful. If you did, of course, I would really appreciate a review from you. Otherwise, if there remains some questions, then of course, always feel free to ask and I'll be sure to respond. Yeah. 78. (Unity UI) Scrollbars and Masks: Or I, let's continue the Unity UI introduction here for the unity course. And in this lecture we're going to take a look at scroll bars and at the scroll wrecked component. Those sort of work hand in hand. In our case, what I want to show you is basically how he could make sort of a view. And then scroll up and down, have basically multiple elements present at the same time. And for that we're going to simply duplicate the L7 layout. And we're going to name this LH scrollbars. And let's immediately open this. And to no one's surprise, this looks exactly the same because we just duplicated the scene. And we're going to make this as an example on the vertical layout here. And the first thing we're gonna do is we're gonna make this way bigger. So the book, we don't want to move it, we actually only make want to make it bigger. So the actual vertical layout panel itself is going to get way bigger. And then we're going to just duplicate the last item panel here and have a few more. Let's not make them run off the screen there or off the actual layout panel, but only like that, then it should be fine. And then what we want is basically we're going to define that. Well, we are going to have sort of a, a new panel that is sort of this size where which is going to sort of act as a window and the rest is not going to be visible. That's sort of the idea here. And that's the way we're going to look at the scroll bar. The way we can do this is first of all, let's make something like this. So we're going to make a new panel, not basically as a sibling to the vertical layout panel. And that's going to be under a UI panel. Now this is going to be really big, but that's, we can resize this to about the same size as the original one. So someone like that. And then we're gonna give it a little bit extra on the right side so that we have a little bit of reading room for our scrollbar. At this panel will be what up at the top here and we're going to call this the scroll panel. Sure. And this one will need to. Let's actually also make sure that this is centered correctly. There you go. That should work out very well. And then we're going to add two components to it. One of them is going to be the scroll erect. This one scroll wrecked. And then the other one is going to be a mask. And as soon as we add the mask, you will see that this will immediately basically changed some visual. Our didn't change them visual. Not yet anyway. Of course not because we still have to take the vertical layout and actually have it as a child of this. And as soon as we do that, now it changes something visual, visual. As you can see, all of a sudden, the actual vertical layout is sort of cutoff at this point because the scroll layout is now a mask. So everything, the size of it actually depends where the visual range of this depends on the size of the scroller layout here. So the bigger the small layout, the scroll layout that the bigger the thing that we can actually see. And this one then now enable us. So if we were to move this vertical layout right. We'll move this, as you can see now it sort of moves up and down. Now if we can do this with in sort of conjunction with a scroll bar, well, I mean, then everything would work out very well. And that is exactly what we're going to do in the scroll panel under this. So selecting this UI and then adding a scroll bar, we're going to add a scroll bar here. Now, what is important? The scroll bar component itself actually looks sort of like the slider component. Like it's, it's pretty much exactly the same. For us for this robot, what we want is we want it to be from top to bottom, I believe. Yes, that's what we want. And then we can also resize it. So let's do something like that. Put it at the very right of the screen here. Let's do something like that and then move it down. There you go. That's sort of a scroll bar. I think that that's actually very well done. And I'm the scroll bar itself. We actually don't really need to change anything. What we need to change is the things on the scroll correct itself. And things that we wanted to change on the scroll rectus, first of all, where we only wanted a vertical movement here because this only moves up and down. And then we want to define a vertical scroll bar, which is exactly the scroll bar we have just added. And then we also want to add content. And this is basically the Rect Transform. So this would be a UI component that has the wreck transform component attached to it, which we want to move. And this is exactly the vertical layout here. After we've added both of those, that's actually all that we need to do in order to have sort of a functioning vertical layout, scroll bar type deal. And I believe however, that actually what we want is bottom to top, I believe, yeah, the direction is actually bottom to top. Let's see if that works out. And yeah, it does. So if I scroll down now it is scrolling down, but as you can see, it's going very slowly. I can do two other things. I can of course, take the scroll bar and move it around like this. And I can also click on the vertical layout panel and move that on its own. And I can also sort of let it go like you would in on a smartphone. Now, if I would go up, you can see that it's sort of a little bit bouncy at the top. This can be changed right here. So this is the movement type. It's elastic. I would personally prefer acclaimed as a sort of how almost all other scrollbars work. And also I would definitely advice to put up the scroll sensitivity there. Something like 25 should be, should be enough. Yeah, now it functions way better, so it's a little faster. With a scroll sensitivity of one, you are I mean, you're just scrolling the entire time. That is not that's not a very good idea. Yeah. And that's actually how easy it is to add a scroll bar with a little bit of functionality. Of course, once again, all of those things we've already seen in basically all of the other interactable UI elements, basically right? Color and all of that. And this, this sort of deal with basically also seen when we looked at the sliders. That's basically exactly the same thing. We can change the value now the value, of course, we can't change because it is tied to the scroll erect right here. But usually we can change the value and then we could also just read out the value by your script. Of course, by putting an any of those there. We also have this ONE value changed event where we can where we basically get the change of the value. Yeah. And that will basically be it for the scrollbar. It's actually not too bad. And with the mask and the scroll red component, you can make some pretty cool things like a scrolling layout there. And then now it could be, you could add on to this vertical layout. I mean, all you want and you could scroll and scroll. And you can maybe have, I don't know, a thousand cool items here. At that point, it would probably be better to have the grid layout, but yeah, that would be it for the scrollbar lecture here. I hope you found that useful like always. If there are any questions, then of course, feel free to ask and I'll be sure to respond. And yeah. 79. (Unity UI) Dropdown and Input Fields: All right, let's continue with the Unity UI introduction here for the unity course. And in this lecture we're going to take a look at the dropdown menu, as well as the input field for the UI elements. Those would be sort of the last elements are believed that we have to look at. So let's make a new scene, really new scene L nine, calling it dropped down input. Sure. Why not? Let's open that immediately. And let's also immediately add a nice little panel here. The canvas, of course, needs to be changed to screen space camera in this case, and added the main camera there. And let's immediately also change the reference. It's actually 1920 by 1080. And do the match 0.5. Great. That should be everything that we needed to do here. And then to the panel, just going to resize it a little bit. Put it sort of in the middle of the screen. And then we're going to add the two sort of last UI elements that we haven't looked at is going to be the drop-down. Let's make this a little bit bigger. A go, put it up here. And I'm also going to add the UI for the input field. Let's also make this a little bigger. There you go. Again with that, that would probably be all of them, right? We have seen basically all of the others. The event system gets added automatically. And the ScrollView is basically what we've done last time, more or less. So let's take a look at first the drop-down. So the first thing that we'll look at is this one label here. So the labels, of course, can be resized a little bit, 38, That's actually pretty good at the arrow could also be resized a little bit. I think that that would make sense. Let's do it like a little bit bigger. There you go. Yeah. That actually looks pretty good for a drop-down menu. And there's also this template which is currently deactivated. So if we activate it and you can see that's how it looks if we press on this other. So if we click this and then we're going to have this sort of template here. You can change the particular content in there, so the item here is changeable. However, overall, I would probably not mess around with it too much because the, I believe that this is actually doubled. Actually we can. So let's make this a little bit bigger than so like yeah, that, that's definitely a little bit too small to make the item a little bit bigger. There you go. The continents to be paid bigger at the SDA ago, and then the item should resize as well. There you go. If you press Alt, then it's going to resize it on both sides from the middle. And then we can also adjust the particular font size here. This here on the left is, as you can see, this is item checkmark. And there is also a check mark, the background and the item label. And there's a scroll bar associate with it. So this pretty much is exactly the same as the scroll records. You can see there's a sort of exactly what we built last time. Just that this is already built into the drop-down menu itself. Now, this is basically what we've seen already, but what we've not seen is the options here. And that's basically a very interesting thing. We have option one, option, option a, option B, option C, and we can simply add options onto this. I think we're going to stick with this and we're going to also not make any sprite's. Actually we're going to make the sprite in the first one a clicker and the other ones won't have a splited all. And we're gonna see how that one looks. Let's just take a look at it. So let's start this and drop this down. And as you can see, that first of all, we can choose those. And then we will have this small little checkmark. They are to note which of those options actually has been chosen. Now the template can be altered any which way you want. Reggie can make it smaller or bigger. Yeah, basically, however you would like, the actual sprite itself is not going to be displayed. This is sort of just something in the background. You once again have the event here on a value changed. And of course, the options you can, with the minus here, you can basically subtract them or, you know, get rid of them. You can also reorder them here. And this, the options here would also be possible to change those inside of the script itself. That also works. So let's take a look at that for the time being. So let's make a new folder. This would be L9. This is a dropdown, drop down. Input, inputs. The, oh, that's okay. And that Let's create a new, let's call this drop down example. And let's let it reload. And then we're going to just start this up. But before we want to change anything, they are, we are going to add this to the actual drop-down as well, just so that we don't forget that because that would be fatal. Right? Once again, we don't need the update method and using Unity engine dot, we're going to have a private. This would be a drop-down. And this is then just call this drop-down. Sure. Drop-down equals this dot get components. Drop-down, self-explanatory this one, and then it dropped down. And there we go. Options. So this, as you can see, is a list of drop-down option data. Okay, That's actually pretty cool. We can also set the actual value. This is, this would be an integer. So it's basically the index of the list in this case. So the index of the element of the list that we want. But for example, the options we can add there, as you can see. So this is a normal list. So here we can add and in this case we want, can see drop-down option data. So belief that we can make this like this, yes, exactly. So we can make new option data and as you can see, we can give it an image, we can give it a text, or we can invert both. So in theory, what we could do is something like option S. We're just going to call this option S because it was generated by a script, something like that. And let's see if that actually does work. We have option D, option a, and option C. And then after we start, we should expect option S to show up as well. And if we scroll down there it is. Option S is also available for selection. And now it's gone because of course it was generated via the script. So that's actually how easy it is to add the drop-down options via the script. You can simply make a new drop-down option data instance there and add it to the options. Right? And I mean that's basically all of the craziness for the dropdown. Changing it visually shouldn't be an issue. We've seen a lot of this basically already with all of the other stuff in the UI. So, yeah, let's move on to the input field. So the input field actually also very easy. There is the input field itself. There is the placeholder, and then there is the text. So the placeholder, we can make this a little bit bigger than you can see this, this is simply sort of like enter text. You can also change this to placeholder or if you have your game maybe on a different language, then of course you can change this as well in theory. And the text itself should probably be about the same size as this. So let's make this 59 as well. And if we were to start this and just go in here, so if I click any of that, I'm gonna get this carriage. And I can type in Hello World. And if I click out of it, you can see that the texts year changes. So this basically is just a text component, right? A reference to a text component, which is this one. And it just reads out the text that is in here. So we can basically change this text immediately. And this is also saved in the text variable, right on at the input field itself. And this is pretty much exactly where you could also read it out from. There is also pretty cool things that you can do. So the carrot itself blinks, I think this is a normal blink red. You can also increase the blink rate so that it blinks faster or slower. I don't know if that's necessarily something you need and you can also adjust the width. I believe that five is the biggest one, so it's a little bit more noticeable here. We can also make it a custom color, which is pretty cool, actually, sort of red. It's a neat thing that you can play around with. And yeah, then you can also get this time even two different events here on value changed. So this is basically when the string itself changes and then on end edit. So this is when you are done editing. And so you don't have to basically call the value changing it each time. So each little, each specific character type would be unchallenged on value changed, and then on edit, string and an end Edit, sorry, There you go. On and edit basically just gives you this ring once you're done with the edit there. So those would be the two events that you could add your function calls or method calls to as well. And yeah, that, that's basically all there is to the input field. It's not anything crazy or yeah, you can also set a character limit if you want to. That is something that you could do. And there's a few other things like multiline with Submit. You can also make it a multi-line new line, and there's also some other things. So what is the content type here? A pin, an integer number. So then it can actually read that out decimal number, right? So that would be something for the content-type. You could basically change this as well. But overall, that would be for the input field, enter the drop-down menu. And that would conclude the sort of look through, through all of the Unity UI elements. I have shown you basically all of them. Now to make this the UI pretty well, that is a whole other different issue that is definitely in your hands more than mine. That has more to do with sort of the user experience design. And that is hard to really be taught. I want to tell you, or I want to teach you the technical skills and then what you do with them. Well, I mean, I hope hopefully you could impress not only me, but maybe even yourself and a lot of other people with what you can come up with, right? So that would be it for the UI introduction. Next lecture, we're actually going to add a few more things back to the cheese clicker. So we're going to add a definitely at least the layout. And then maybe we can see if there are maybe one or two other things that we might be able to add there, right? But that was it for the UI. And in this case, the drop-down, an input field lecture. I hope you found this useful and you'll learn something new. Once again, if any questions remain, please feel free to ask and I'll be sure to respond. And yeah. 80. (Unity UI) Adding Layout Groups to our Cheese Clicker: All right, like promised, we find ourselves back at the cheese clicker here. And this is the last lecture here for the introduction. And we're just going to add basically to layout groups, one for the building panel and one for the upgrade panel. Because both of those basically could well, I mean, benefit from those. And let's think about this. So the building panel itself, we can simply go to the Add Component, building panel app component, and then add a vertical layout group. I think that that would make the most sense. And let it all control also control the child size and then get something like 15, 15, 15, 15, and then spacing also 15. I think that that actually works out really well. And if we were to have a third element here, then this would just work. And at the fourth, we would need to start resizing a little bit. Or we could also think about not having a vertical layout group and maybe having a grid layout group. We can have two of those at the same time. That makes sense. So let's remove that. Let's have a grid layout group. And then also making sure that this is a little bit bigger, I guess, because otherwise that's not going to fit. So something like 300, 200 maybe, maybe 300, 300 actually would work. And then also making sure that we have a little bit of padding here. There you go. So this will also work if we were to change around with the actual prefabs are a little bit. But I actually think that let's go back to the vertical layout group again. I think that that was fine. And that's actually okay, right. And when we look at the upgrade panel, of course those get generated via the upgrade UI. Let's actually open this as well. Because there's one thing that we of course need to change. And that would be the transform local position here because we were setting the position ourselves. Now we don't need to do this anymore. So we can basically just deleted that line completely. And let's actually just comment it out. Because otherwise, who knows, maybe that's a better. And then we can make this a little bit smaller and simply literally just add the grid layout group. If a little bit of padding, maybe 10 here, and then the cell size, I actually think that the cell size of a 100 should be fine. We can probably make it a little smaller, even 8585, something like that. And let's see how that looks. Now that's okay. I mean, a little bit of spacing would also be fine. So 10 spacing and then I think, fine, That's actually very well done. And if we were to add new new upgrades here, we could of course, make it a little bit bigger, something like that. And then the upgrades would fit it in there as well. So that's pretty neat. Actually. That that's how, that's how easy it is to actually have a functioning layout. And that's really nice. So let's actually add the little bit of cheese so that they light up. Just for the hell of it. So let's get to 500 and yeah. Yeah. So they still work totally fine even though they're in layered group. And other greatest thing is that when we click one of them, they get disabled, right? That's what we set. So the set active on the game object is set to false. And if that happens, then as you can see, they simply move. Because the layout group basically lays its self out only on the active game elements. So if we were to re-enable this, it actually just works. So that's really nice that, that works sort of inherently for the UI in the layout group. So that actually works without any issues, right? And then we might add a sort of another panel here or something like that. Or you could also replace all of the individual texts with texts mesh Pro to have a nicer feel to it. But overall, I think that that is actually fine. That's sort of what I would have imagined what we would do for the sort of different layouts, right? The upgrade panel I found to be like the most interesting one. And then the buildings panel, if we were to add a few more of those, we would probably have to realign our actual building like building panel, the individual building panel a little bit. But overall, that would still work out very well, right? And that would be it for the UI. For now. I hope you found this useful and another cheese slicker with that would be sort of complete. And I hope that you learned something new. And if any questions remained, of course, like always feel free to ask and I'll be sure to respond. And yeah. 81. (Unity Intermediate) Adding an Audio Source: All right, and welcome to the Unity intermediates section for this unity course. And in this lecture, we're going to take a look at audio sources and basically how to play audio. And the basically options that we have with that. So first things first, because we are once again in a new project, let us first setup our assets folder here. And at this time we're actually going to need a few more things. First of all, of course, the scripts once more, that is a given. And then let's just duplicate this with Control D. Then we of course need the sprites as well. Even though in this case we're not going to use any sprites in this particular lecture, but those will come. No worries. We will also need animations. We're just going to add this already. And then one of the thing we're gonna need, of course, right now in this lecture is that the audio inside of the Scenes folder. Let's just create a new scene, not a new script, a new scene, of course, they ago. And this is L, one, because once you get the first lecture in the intermediate section, and this would be audio sources. And then in the scripts folder, we can create a new folder, L1 audio. And then in there we want a new script. And that one we're going to call audio, audio example. There you go. As so that's a pretty good already m. And then I believe once we start the audio sources here, I think we have everything we need for the setup. Let's create an empty game object. This is going to be our audio source. I put it at 000, of course. And then we will add the audio source component to it. So under audio, strangely enough, and this is the most bottom one, the audio source. And there are a bunch of things that we can basically change here in terms of fields. But let's first add the audio examples here as well. So the script to the game object, and let's also add our audio files. So this one of course, is provided. You can also play around with your own audio file. But I thought that I would have one that is sort of a like a funny boing sound. We're going to hear that in a little while. And well, there's actually a very easy way to add this. You have this audio clip reference year and you can simply drag this in, and then there it is in there. Now this of course, can be changed just as with, for example, the sprite renderer where we changed the sprite just as that one. We can also change this audio clip via script. In this case, we're not going to change it. What we are going to do is we're going to play these, the actual sound via the script. So what we're gonna do is first of all, let's just go through this for a moment here. Audio mixer, we can basically, so as you can see, this is basically whether the sound should play through an audio mixer first or directly the audio listener. We're not going to use an audio mixer in this case. So this does not interest us, simply mutes the sound bypass effects. So if we have effects on this. On the actual audio source, we're going to just ignore those if that is on the listener effect. On the listener can also have some effects. We have reverb zones and we can bypass. So this would be bypassing all of those. Play on awake simply means as soon as this particular game object wakes with the audio source component on it, then it will play the sound once. And loops simply means that it will loop once it reaches the end of the audio clip, it will restart from the beginning. The priority here, as you can see, the idea here is that so if we were just read this quickly sets the priority of the source. So that kinda makes sense to the, each audio source has a particular priority. In this case, a sun with a larger priority value will be more likely to be stolen. Likely be stolen by sounds with smaller priority values. How does that, what does that mean? Well, if we have two things playing at the same time, maybe something can't keep up with it. So sometimes we have to have a priority of those. I've never actually seen that really come into effect. But I also have to admit that I've not played around with the OU, with that much. A volume should be self-explanatory. It's simply the volume of the sound. It should also not be crazy. This is simply the frequency and this will actually slow and slow up and down the speed of the sound. We're going to heal us as soon enough. Serial pan, if the video encoding is right, then you should also be able to hear this. So this is simply whether or not it comes from the left or the right speaker. A spatial blend is basically you can have 3D audio. In our case, there's three REO doesn't even make sense because we are on a, on a two-dimensional game anyway, so they go and then the reverb zone mix, I'm actually not a 100 percent sure where this goes. I basically always keep this on one. On Default 3D sound settings. There are pretty cool. So we actually have a lot of things in here. Once again, for us right now not needed because we only deal with 2D anyway. So 3D doesn't actually make any sense for us anyway. Right? So let us open our audio example and also let's untick the play on awake. Because we don't want the stew play on awake. We actually wanted to only play when we do something. So first thing, because of course this particular script is once again on the actual game objects that are audio sources on as well. We're gonna make a private audio source right here. And then we're going to set it by doing the following equals this dot Component Audio Source, and that was it. So because of course, the actual script is on the same game object as the audio source. We can just do it with this command. Otherwise, we might need to get the game object, but the Get component method easily enough. And then what we're gonna do is we're gonna say if input schottky down and get key down, actually the ego get keydown. And then we're going to say keycode dot space. Let's take space here. And then as easy as you might think, Audio Source dot, there you go. That was it. That, that, that's actually all we need to call this the only method that we need to call in order to play this sound. And let us hear the glory of the funny boing sound. So if I start this, nothing should happen. And nothing does happen. And if I now press the space bar, there we go, It works. Well, that's pretty cool. So I can actually play a sound when I press the Spacebar. And let's play around with these things a little bit. So for example, if I pull the pitch up a little bit here, and as you can see now it's pieces up and the pitch is going up. If I pull the pitch down a little bit, not too much, then it sounds like someone. That's pretty good. Right? So that's pretty funny. The stereo pen, so the stereo pen, if I play this, and it should now have basically moved all the way to the left speaker. And if I play this again, now it should be only on your right speaker. So if you want to control that basically, then you can do that as well. Of course, all of those things can also be controlled via the script. So if we take a look at this audio source dot for example, the pitch year is moved a get and a set. And we have the pan stereo, get an a set. We can have a Boolean, mute and all sorts of other things as well. So there are a bunch of other things that we can do as well. Including, for example, the volume could also be set from 0 to one and some of the other things, but the play method is one of the most important ones. There's also a play scheduled, so you can basically have this on a particular time. We can have a play one shot. So this plays the audio and then scales it up. This actually also is, you can also give it an audio clip actually. And then play delayed simply makes it delayed. Those are like very specific things. Usually the audio source dot play is the one you really need, right? And that would actually already be it for the idea of the audio source. And you can simply add it. And what's very important is that, that the camera component usually has the audio listener. That is one of the components that you need in your scene. If you don't have that, then you will not be able to basically here of this audio source and then no sound will actually reach. So that's very important to note that that as actually on your main camera as well, it should come with the main camera. So each time you have a main camera in your scene, this should immediately be on there. But if for whatever strange reason it's not, then, now you know that this is actually also something that you need robot that would be it for this lecture. I hope you found it useful and you learn something new. Like always. If any questions remain, please feel free to ask and I'll be sure to respond. And yeah. 82. (Unity Intermediate) Adding Particles: All right, let's continue with the intermediate unity section here for the unity course. And in this lecture, we're going to take a quick look at the particle system. Now the particle system is probably one of the most extensive systems in Unity. It can, I mean, you can almost do anything. Well, not anything literally, but let's say in terms of particles at least. So let us add a new scene here, L2 particle system. Let's immediately open that as well. And then let's actually don't need a another script folder because in this one, we're actually not going to use the scripts, scripts in that one at all, right? And this one is under effects. So if we right-click and then go to Effects, we have a particle system. So let's add this particle system and as you can see, it immediately goes off and shoots particles out like crazy. And the first thing we're gonna do is basically take this and drag this down so that we can see a little bit more of the inspector here. And I didn't I didn't kit when I said that, that was a lot of things and there's even more so we can actually basically each one of those or even more things. And one of the things that I want to mention is we're definitely not going to go through everything right here because three hours later, we are basically done with everything. Just immediately at the beginning, I want to say that the best thing that you can do is just play around with this as much as you basically need And as you want to. Because that is the best way to learn the particle system. Some of those things should actually make sort of inherent sense. So something like this. Start with what? Start Color. Do the particles start? What sort of gravity modified or they have. So now they're falling down, as you can see, there are sort of going up and then they're going down again. We can change the speed, right? So now it moves faster. Or we can say, actually let's make it slower, so then it's negative two. Let's actually also do that one. And not a 0, that would be, yeah, and they're really, really slow. So that's one of those things where it should actually make sense. Fairly easy. So flip rotation, I don't believe actually does anything. And this moment, nope. Because what's also important to be said is that the, this one does something so this actually rotates the actual particles. The product system usually is used in three-dimensional space. So if I change to three-dimensional space, as you can see now, they're going up there. But there's no reason why you couldn't use it in a two-dimensional project as well that like this, there's actually no reason to not do that. Right? So let's think about this. There's a few things here. So the duration, I mean, you can also hover over those and get a pretty good estimate at what all of those things are. I want to definitely show some of those things you're down here. So those are sort of the sort of functions that you can apply it. So for example, what I really like something like color over lifetime. So if I put that one in, then I can actually, as you can see, sort of have a color mode so they can start off, for example, as white. And then when they are location is at a 100, then I can say, well then I want them sort of greed. And what happens? So the farther these particles get away from my source, They get greener. That's actually pretty cool. And that is basically, you can do this with almost all of those things. You can do that with the size, with the speed. Even, you can even change the color by the speed of the actual particle. Like there's a million things that you can do here. You can add noise as you can see, that's, I mean that's madness. You can either even add custom data. We're not going to definitely not going to look at customer data because that's crazy. But let's, for example, say velocity over a lifetime. So we can, for example, give it a little bit more velocities, for example, in the z direction or in the x-direction. So then we can actually change the trajectory of this. What's more important or interesting is actually the shape and not the emission, but the shape. The shape is basically what sort of controls where the particles are being spawned. So this is the cone shape and then we can, for example, extend the angle. And then as you can see now it's a wave flatter angle, so the particles are moving out in a way more flatter angle here. We can also adjust the radius down here and also the thickness. The thickness actually shouldn't matter that much. Because once again, this is in 3D. So if I go to 3D, as you can see now, this looks a little bit different, as you can see than it did in two-dimensions. That's why I said that the product is awesome, usually used in three-dimensions, but there's no issue. You can also do it like that. And when it comes to the shapes, here, you can see there are a lot of shapes that we can use. So the sphere is, well, simply a sphere, so it will start at the beginning and then just move out. We can also extend the radius to where they are spawning in. Also have a different arc. I believe that the arc here is, once again, a little bit of an issue because of the two-dimensional nature of this. Let's look at another one, the cone for example, I actually, the cone was what we've looked at the hemisphere. But that's sort of a half circle. Open vessel, bigger radius. There you go. Something like that. So as you can see, there's almost no end to this. Now we can have sort of like a beam and we could, for example, have a, another scalable levy IFA, scale it up. And for example, this could be, you could have this and then say, for example, have the idea of we could have a where is it the size over, let's say lifetime. Actually, let's do the max particles. Also, very important by the way. But I actually want the lifetime, right? So this is when they die. So you can basically say, well actually let's do it. Let them die at like 1.5 or something like that. And then all of a sudden bam, you have sort of like a cool teleport effect for like a 2D teleported. I mean, that's, that's as easy as it is for the particle system as an example here. That was just sort of an idea that came to mind for the box, for example. And then you can also have your own custom sprites in there as the sort of spawn area, you can have a circle. Now the circle is basically an issue because it's once again the way that is rotated in this case. But yeah, that's sort of a general look of for the particle system. I really gotta be honest, there is so much you can do with this. But I highly suggest just trying out a whole bunch of stuff in here because I, it doesn't get you anywhere if you watch sort of a three hour lecture on, okay, what does each one of those things do? I mean, most of them are very well-described color by speed, okay, so the particle changes its color by the speed it has. That's all that there is. And yeah, once again, what is crazy as well? All of those things can also be changed via script. So you can basically also change all sorts of things via script. So maybe you have a teleprompter that looks like this when it's red, so you can teleport and then you make it green when you can't teleport something like that, just as an idea. So there's so many things you can do with it. Yeah, I want to leave you with this. Play around with it as much as you need to. The particle system is incredibly extensive and it can do a lot of things. But like I said, best thing playing around with it a little bit. I just wanted to show you a few things here. And so sort of the general gist of it, right? So that would be it for this lecture. I hope you learn something new. If any questions remain, of course, feel free to ask and I'll be shorter. Spawned. Hand. Yeah. 83. (Unity Intermediate) Project Settings: All right, let's continue with the Unity intermediate section here for the unity course. And then this lecture we're going to take a quick look at the project settings. So there's something where we actually don't even need a new scene four. We're just going to go to edit up here and then to Project Settings. And then we're going to be hit with a lot of stuff that we're just going to sort of glands over a little bit. A few of those things and the project settings we've seen them once before in the C sharp introduction for the C, C-sharp Project generation for the namespace. So here we were able to basically put in a namespace. And now we're basically flooded with all sorts of settings that we can put in. We have audio settings, we have package managers, custom physics. It's actually quite a bit. And usually what I would suggest is only have certain things looked at if you really need them. So we're going to look at a few things that I think are usable and sensible to have seen before, but usually none of those are really necessary. So I'm, one of those things is, for example, the graphics. You can have different tiers of graphics. And the defaults, I would actually say our best just kept like this. You know, there's some shader basically settings in there. I wouldn't mess with those, especially we're in a 2D setting. I definitely would say that the graphics should stay as they are. You can actually have an input manager. We have not really talked about this before. Package Manager, we're going to skip the physics, don't interest us. We are interested in physics to D, and that is the first one which is very interesting here. So first of all, we could, for example, have a custom gravity. Of course, gravity in our world is 9.81 meters per second squared. And that's the same that it is here. But if you, for example, want to have a gravity that is applied differently, then you can change it here, a project wide basically. And there are also so many other things that you can also change in year as well. The idea being that there is, the physics are basically completely customizable. So that's pretty cool. Actually. The player settings is another one of those things that are very interesting. So here you can supply a company name and also a product name, as well as a version. You can also override the icon of your EXE basically. And you can also override the cursor. Then there's also some settings, for example, for the PC here. This would also here the icon on the PC version for your EXE. Then you have some basic resolution and presentation options. So you can say what is the basic full screen mode? I personally think that a full-screen window is basically the best one. You can have a default native resolution run in the background is also possible. So this would be, as you can see, the idea of if you click outside of the window, whether or not the game continues in the background. And then some more things that also work resizable window would be something that might be interesting. And yeah, so that would work. Then there's also a splash image options. So this is the basically the beginning of the game. We can actually take a preview for that. So in the beginning of the game, you will have, you will see this made with Unity. You can also add your custom splash screens there as well. So if I do this, they go, you can basically add logos and then you can say, Hey, where is this, you know, you want it before the unity logo after, and so on and so forth. You can make your own background image, all of that. So basically, this is something that you would have if you're really have sort of a, a, a real maybe even Studio. And then you have your logo and you show it and then you make, has a unity logo and then any other logos you might need, maybe for a publisher or something like that, would be then basically in here. But once again, a lot of those projects settings are really for people who are way, way at more advanced into even their game. Yeah, and then there's a few other settings as well. Usually most of them can be left as they are. And that's definitely what I would recommend. As you can see once again, that there are so many things that you can basically have in here that it's actually madness. The next very interesting thing. So both the preset manager as well as the quality, basically we're going to not care about as well as the scene templates. Those might be interesting to create sort of templates for scenes. But currently, this is not really needed for our use case here. What is interesting, however, is the script execution service. And that is one of the things that I sort of alluded to in one previous lecture where we had two things where one gameObject was being set by one script and the script was reading that game object. And the issue there was that, well, maybe one of the other, one of the ones is going to be executed first and the other is second. So here we can basically add scripts. For example, just add the audio example script. And then we can say, well, when is this going to be basically executed? So this is an add scripts to the customer order and drag them to reorder scripts and the customer can execute it before or after the default time. So this is the default time and executed from top to bottom. So basically, first of those and then, and then at some point we'll get to the audio sample. So that is something where you don't necessarily have to have the awake and the start function or a method. Rather use those to sort of know which one gets executed first because maybe we have two things that are executed in the awake method on two different scripts. And we are like, Okay, this script has to run before this script. And this is some one way that we can assure this. So this is why the script execution order can be really, really important. The services, let's actually apply this. The services once again are something that I would personally say. We're going to skip over once again because that is something that is a way more advanced for you actually have a real project going that you might want to have. What do you want to collaborate? And either have in-app purchases, Cloud builds, and all of that. Not really interesting. Tags and layers is something we're going to look at in a later down the line. This is in a future lecture, especially the tags or what we're going to look at. A very interesting text-based Pro that is simply the screen that we had when we import a text smash bro last time, the timer also be something that is important or interesting. We basically have some fixed times steps as well as the timescale. This is basically what we get if we call a Time.deltaTime scale. And we can, by the way, also change this in VA script and then time basically stops. So that is something that we can also do. And all the other things are not interesting for us. The only thing that might be interesting is divergent role with the visible metal files, which we might want to basically enable in order for our I don't know why it started. All of a sudden that's kind of weird about we might want to have the visible mesophiles here. Because maybe what we want is to have this be on GitHub and then the visible mesophiles make sense, right? And that would be basically it for the quick look at the project settings. Like I said, I just wanted to give you a cursory glance of some of them, especially execution order can be very, very interesting and important. And physics 2D that you can basically customize those is also quite cool. I would definitely advise you if there are certain things, then you can also look up always look up certain things that you want. So usually, I don't know. So for example, it might have been that, Hey, I actually want to have the time to sleep be bigger or I wanted to set the timescale to something more than one, and that is exactly what you should do. So on a case-by-case basis, I would advise you to look up the project settings in the unity in the Unity documentation. That is the best idea that I can give you for this because otherwise, once again, just like with the particle system, will be here after three hours. And then we would go through every project settings. And then the first two hours would have been just forgotten after the last hour. So that's why I just wanted to mention those exist can be useful at some point down the line. But right now, I would just advise you to take this in. Okay. And then let's move on for the next time, right? So this would be it for this lecture. Once again, if any questions remain, of course, feel free to ask and I'll be sure to respond. And yeah. 84. (Unity Intermediate) Adding Tags to GameObjects: All right, let's continue with the Unity intermediate section here for the unity course. And in this lecture, we're going to take a look at the tags. And to do that, first of all, we're going to add some nice sprites to this project here. We have our good old cards that we have used previously. This is once again the multiple cards. So we're just going to basically put in a few settings here. Filter Mode point, we're going to put the pixels per unit to 16, as well as putting the sprite mode to multiple. Then we're going to apply this going to the Sprite Editor. Put the slicing to automatic, That's fine. And then slice. And then we have ourselves individual cards here with a width of 42 and a height of 60. Hit Apply here. And then we're actually fine. And then inside of here we have those cards, core 0, 1, all the way up to 55. And we're going to just take Court 0 and put it into our little world hears into our scene. And I think that 02 is a great position for this. Actually, none of that's a particle system. Let's first of all, create a new scene, of course, to keep everything nice and tidy. And this would be L4, which is adding tags. And that's also open this. And then inside of here we can put the card and they go to 0.5, right? That's great. That's a good position they are. And then we want a nice empty GameObject here. Of course, at 000, 000 or Monaco, this tags. And then inside of our script folder, a new folder. No, that didn't work. There you go. Scripts. Scripts, create folder, L4 tags. And then we're going to create a new C Sharp script. We're just going to call that tags as well. And this will be added to our empty game object here. And then we will take a look at what this actually can do for us. Alright? So first of all, a tags, what our tags? Well, the idea is that you can add certain elements to game objects, and that's exactly up here. So as you can see, tagged and currently this is untagged, this is untangle. The main camera actually has detect main camera. And what we can do is if we go into this, we can actually see there are a few tags predefined for us. Respond finish editor only main camera player and the game controller. And then there's also the edge tag, basically functionality which we can click. And then in the Inspector we get this tags and layers will feel that we can see. And instead of here, as you can see, tax list is empty. So the list of our predefined tags that we've defined is empty and we can hit this little plus and then we have to specify a name. So for example, we can say, well, the court, the new tag name is card and then save this. So this is now tagged 0. And then we can, for example, add enemy as well. And then maybe something like. Aren't even know even health or, or, or, or, or damage, something like that. So what does that do? So what does that do right now? So let's go to the vector, the card. First of all, very important if you add attack via this sum, we have this drop-down menu. It does not automatically add the tag to the game object. You will have to be open the drop-down and then basically select this. So we're gonna say cord because this has detached card, because this is a card. And then we can think that this is basically one of the other ways that we can sort of see, okay, is this GameObject a certain type of object basically, before, when we think back to where we had the box collider, where we use the colliders. There. We were able to compare the name of the object. But you know, sometimes the name changes and maybe different enemies have different names. And you want to have some sort of other identifying mark. And that could, for example, be an enemy tag. And how do we use this tag? Well, this tag is actually just a string. It is very easy to use. So we're just going to make a debug dot log here. And then we're going to say gameObject dot find. And we're going to find chords 0 because that's of course the name of this game object in this case. And then we're going to say, for example, tag, as you can see here, is just a string. And then let's copy this with Control C. And then there's another really nice function or method here called compare tag. And then inside of here we can, for example, say card. And then there's another one, Let's say enemy. Right? So idea being here. The first one, we're going to just output the tag, as you can see, tag of this game object. And then the compare tag is this game objects tasked with whatever tag we give it as a perimeter? This is of course going to be true because cord is exactly the tag that we have set it to. An enemy should be a false comparison. In this case, it's better to use this method of the compareTo method instead of making our own a string comparison, I believe there's some little bit of debate about that. But usually the compareTo method looks nicer anyway, instead of doing tag dot equals and then put in, it's fine. Compare tag is actually really a good method. All right, so in theory, this should work itself like immediately, Let's see, card, okay, first of all, that, that is the tag that we have predefined here. And then of course, it is true that tag and the cart and CT are exactly the same tag. And then enemy is not actually the tag that this court has, this game object, right? And that actually is all that there is to the tags. They aren't crazy, complicated, but they can be really useful if you have certain predefined things that should function in a particular way. And they are really useful, especially when you use the gliders. We can basically just compare tags. They are instead of comparing the name like we did. And they are a normal thing that is part of a gameObject as you can see. So this is a normal property of the game object and you can access it and even set it inside of the script if you would like to write, and that would be it for this lecture once more, I hope you found it useful and you learned something new. If any questions remain, then of course, feel free to ask and I'll be sure to respond. And yeah. 85. (Unity Intermediate) 2D Raycasting in Unity: All right, let's continue with the Unity intermediate section here for the unity course. And in this lecture, we're going to take a quick look at a ray casting. So recasting, maybe you've heard of it before. It is basically a way of looking at whether or not if you were to shoot a projectile in a certain direction, whether or not that has hit something that has one of the things where it is used. Most often I would say one of its use cases can be to basically do hit detection. So rather than spawning a bullet and have actually having the physics system sort of calculate its trajectory and having a new game object and sort of some like that. We actually just draw a ray cost, which is sort of an invisible line. We're invisible vector that then sort of detects when it hits a certain collider basic. And we're going to take a look at that. So seems new scene. This is going to be L5 recasting. Now. Oh, that's actually like that. There you go. And the, we're going to look at recasting in two-dimensions. Now in three-dimensions, the only thing that really changes is the number of what the vector that you have to put in. So instead of a vector to have to put in a vector of three. But apart from that, everything really stays the same. And then a new folder inside of our scripts folder L5 recasting, as well as a new script in there. And that to no one's surprise is also called ray casting. Great. So now let's actually add two cards here. So let's add sort of an ace of hearts. And then I'm just going to pick randomly out of this. So now we have two cards here. And what we're gonna do is we're going to semi-centralized, so negative six and then put the y at 0. And I'm going to put this one at negative one. And the X86, That's great. And one of those is going to be well detected in a little while. And one of the one. So the ace of hearts is actually going to shoot out a re-cast from itself. And then it's going to detect basically this chord here. And the way we can do this is first of all, let's add a box collider to discard. So to the five of clubs, I guess this would be once again in Physics 2D and then just box collider so that a nice box clutter is drawn around it. And then to the 0 or the ace of hearts in this case, we can simply add our script so they re correct casting script is going to be added here that you go. And the other one has a boxplot. Let's open the ray casting script and see what we can actually do here. And this is going to be a fairly easy thing to do. So first of all, we're going to delete the start method because we only need the update method. And inside of here, input.txt gets a key. We're going to take the gatekeeper, in this case, not key down. And we're going to take space in this case. Because what I want to do is basically I want to always make a new. Actually let's do key down for now first and then we can change it later. If we want to. A new method, private void, spawn, re-cast. This is just so that we can read it a little bit better. So this is for readability sake as well as just because it's a little nicer instead of putting this inside of the sort of the if statement there. And what we want is a re-cast hit 2D. This is what we want. This is equal to a ray. So this is called raid the variable, and this is equal to physics 2D. So this one physics to D is a class dot re-cast. And this takes, as you can see, an origin and a direction. And we can also supply a few more things. So this is going to be this dot transform, that position. And then it gets a direction. In our case what we want this vector to dot-dot-dot, right? Then we can also specify a distance, as you can see, let's do 15 F for now. And then we're going to be fine. If you do not specify a direction, then the ray is going to be infinitely long. And in basically the same stroke or we're going to do is we're going to draw, so debug dot draw ray. So we can actually draw a ray costs here, as you can see it also. In this case, it actually takes a three-dimensional vector. So vector three, well as a direction. However, that's not an issue because we can simply still pass it. This dot transform, dot position vector, the vector two dots, right? Times 15, because that's basically the length that we've specified here, right? This direction and this is the length. And if we just multiply those, and that works out very well as well. And then we have to supply a color. Let's do blue here. Let's do blue. And then there's a duration. So this is for how long this ray actually will be drawn. I'm gonna take five seconds. So this is very much like a draw line, just that it is specifically for a ray in this case. And then what we can do, as well as debug dot log re dot collider. So this is the GameObject, Let's see, collider. This is actually the collider 2D that is attached to the game object that this array has hit. And I'm just gonna say name for now, let's just output the name to whatever the actual re-cast has hit. So if you think about this, what should happen is that from the position negative 600, a re-cast 15 world's wealth steps along with 15 world units along spawn. And then as soon as it hits the courts, 32, it basically should output that as well. So let's just see if that actually works. So right now we are in the game and I hit the space bar and you can see cores 32 actually gets output. And we can actually also see this very thin blue line. It is very, very, it's not actually very good to see. Let's actually go back and make this red. Maybe, maybe the red is a little bit better to see. That might be the case. So let's see if that works out. Yeah, red is a little bit better. So C, I'm just going to pause it. Instead of our scene here, we can actually see it a little bit better. As you can see from the center of the card outside, we go to the right, exactly 15 units basically. And we hit this chord and this ray then basically detects, oh, I've hit a card and then outputs the actual name of it. Now, we can do this multiple times, right? So we can spawn array. Now, the ray actually would be gone at this point because we've already hit something we've done, we're done. So the visual is a little bit, well, I wouldn't say wouldn't say that it's deceiving, but the visual stays a little bit longer, just so that we have a show that we can actually see what's happening. If we were to take this card and move it down. What you will see is that all of a sudden we will get a null reference because we have not hit anything inside of this ray. So that's also something that you should definitely consider that maybe re dot collider is actually going to be null. So just be aware of that. And if we put it back and we hit it again, then as you can see, the cards 32 gets outputted multiple times. So with that we can basically say, okay, where's this? We can also take a look at where this was hit and all sorts of other fun stuff. So the ray actually has a few things there. Let's just see what the ray also has to offer. So we can get the collider. We can also get the distance which is can be really useful. And this is the C fraction of the distance along the ray that the hit occurred. Basically means that if the ray is 10 units long and it was hit in exactly in the half of the length of the array, then this would get 0.5 because that's 50 percent of the length of the array. There's a normal vector that you could get which might be useful if you want to do fancy things with vectors they are. You can also immediately get the rigid body that is attached to the game object. In our case, we actually don't have a rigid body attached, attached to it. You can also get the point, the exact point in world space where the ray hits the target. So this would be, well, in our case it would be somewhere here. This is one of the ways in which you could, for example, say, Well maybe if it hits at the top here, then you want maybe the top half of this core to vanish. And if it hits at the bottom you, then you want the bottom half to vanish somewhere like that. So you can sort of make you without damage in particular parts of this card. But yeah, that is the basic recasting heater. It is really useful because with of course, the collider once again, you can very easily get the gameObject dot gameObject as you can see. And then you have the GameObject and that of course, opens up basically everything that the, that the game object has rights you can get, do get component again, get any component that it has, and do all sorts of crazy things with it. So you could hit it and then change its position or you could change its size, something like that. So basically the, the possibilities are really endless in this one. And the re-cast is simply one way you, that you could do this basically. And it's a fairly, I would say cheap way. All things considered to do this. So if you have a if you have basic 2D scene where you would shoot something, then maybe putting in re-cast is a little bit better. Well, yeah, there are numerous options of what you can use re costs with. Those are just some that I mentioned. One of the ones that I used, for example, was inside my, I had a 2D game. Let's similar to Zelda, let's say. And I was shooting in a re-cast out of my character every time I press the spacebar to basically talk to NPCs. Npcs all had a box collider and they also had an interface called a trackable. And if the re-cast detected that they had an eye tolerable interface basically attached to them. Then I was able to talk to them. That was basically the way that I use re-cast in one example. But of course, there are so many ways that you can use the re-cast that yeah, I just wanted to show you how you can use it and the more you use it for, well, that really is up to you. And that will be it for this lecture about ray casting. I hope you found this useful. Like always. If any questions remain, then please feel free to ask and I'll be sure to respond. And yeah. 86. (Unity Intermediate) Preparing the Scene for Saving Data: All right, let's continue with the Unity intermediate section here for the unity course. And in this lecture we're going to take a look at how to save data with player prefs. And yeah, so basically how you can save particular data to the hard drive. And then when you basically reload a safe, for example, how does that work? And we can do that with something that is called player prefs. That is a class that unity provides for us in which we can basically safe integers, strings, and sort of the normal and primitive datatypes. Now to do this, we're going to actually build a quite big seen in this lecture here. So this is L6 player prefs. And the reason why I want to build a little bit of a larger scene here is because number 1, it's a good practice. So that's pretty good. And then number two, this will also be used next lecture when we are saving and loading with JSON files. But we will get to that once it is time, right? If you're not interested in basically the fluff around it and making the UI here, then you can, of course, also skip this lecture because the next lecture is basically just the wall, how you do the player prefs on their own. And you can simply download the actual package that is provided. There. Everything is already set up the scene and the player prefs and all of the scripts basically are setup. The only thing that is not setup is the saving and loading of the data, which you could then basically follow along. I just wanted to mention this because the actual player prefs is only about five minutes of the actual lecture. The rest is sort of the thing around it. I just wanted to mention this. You don't necessarily have to set it up. You can also just download it. So yeah, so L6, player prefs. And to create our scripts, we actually have four scripts, in this case, the one of, the first one is called population. And then probably, yeah, there you go. And then the second one is a player data. So this is just an example for some player data that we're going to use. Then we have these safe player prefs that is going to be the actual file or the script that is going to save the data. And then we also have a UI Manager that is going to manage the UI that will be displayed. So let's open those one after the other. Core population player data, safe, player prefs, and then last but not least, the UI Manager. The first thing that we're going to take a look at is the court population, which is going to be very, very easy. That is actually going to be a like the easiest one of them all. Because this one simply will have a private list of Sprite. Nope, not spring drawing but Sprite. They go as going to be cold, all called sprites. And then we're going to make this one serialized field. That is it, That is all of the car population has. It is simply a mono behavior that will hold all of our cards. And we can immediately added this as an empty game object here. So this would be our card. Population. And then we're going to add this to the actual object and then our cores that you have already imported. Once again, we're going to, first of all, we're going to lock this in here. So selecting the card population GameObject, locking the inspector. And we're going to select Chords 0 and then hold our Shift key go down so that if every card selected, and then we're going to simply drag those over to all cord sprites. And now we have all courts brides here, neatly inside of our card population script. And that will be used later to reference basically a different card sprites. And yeah, so then let us continue and let us first build a very nice UI. So for that, we're going to add a tonight's panel here and then the canvas, first of all, of course, unlocking this again. And then the canvas will be put to screen space camera. Adding the main camera in here. This shouldn't be anything too crazy. And then the panel will be sort of at the lower half of the, the lower half or the lower third. Let's do lower half, That's fine of the visual field. And we will also have a card. So let's just put in a court hears occurred 0. This is going to be at 0.52. I think that that's fine. And this is going to be called the player cord. So this is the car. Basically, the player can choose what card is being displayed here and we're gonna save that. And when we load the data back in, then the card will actually change. So that's one of the things that we're going to do. We also have to build a few more things on the canvas here. So that's going to be a little bit more extensive in this case. One of the things that we're going to have is a drop-down and we're going to use the text Mesh pro in this case. So let's do the import TMP essentials here. Now that we have the text Mesh probe basically on this as well. So let's make this a little bit bigger. Something like that is probably going to suffice for now. We can look at that in a little bit later. So this would be the, basically the card drop-down, right? So we're going to rename this card drop-down. This is the drop-down menu from which we can basically from which we will be able to choose the cards. We're going to populate that with the courts later down the line. And then we will have three inputs. So this is going to be a UI and an input field, also text Mesh Pro. Because why not? Let's make this something like that. Let's try to center it more or less. And then let's go into this input field and just resize this week this auto size. So the placeholder is auto size and other texts will also auto size. And then this input field is going to be the HP input. So that's, I'm going to basically, yeah, Well, first of all, we're going to build this and then we're going to build the data to it while selecting this Control D to duplicate it. And then this is going to be dragged down a little bit. And this would be the empty input, for example. And then we're going to duplicate that as well. And then this is going to be the XP input. And the, I'm also going to get some labels there. This is just going to be text Mesh Pro. So this is the HP label, for example. Let's do this one. And we're going to move this, actually make it a little bit bigger. Move this up here. And this is HP, right? We can also auto size this. That's great, That's pretty good. Duplicate it once again with here Control D and then another one, rule d. This one would be the MPI label, always making sure that this is a nicely done here as well as the game objects being renamed portal properly, as well as then of course, also changing the texts that they are. Because this is going to save you a lot of headache, especially later down the line. If you might want to change some things, they are you're going to be happy that you rename this properly. And then two last things, and those are going to be two buttons. One button right here. This is going to be once again a text Mesh pro button. And this is going to be the to be the Save button. And then let's duplicate that as well. Actually change the so you can just go back control Z. Of course, this can be the safe Data button, and then let's copy this. Actually. Let's also make the auto size, so that's actually even better. Now duplicated. But it appear this is going to be the Load button, load button. And then also change the text here to load data. Right now the first panel here is set up. And now we want a second panel. And this is basically to display whatever we have put in there is going to be you panel. And then make it a little bit smaller to the right side here. We're going to have a panel up here, which is going to display the rest of the data. So this is going to be the player data panel. And on this one, we're going to have a UI text at the very top. Which is just going to say, this is just going to be the player data label. For example. This is just going to say player, a player data auto size and then also make it center id, the ego. And then we're going to have text. This is going to be the each peal HP label once more. So for example, we could also select those and then duplicate them again. Take them over to the player data panel, and then just drag them over so that we don't actually have to read. We do those because those are basically the same. Those are just labels that are going to stay exactly how they are. So they're not going to change. However, we will, then we can basically duplicate them again. And then these ones, these game objects, are actually going to change. So those would be. The HP value, value text, for example. And then we have the MPI value text and the XP value text. The inputs here are, I'm just going to pick any number here. So something like that. One hundred, ten hundred, five hundred, and then this one's going to be 500. Now also going to expand this a little bit. So we're going to make this a little bit bigger and also make it align with these so that it kinda looks nice. More or less. At least they go something like that. A line there and a line. There. You go. Now it's fine. And then this one as well. And there, and then we're going to make this same size here, as well as this one are the same size as the lowest one and the middle one. There you go. Then these three are also going to be sort of anchored to the right. So we're going to have the alignment B on the right, and those are going to change. But we'll, we'll figure out why, how that works in a little while. First of all, that is the setup here. So that works out very well and that's pretty good. Let's make this smaller. And we can basically already add a few things onto this. So the first thing that we're going to have is we're going to have a create an empty object. Does the UI Manager, we're going to do a lot with that in a little while as well as we will have a, another empty object, the safe data object. This is basically going to save our data and basically also load our data so that we have this available, right? I believe that that is sort of the setup that we need for now, and now it goes on to the different scripts. Let's also added the, let's add the player, the safe player prefs here to the safe data object, and the UI Manager to the manager object, as well as the heart population we've already added. And then the player data, right? The player data doesn't need to be added to anything because the player data is actually not going to be a mono behavior. So that's where we can basically start. So let's actually delete this first and foremost. And the player data that we wanted to save is a few things. So for example, what we want to save is a public integer, HP, a public integer MP, and a public integer XP, as well as a public int card index. So this is the index that represents the card. Of course, what we could do is we could save the card itself. But why would we save the card itself or the sprite if we can simply say, Oh, I mean, we have an index, we have a list of cards. This is why the core population was such a good idea. And we can easily do that. And we're basically going to make this fairly sensible. So first of all, we're going to actually have a delegate here. So this is going to be a public delegate void on player data change so that we can basically see when the data changes. So we're gonna put in every bit of data here in the card index, in heart index. So that is the The void and then all of the parameters is how the actual event or the method that it's being called by the event has to look like. So we have to give him the perimeters and it needs to be avoided. And then we're going to have a public static event of type on player data change, which is on data change. And we're going to use this to basically update the UI once the data has changed. So once again, instead of going through it with inside of a, an update method, we're going to do it like this, right? We're going to make a single pattern here. So we're going to have a private static LEA data, which is going to be the instance which in the beginning is going to be null. And then we're going to have a nice little get ghetto by doing a static player data instance. This is written now in capital letters. So this would be at this instance, in this case is actually a property. And then we're going to have a get in here where we basically say, Hey, if instance is equal to null, then we're going to create a new instance. And if it is not, then we will simply return this instance. And inside of here, we actually want instance is equal to a new player data. However, right now this would be unfilled. So we're first of all going to have to make a new constructor. Now this constructor can actually be private because we actually never want clear data to be outside of anywhere. We always want to create it inside of here. In this case, because there's always only going to be one player data. And that is going to be saved in this instance variable accessible by public static player data instance. Now usually, this is not quite the way that it would probably function inside of a game that actually works. But this is going to be, I think suffice for this moment because actually what all the only thing that we want to do is we want some data that we want to save. So our constructor will have a JMP XP and card index. We could have also have this generated automatically, but I believe that this is going to be fine as well. So this is, this AHP, this dot AMP is equal to MP. This.tab XP is equal to x b, and then this dot card index is equal to coordinate x. It's equal to card index they go. And what we will also have is, so this is the player data inside of here. Now we have to specify the things that we want. So let's do a five hundred, one hundred, ten hundred to 507,000. So this would be the HP, Starting HP, the starting MP, starting XP, and the card index that we start with. And we'll also have a public void, which is going to be the set player data method, which basically sets the player data. So we can basically change it. This is going to be have exactly the same parameters as the constructor. And it's going to do exactly the same in this case. And then we also will call the data change with a question mark dot invoke so that we check whether or not it is basically null or not. And then we can simply put in all of the parameters that we had up there. Inside of here. And this will then call the update or change event every time we set the player data and basically change it so that then we can update the UI once we have basically put that into our UI Manager. All right, so let us then go into the UI Manager. So your manager is going to have a, that's actually going to be very interesting. This is going to work like the following. So we have a bunch of UI elements inside of our scene right now. And we will actually have all of those sort of explicitly put into our UI Manager. So we're going to have a, so first of all, of course, using the Unity engine wi, so we need to use this namespace. We will have two buttons here. So private button, Save button. And then we could simply copy this over control C and then save this with the Load button. Now both of those are going to be serialized fields. In this case, I'm actually going to put the serialized field in the same line as this, because otherwise our script is going to get very long. It is now is already very long, but this will just make it a little bit easier to read. You can also do that by the way, I usually put it at the top on another line. But it's also works. We will also be using TMP Pro or TM pro for our pro in this case. And we're going to have a serialized field of type private TMP input field, input HP, no input, HP actually. And then this can be copied as well. So Control C, Control V, control V. And then we have input MP and XP. It will also have a serialized fields, private TMP, dropped down. This is going to be our card drop-down called drop down. And then we have serialized field of private TMP, txt. This is the HP text. So this is the actual display of the values. Hp takes empty text and XP text. And then for now, what we'll have is we'll have some. So one player data play out data reference here will also have a private called population, core population, so that we can access this whenever we want to. And then last but not least, which we have not implemented, but we're going to very soon at the safe player prefs, which is going to be the safe player prefs. There you go. And now this is a whole bunch of stuff, right? That's crazy. That's a lot of stuff. Yeah. And what we're going to do is first of all, we're going to basically set this up in the awake methods that we're going to store this in the wake method and we're going to set up a few things in the beginning. And that is going to be the player data. So player data is equal to data dot instance. So this simply makes sure that the player data variable here, the static variable is being set. And this then saves this into the player data variable. Then we will do, then we will say, Yeah, well then we'll actually find all of those things. So safe player prefs is going to be equal to GameObject dot find. And actually what we are going to use another one we're going to use find object of type. So this is sort of the gameObject dot find and then get component all in one. This is going to find a, a game object that has this particular script attached to it. And then the car population is going to be the same game object dot find, object of type. And this is going to be the card population, right? And that is it. For now what we're going to do in the awake method right here. There's a few more things that we need to do before we can basically continue with this. And so I believe the update method we actually don't even need because like I said, we don't want to use the update method. We actually want to update the actual UI with a, with the event coal. And yeah, we can actually implement that already. So this would work with the private update UI. Note not updated, but update UI, which of course has exactly the following parameters. In MPI, in XP and int index. This is the card index, of course. And then what we're going to do is we're going to update exactly those things here. So we have the XP HP texts, we have the empty text and with the XP text I then one other thing that we of course need is the GameObject of the player card. So what we can actually do is private sprite renderer. This should be understandable in just a while. Player card sprite renderer. So this is the, this is going to be a reference to the cart here. So the player card that we have right here and to the sprite renderer us so that we can set this as an update as well. And this is going to be the player card sprite renderer equals gameObject dot find, player card, player card that you go. Dot get component, not get component in children, but normal get component that ego, sprite renderer read. So this is the setup. This is something that you usually will have to do anyway when you set up some big scripts and sort of an interlocking way of doing it. And now we can actually set the data already. So the update UI should now work no, without any issue. So player sprite renderer dot sprite is equal to the car population. And then Aya, Of course, well, the car population right now, let's just quickly go back to the core population. This is of course private now, we actually will have to set it to public in this case. So that we can access it from anywhere we want to. You could also think about making it static sort of as a singleton, but that's going to be fine as well. And then now we can actually access this. And this is going to be the chord of the given index where we're going to set this tube. And then the texts will be set as well. So HP text, text is equal to each p dot toString because those are integers, we actually have to convert them with the toString method. And then we can simply copy this over. So MPI texts and expert TTX, XP and MPEG-2 string. With other way around, they go MP and XP. Be careful about that. That might happen just to make sure that everything is in the correct order there. Right. And then the what else would we want? We would also would like another method which is going to be called private or not load, not on level loaded but only load. And this is where we basically take the inputs and set those. So the idea being that right now they are empty, right? So right now the texture is empty and we're immediately going to set this to the default basically. So we're basically immediately going to say, okay, input HP, that is written in there is going to be player data dot, dot, dot to string. So at the onload, I'm going to show you what this does exactly in a little while once we start this. But it is basically simply going to make sure that the actual inputs are also done correctly. Coughdrop. A value equals player data dot card index. And then the onload method is going to be cold. Well it currently we actually don't need to call it. Let's just call this on load right here in the awake. After the player that instance has been set. And then I believe that we actually don't need to do too many things anymore. We need to populate the courses drop-down. So that is something that we need to do because right now we could do this either manually or via the script. Because when we look at the panel here, so this is our input panel, the card drop-down right now of course has no options, or rather it has options a, B, and C. But that is of course not quite what we want. And what we want is basically all of the cards in there. So we want the card population sprites in there so that we can basically choose one of the cords they are. And what we're going to do is we're actually going to make a new method for this. So this is going to be a private void. Void pop you late, cord drops down. And this is going to do the following. This is going to have a list of TMP drop-down option data. This is what we've seen already, the way that we were able to populate our dropdown before it was with this option data class basically. And this is going to be a new list here. And then we're simply going to do for each sprite, sprite in court population, dot-dot-dot note, card population. That's not right. Card population. There you go. Dot sprites. We're going to do data.table package and then do a new option data here with the particular sprite dot name as well as the sprite itself. And then in the end card, drop-down. And options is basically where we can add a list of options and they are, we will add the data in. So this simply populates the actual drop-down menu. And we're going to see that in action fairly soon. Right? So let us see let's also make sure that inside of our court drop-down that the options that we already have or actually taken out that are optional list here is empty right now. Otherwise we will have those options as well. And that of course, will not work. Okay. I believe that for now we're far enough ahead or we're far enough inside of it that we should be able to start this and actually change things. Currently, we will not be able to save anything. And yet the last thing actually, before we start is we need to say on, are awake here, at the very bottom here, we're going to say this would be the change. So this is the, actually, let's put this up here. So as soon as the player dataset, this is going to be player data, ordinal data change plus equals update UI. So we're going to update the UI when the player data changes. Right? And that should actually be it for this one. Let's see, Let's start this, see if we get any errors. We actually do get an error. That is not the worst thing. Right now. We're actually making a very, you know, quite the complicated things. So we can see what Y0 is. This will card dropped at data options so that somewhere something here is a null reading. We can think about this. So the idea is we have cold line 38 in the UI Manager. And this somehow is null here. So what is probably know is the card dropped down in this case. And let us think about this. And that is of course, true because we have missed a crucial part of this and that is setting all of these serialized fields. So if we take a look at the UI Manager here, everything here is not being set. And that is of course, something that we need to do first. So that is something that is totally normal can happen to any, anyone. Basically, sometimes we just forget to set something. So that's actually very important to think about. This is an error that can occur at anytime. And now we're going to set this so the insert of a panel here, Save button is the Save button, the Load button. And now, as you can see, the naming here comes in very handy because we know what everything is. Hp input is HB input, empty input is empty input x p input is EXP input, sorry, executed with the ego. And the card drop-down is the card dropped down. And then we can go to our player data panel. And get the value texts. So HB value texts, MP value texts, and XP value texts. This is why the naming of the game objects is so believably important. Don't say I don't need that. It only takes a few seconds and it will save you a lot of hassle because now if those would be input one, input two, input three, we would have no idea. We will have to click on this. Look here. No way easier. Name them correctly and everything is going to work out way better. Write it now, we should be able to start this without any arrows. Let's see. Okay, there are no errors, so that's kinda nice already. Can see the input fields here. I have actually filled up with the player data that was in the background. And then we can also choose some of the cards here. Now, those are, as you can see, a little bit crammed in. So we might want to look into our drop-down and just make it a little bit bigger here so that you can basically expand this template in a little bit. And I believe that that should actually already make this a little bit nicer. As well as putting the template here, having the scroll sensitivity a little bit higher. So maybe putting this to 10 would also work, but that is something that is really not incredibly necessary. It just going to make our life a little bit nicer. So now it's a little bit nicer. We can still see however, what we can choose your end. Yeah, we can basically choose a different card. And right now, nothing happens on the, on the choice here. But this is actually something that we're going to put in now because this is the last three things. Before we are actually saving something, we've curve has to, have to change the data that we see. So basically, if we change the display here, then we want the actual cards to change. And if we change something here, then basically at the end of this, we want to change those data things here or the relevant player data that is being displayed. And we can add this by basically, let's make another private void. And this is would be basically on, on data changes, on data changes. And we're going to put this at the very bottom here. So this is on, on data changes. And that is going to have some added listeners here. So this is going to be the card dropped down. But yes, on value changed, add listener. And then inside of here, we basically have the index given. And then we can make another a lambda expression here. And what we actually want is we want to change the player data they are. So the easiest thing I think to do here would be to, yeah, Actually let's make a private void safe method with inch, HP and MP in x be an integer index like this, just without that one. There you go. And then we will simply call data dot set player data, so that it was the method that we've defined before. Each BMP. And index. And this is going to be called in here. So even if the index changes, we're going to change all of the player data. That's not too bad. All things considered because, because, why not? So this is going to be, we're actually going to make an int. This would be the input HP is equal to in dot parse input HP dot text. Sorry, this is the input. Hp. I call this the input. Yeah, definitely. Okay. Input HP is the, is an integer. Oh sorry, of course, this the same, then this will not work. So input HP dot-dot-dot texts, they go. So that was the issue in here. And we're going to copy this over, make the input MP and input X p value. This can be MP and XP. So basically, in this moment we are reading out whatever the text is inside of our inputs here. So the input here, the input here, and the input here. This is the text that we're reading out. And then basically saving it in this safe method. And this is going to set the actual data there. So this is going to be input each p-value, input empty value, and input XP value down here. There you go. And then we also need the index. Now the index is actually what we are given with the listener here because this is the dropdown basically gives you the index of the change so we can drop down and then we choose a particular item in that. And we are given the index that we are changing too. And this is exactly what we would want to add to the save method here so that the index of the chord changes. So this is one of the listeners that we wanted to add. And we also want to add listeners for the change on the actual inputs they are. So the input HP, um, which is the input field, there is an end edit. So this is once again, we've seen this before. This event that gets fired when we are done editing the particular, well, whatever is written in there. And then inside of here, we actually will get a string. So this is going to be, let's call this the HP text. Sure, why not each vertex change, why not that one? And then we will also call the save method here. And instead of using the actual thing that was parsed up there, we actually wanted the each vertex change here. However, the other values we are going to take from the top, they are input x p value as well as the index we actually also have to get, of course, then this would be int index equals int dot nowhere. You actually don't need to do that. We can do drop-down dot value. There you go. So this would be the index. Let's actually call this the card index. Because otherwise this index and this index might be confusable. So card index. And there you go. This is now of course a string. So this would need to be parsed in the inside of here, is a little bit wonky, but I think that this is going to be fine. The text change the ego. And then Let's actually pull this down here so that we can, now actually I think that this is going fine. And we want to do this not only for the HP. So when the, when we are finished with the HP editing, but also with the MP and the XP editing. Now very important that we also change those variable names. So this is NP and this is XB tax change. And then we don't no longer wanted to parse the HP change here. We actually want to take the value at the top. We want is copy this one in dot parse. And then here it is, the same idea. Oops, nope, that's not what we want. There you go. This is going to be input HP value and then copy this Control C. And then this is going to be Integer.parseInt, this and this. All right, let's go through this. Let's quickly, quickly, quickly explain lists. So what are we doing here? So on data changes is simply a method we call at the end of our weight method here. And the idea is that in the beginning we are reading out everything that we have the inputs for. So we read out of the text of the HP and put the MPI input in the XP input, as well as the current value that is selected in some of our dropdown menu. Then we add listeners to each of those. So basically when the value of our dropdown changes, so if we select a different value, then what we want is we want the safe method to be called end, to be passed exactly those values. Now, this is simply not going to change anything. We simply be, but we still want those values to be passed. Because in our case that we have a safe method that has all four of those values in theory, of course, we can also go to the player data and basically set player data individually so that we can set individual pieces of the things. So if we go back to our player data here, of course right now, our set player data is something where we have to set every variable at the same time. We could, for example, make more over, overload this method and have something like set player data and then only give it the HP or only give it the MP, or only the XP and so on and so forth. Right now I think that it makes more sense to have all of this in one because we can access the rest of the actual input. They are no problem whatsoever. And then next thing would be that if we were to a, change the input fields. So if we're done with the edit there than what we would want is we want to set the only that input that we changed. This is going to be a string of therefore we have to parse it as well. And then the rest is going to be the default values, sort of speak. So those are going to stay like that. And we want to do that for each of the three inputs. Right? And now we're still not to saving because like I said, this is going to be a little bit more extensive because I actually want you to sort of understand the framework around it. It is weight because of the saving itself is going to be really easy. You're going to be like really, that's the saving. You spend like 30 minutes on, on the UI and all of that and then like four minutes on saving stuff, that's ridiculous. But this is basically, I want to have this as a sort of a, a really nice way in which you can also play around with it a little bit. So, yeah, so now everything has been set. Let's see what happens. So first of all, let's start this. And if we were to basically have a different card selected here, and as you can see, it changes to the King, which is really, really cool. And then we can change another card, 33, and then maybe we want to go down 41. There you go. Now, let's change the HP. So for example, 8 thousand. And if I click outside of this, then the HP will actually get changed as well. Now what you will have noticed here is that the chord changes back and we will actually fix that as well. I've just noticed why that would be the case. And the reason is because this on data changes, of course is called once. And we basically save whatever the actual values are. Ones in here, which you might say, well, that's not going to be an issue. However, it actually is going to be an issue because this is sort of a one time thing, right? So this gets called once and then those values get passed on to this. So there are two different ways that we can deal with this. We can either make this take these things right, and then put them in here. So may basically have this one and then this one, and then this one. Now you might ask, why would that change it? And let's break this like this so that we can see it. So you might ask, why would that change this to working? And the idea is that, well, because the input text here changes after we have cached this value. This value doesn't change anymore. This is set in stone basically. So this is sort of a thing that is important when you are. I mean, this is not really sort of parallelism or, or, you know, working with parallel things. But this is one of the things that is very important to think about because sometimes caching these values actually doesn't quite work. So sadly, we'll have to take this and then basically replace this one and this one as well. And then we can take the empty text and replace this one and this one. Let's also make sure that we are breaking this at a reasonable way. So basically, after the empty text for this one, and we have to take the XP horsing here and take the z value, z value. This is already being done. And then sadly same with the card index, where we actually have to put in the value here. And then all three of those variables, all four of those variables completely get obsolete and we don't need them anymore. This sadly leads to the fact that this is way less readable. But we could make this a little bit more readable by expanding the lambda expression in this case. But we're not going to do that right now. Because for in this case, this also works. We could also have another method called, but I believe that this is going to be fine for the time being. Right. And then just for tiny bit further clarification, because this might not be sort of obvious why this is not working, why this wasn't properly working before. The idea is that so for example, when we change the value of our cards drop-down. And if we now put in the parse text here, then this happens every time we actually change this value. So we basically, each time that the safe method is called, we're actually doing this again. And before, when we had those variables cached before, then that would happen once before, and then never again. So we would never read out the actual text that is in there. Therefore, we had to change it like this. Actually. One example of where sort of, I wouldn't say being fancy, but you know, sort of premature evaluation of the code might actually lead to it not properly working. That's actually a good example of something like that. So that's why I wanted to basically keep that in and show you, right, but now if we are actually doing this, then it should work no matter what we do. So if we change this to something like here, and then we change this to 5000, as you can see, the MPG or changes. And we can also change the XP to something and then change the HP to something. And all of the other data basically stays how it is supposed to be. Because now on each of the changes here, we're actually reading out what the actual value is. And then we are setting it to that. Right? Once again, there are multiple ways of doing this. One of the other ways, of course, would be to have multiple safe methods so that you can have set only one of those variables instead of all of them together, that would definitely 100% also work. But in this case, what we're going to do is we're going to set the data all at once. That is of course, something that you could implement. If you think that that would be more sensible, you can implement your own version where you could set each of the individual data types they are. And yeah, that would be an idea, right? We continue with the saving inside of the player prefs, next lecture. So I hope you found this useful and that was good training for you. So if any questions remain, of course, always feel free to ask and I'll be sure to respond. And yeah. 87. (Unity Intermediate) Saving Data with PlayerPrefs: And now on to the saving part, which probably everyone has been waiting for for quite awhile. And what we will have is we will have two methods inside of our play, safe player prefs. That is going to be a public avoid a safe data, save data, and then a public void load data, load, load data. There you go. And also a private player data variable here play our data. They go. The player date of variable is going to be set to play a data equals layer data class equals in dot instance should be sensible. The saved data is simply going to do player prefs. So this is exactly the class I was talking about in which we can save things and then we can save things with the set. So set, float, set, and set string. Those are basically the three different values that we can save. So those would all be ins, so this is HP. And then as the second parameter, we're going to give it the actual value. So that is all that we really need to do to save this. And then let's do this for all of them. So MPI, not only him but MP, EXP, and then we'll also do the card, card to card index. And this is going to be empty EXP, and then the court index. So this is the saving done. That's it. Now we only need to remember those strings, of course, because they are the keys. So you can think basically of the player presses as a dictionary, a fence dictionary that actually saves this onto a, onto the disk, onto the file. Then to read get this, we can do. So interrupt integer XP, player, player prefs, player prefs dot, get into in this case. So getInt is done way you pass the key in and then you get to the actual value. You can also do a second thing where you can put in a default value. So if this is not found, then you basically get out the default value. This is simply to fail-safe that if for whatever reason your things are not set, then you can actually do it like this. So let's copy this over a few times as well. Mp XP and then the card index. And we had a one of 1500 for the MP and the XP was 2500. So we're going to change that as well. Is 0 for the card indexes will open up like that. Card index the ego. So now that we also have the basic default values, just in case that those don't exist. Because maybe what happens is that we click the load data button and actually the data has not been set yet. So that would be very good. And then play a data set player data. And then in there we can put in the HP, the MPI XP, and at the card index. And that was it for the saving and loading. We now only need to hook up at the two buttons there. And that would be it. So we only have to do the save button on click, Add listener. And then in there we can simply call safe player prefs dot save data. And in the same token, copying this, we can say the Load button. We want to load data. And the player prefs, safe player prefs have been set with the find object of type. So that should be set. This will do as well. So this could be extracted into another method. We're going to keep this in there for now. But overall, I believe that this should actually be everything that we need. Do. You know, there's some more things. So this onload method, we could probably recall this to populating the text. There's a lot of things that we can change out to make this a little bit more readable. But overall, this is going to be fine. And let's see if we can actually save and load data. So that would be very cool and very interesting. So we're going to start this for now, and then we're going to just select a nice the king. Then we're going to have something like 12000 and then we'll have a lot of there and then something like this for the EXP. And then let's hit the Save Data button. Nothing happened, which is actually pretty good because, you know, if, if there is an error, then we probably would have heard about it. And then let's just exit out of it and then all know, all my data is lost. I don't know. I don't know what we had in here, like 30000. Let's click the load data button and see if that works. And it did. So that's pretty cool. One of the things that right now did not update is the HP texts, the texts and the XP texts here. So that's something that you would also need to think about. Because if we were to change the actual card here, this would change back because this is reading out from those all the time. So that is one of the thing that is very important to think about, that you actually have to. I'm also makes sure that those are saved as well and that they change with it. So that what you could basically do in theory, which could basically do is you can simply call the load method each time that you do this. So basically what you simply do is instead of just giving it the one method, we can put in a curly bracket here and a curly bracket here. And then make sure that you don't forget the semicolon and then say on load. So now the onload method is being called each time you say click the Save button. And then we can basically do the same thing for the Load button as well. So make this one, and then we can say load. And then if the onload is called, of course, then we will always reset our inputs to exactly this. And this should then be totally fine. So let's see if that works now. The data should still be saved because it was saved before. So let's look at this load data. And as you can see now, all of this data has been set as well. And then if we change the card, then nothing here changes again. That's the last sort of fixed that you would need to implement in order for this to work. And then I can change this to something else. 99, 99, something like that. And then, you know, I don't know, something like that. And if I save this again, and now, I will change everything, right? Something like this. And then we're going to go to another card. And if I were to load now, everything changes back to exactly the data that I have saved just before. Right? So that was a very roundabout way of showing how you can save data. I wanted to make this in a little bit more, let's say style in a little bit nicer and something that you actually have that so that you can play around with it. Regardless of if you took the if you already imported the package and played around with it like that, or if you programmed along, understand that this is a little bit more complicated, even though the actual saving itself, as you can clearly see, is very, very easy to do. This is not some crazy thing. It is just two methods when basically just the set method and then the getMethod that we do on the player prefs. And yeah, that would be the saving. But I wanted to have the whole thing around it because next lecture, what we're going to look at is saving data with basically Jason with JSON files. And that is going to be a little bit more complicated, however, is a number one going to be way more robust? And number two, it is actually going to allow us to save entire classes instead of just saving integers, floats, and strings. Which is kind of important, especially if you really are working with a big project. Then integers, floats, and strings might get you a little for. But at some point you're going to be like, man, I just don't want to set this also the player prefs are not the best idea to save everything in there. Those are, It's better to basically save. So as you can see, it stores player preferences between game sessions. As the name suggests, it's more or less better to save sort of, you know, your preferences for your player in there. So maybe options, that is a good idea to save in the player prefs. And then beyond that, it's probably not, it is definitely not recommended to save any vital data in there. It is way better to save that in your own JSON file and then maybe even your own file format, but that is way too advanced adjacent file for us right now at the next lecture is going to suffice very much so it's going to be more than enough. That would be it for this lecture. Like I said, it was a little bit more extensive. The saving itself. Fairly easy. But yeah, that would be it for this one. Like always. If you enjoyed it and if you learn something new, I would of course very much appreciate a review from you. Otherwise, if questions remain, then of course, feel free to ask and I'll be sure to respond. And yeah. 88. (Unity Intermediate) Saving (Custom) Data with JSON Files: All right, let's continue the intermediate unity introduction here for the unity course. And in this lecture we're going to take a look at how to save data in a JSON file. The last time, we basically set up our nice little example here, as well as safety data with the player prefs in this case. And now we're going to sort of add onto this and basically have the data saved in a JSON file instead of the player prefs. So first of all, let's create a new scene. This is going to be actually now not a new scene. We're actually going to take the L6 player prefs, sorry, and then Control D to duplicate them. And this is going to be L8, Jason. And then inside of the scripts folder, a new folder, and that is L8 saving with JSON or just Jason, that's fine as well. And then the new script here, and we're going to call this the Jason loader. Because it is going to be a loner that loads Jason Wright. And now let's also open the Jason is seen here and then switch over the safe data. So we're going to basically remove the player prefs safe script from there and add the JSON loader script there. And then we will open the Jason lower script as well as we also need the UI Manager and the player data. This is the other two that we also need because we need to change a few things in there about actually not that many. So in the player data, we will actually add System.out serializable at the top of the class. This simply enables us to convert this class data into a, into a JSON file, so to speak. So that's, that's the idea they are. And the second thing in the UI Manager that we need to do is actually not too bad. We want to add a, another private variable here, and that would be a private Jason loader called the JSON loader. Let's call it like that. That's actually, and that's okay, That's fine. And this will be set to here. So this would be the JSON loader is equal to GameObject dot find object of type Jason loader. And that would be fine. And then instead of doing the following, so instead of saving and loading with the player prefs, what we're going to do is we're going to say, okay, if the player prefs are not null. So if it has found in the current scene a, an object with the safe player prefs. Then we will do this. And if that is not the case, we're going to look if the trace and loader is unequal to null on equal null. And if that's the case, then we're going to do something else. Then we're going to basically hold the JSON loader dot save data. So let's open the JSON loader file here. And we're actually going to keep this being a mono behavior because we've already attached it. And we need once again at the player data here, layer data as a variable. This of course, can be very easily gotten with player data dot instance. And then just like with the player prefs, we're actually going to have a public voyage, safe data and a public void. Public void load data. Nope, not that one, but load data methods. So this, if you have seen this and then also the player prefs C-Sharp class that we've made. You might say, well, we have a safe data and load data on both of those. Couldn't we make an interface for that? Yes, that is exactly right. That would be one of the, one of the ways that you could also do this. So you could probably set up an interface for each of them. Sort of have this like a saved data or an IA, IA data save or something like that, that would probably work as well. But in our case right now, we don't need to do that. We just want to know, okay, how can we actually save this into our adjacent and we can do this? First of all, what we need is we need to use the System.out.print Joe namespace as well. Because that's the namespace which we, which we can write and read data. Right now in our save data method, what we're going to do is we're going to define a string called adjacent. And then we're going to use the Jason utility class to basically convert an object into a JSON. So as you can see, we can put in an object as a parameter and convert that into a JSON representation. So just for a quick clarification, adjacent is a JavaScript object notation. Now don't let that fool you. It's, it doesn't have to be only used in JavaScript, is just sort of a way that you can store data fairly efficiently and basically read it and write it. So what we're gonna do is we're actually going to log this JSON string and actually see what it does. And then what we can do is we will also log a particular path. So of course, we're soon going to basically use the stream writer, which we've already used in the C-sharp introduction. And this one is going to be saving something in particular, in a particular directory. And the way that we can do this is by using application data, datapath. So this is basically the datapath. Then we can use half old directory separator. Now this might seem crazy. What are you doing there? Then the last one is going to be saved data dot JSON. And the idea is that, well, the datapath, as you can see, is always directly to the game folder. So this is a direct path to the Assets folder. And this old separator is basically. Well, what you need. So either a slash gray backslash because sometimes depending on what type of system you are on, whether or not you're on a Linux, Mac, or PC. So Windows, that this might be different. This is why a path dot old directory separator character is probably best to use here. So let's first of all actually just have this be output here on a safe instead of actually having it basically saves something, just so that we can do this. So let us copy over basically the listening here at listener and then change the safe player settings to Jason loader, and then the JSON lower as well. And this should absolutely work, totally fine. Now, let us see whether or not this has actually worked. So if we will go in here and we are going to change a few things. So for example, in old age, this change the numbers here just a little bit. And then if we hit Save data, we should see some output. And we actually do so HB is five, what does that 5 million, yeah, and then 24 thousand for MP a 100 and 33 for XP. And then the cart index is 18. And then you also see exactly where it would save the adjacent file. And that would be exactly inside of our assets folder here. So that's pretty good. And we can now add the functionality. I'll actually saving it as well. So how would we save it? Well, we're going to be using the, using keyword once again with the stream writer in this case. So this is going to be the writer and that is equal to a new stream writer for a particular directory in this case, and that is exactly the directory that we have specified here. I just wanted to output this because that's kinda nice. And then we're going to do this. And then while this happens, actually, we don't actually need to do anything crazy here. Writer, dot-dot-dot, right? And then we're just going to give it the actual adjacent string that we have here. Because the adjacent the Dacian utility has already converted our object or a player data objects to a string. We've seen that in the output. And we don't necessarily need to output the datapath anymore. And then for the load data is actually exactly the same just the other way around. So we're going to have a string, Jason, that is going to be a, a string dot empties on empty string. And then we're going to be using the stream reader. In this case, reader equals new stream reader. Now of course, making sure that this is exactly the same location here. So there might be some sense or some interest in actually saving this datapath as a string variable inside of your loader as a, as a string, like I said, where it's going to not do that at this point, but it might be a good idea. And then we're simply going to say Reader dot to end and save that inside of our JSON string. Now we have basically exactly the same JSON string. Read back out like we have in here. But now we of course need to sort of make a new player data for that. And we're going to do a player data. Data is equal to Jason util dot from JSON. And then inside of here, inside of our And angular brackets are angled brackets. We actually specify what we want as returns. So this is going to be the player data. And then inside of there is going to go at the actual string. And then what we're going to do is we're going to say player data, set, player data. So this is the actual data that we have in here. This would be a new instance of this. And usually what we would do is do a data, data.table P and then data.dat AMP, and then data.txt. And then last but not least, data.dat card index. And then the actual player data has been set again. Now we could of course, also think of maybe making another set player data method where we actually give it a another layer data instance here and do it like that. But right now this will, of course, completely suffice and it will work totally fine. So let's actually see whether or not this will work. So the first thing of course being storing this and I'm just tracing around a little bit. Let's do something like that. And then let's do like 1990 and then let's do like 420. Sure why not? And then let's click the safe Data button. All right. So that seemed to have worked. So 17 for 20, 30, 45, and 1990. And then I actually look inside of our project folder so we don't see anything right now. Let's do a right-click refresh. And let's see, there it is, safe db.json. So let's double-click that. And it has actually opened inside of Notepad Plus, Plus. That's a little bit unfortunate. But you can actually see it here as well. Each before 2013, 45, 1990, and 17 is the cart and neck, so that has been saved. And if we were to stop this and then restart it, you'll see that if I loaded the data, and as you can see, everything works totally fine. And this is actually as easy as switching this out, right? Of course, there's a point of saying, well, maybe we don't wanna do it like this. Maybe we want to do it with an interface or something like that. I think that that would overly complicated. We have already have a quite complicated construct over here for the entire saving apparatus, so to speak. And I think that will definitely be fine. But yeah, it's basically the same save data and load data methods that we call. And this simply saves the data to a, to a JSON file. Now I do actually wanted to show you the actual file as a inside of the actual project. Just a second. I'm going to do show in Explorer. So this is another folder on my other screen. And then I'm going to simply drag that in there. Let me see. There you go, and there you go. So this is how the JSON file actually looks. So the formatting is not the best, but right now, I would personally say, don't really worry about the formatting for now. The most important thing is that you can still read it. If you have more complex classes, then of course it's going to get more complex. You know, if you have lists, then this is going to look a little bit different. And yeah, but overall, that is that. And yeah, that is how you can load and save data with a, with JSON files basically, uh, using the adjacent util that comes with Unity itself, and that would be it. So those are basically the two lectures on how to save the, let's say three lectures on how to save your data. I would definitely say that the adjacent loader, while it is a little bit more complicated, definitely, I would say use that. It's way more robust, it's way better. And using the player prefs is okay. But it will lead to only headaches because the player prefs really are not the, not the real source or relocation way you should save data that is important to the program. So save files definitely be done by Jason or you could also do them on your own, make your own sort of a bit wise thing, but that is way too advanced at the moment. Right now. Jason is definitely where it is at, right? And that would be it for this lecture. Once again, I hope you found it useful and you'll learn something new. If something remains unclear, then of course, don't hesitate to ask a question and I'll be sure to respond. And yeah. 89. (Unity Intermediate) Using TileSets: All right, let's continue with the Unity intermediate section here for the unity course. And in this lecture we're going to take a look at a tile sets. So tile sets are basically a way in which you can sort of make a two-dimensional landscape. And that is going to be really easy. So let's actually just create a new scene and let's just take a look at what all of this has in store. So L9 tile sets. We don't need a new folder inside of a scripts folder because we actually don't need that. Whoever would we do need is a new folder inside of our assets folder. And that is going to be the tiles, tiles sets folder. And then we're going to make even one more in that one. So another sub folder, and that is going to be called just the title set underscore one, just so that we have a name to that. And we're going to import the tile map PNG. This is once again one of the kenny assets. Of course, number 1 as a link and then number two as a resource as well. Let's change the compression to numb filter mode point. And then pixels per unit is going to be 16 as well as putting the sprite mode to multiple. And then we're going to say Apply. And then what is very important is that what we want is we want to go into the Sprite Editor here. And we want to slice this, slice this automatically. I believe that that should be fine, but I actually think that by the cell size is better. So this should be 16 by 16 if I'm not mistaken, let's see 16 by 16. And then he could see that they are always separated by one pixel. So what we want is we want 16 by 16 and then the offset should be 11. So let's slice this and see, oh, no, that's 64 by 64, that's not right. Revert this revert here. Slice 16 by 16, offset 11, slice that. And then the offset is actually the wrong way round. So we actually want, do we want the padding here? That is a very weird way of saying that. Okay, So I guess that it's a padding for the Sprite Editor. I actually thought that the padding would be the one from the, well, the edges. But apparently it's not. So they go to slice this 16 by 16 and then padding 1 and 1. And then every one of those should also work out very well. Each one of those is now a separate well sprite and we will be able to use that as a talented. Now the apply here might take a little while because those are 485 different sprites. As you can see, it's sort of a cityscape here with a few green and sort of building sprites as well. And if that is done, then let us actually go to our tile set scene here, and let's see what we can do. So what we can do is right-click on the hierarchy. On 2D objects, we have the tile map. We are going to make a rectangle is higher matters also hexagonal with a pointed top and then flat top. There's also asymmetric and then isometric Z2, Z0 as y. That would also work. But we are going to look at normal tile maps in rectangular fashion. If I can get that to work, they go rectangular. So then a grid will appear inside of your scene view, as well as a two basic game objects, a grid gameObject with a cell size as well as a gap, gap, and then a tile map underneath it. And those are the two things that will basically appear they are now. Now how can we change this? If we go down here to the open tile palette, then we're actually going to get a new window appear, that is this one. And instead of there we currently have no active tile map. And it says create a new tile map. And we're actually not going to create one. We're actually going to take our town of Sprite and just drag it in here. Well, we actually do have to create a new one story and then we're going to drag it in there, of course. So this is going to be, let's just call this tile, tile city tile set. City tiles set. That's fine. They are rectangular. Grid size is going to be automatic and then the sorting mode is also going to be fine. So let's create that. And this is going to be created inside of a tile sets and mental set underscore one. As you can see, this is cool to see, digitize it. And now we can drag in a spread, a spike. And then we're going to do that. We're going to save this at exact, in exactly the same folder here. And this is going to take awhile because it is going to basically convert each of these sprites into a sort of a tile in this case. So it's going to, like I said, take awhile. Depending on how fast your computer is, it might take a little bit longer or a little bit shorter. And then everything is important here. So if we now look at sort of a tile sets, tile set, underscore one folder, then you can see that there's a tile map 64. And up here you can actually see what sprite this is. And those are basically all of the sprites now as tile map, sort of individual parts. And you can now take those and draw with them. So let's position our tile map window like sort of here. And what can we do? Well, if we, for example, select this, then you use, you can see this is sort of select highlighted here. And it should paint with the paint brush. And if I go here, then you can see what is this? Well, I can now paint to this. So if I now hold the left mouse button and I can actually paint this. And I can paint in, well the basic tiles here. So that's pretty cool actually that, that works just like that. And the other buttons that are important, of course, there is a selection of the grid, so I can basically select something here. And that way I could be able to basically move it, I believe as well. So this is what we, this one remove selection exactly. So I can basically select this, change, the Move tool and then I can move this around. So that's pretty cool. I also have different types of painting mode. So there's of course, the one single brush painting mode. There's also the, this is the box filled mode. So with this I can basically draw a box. And this will then draw a box around it. So with the tile that is selected, I can also select multiple tiles by the way. So I could, could, for example, say this so I can drag, and then I have four tiles that are being selected here. And then I can put that down as an example. And then I can select this tile, take the draw, and then do something like that. That would work. And I can take the edge, for example, something like this, sorry, something like this. Make sure that if you have multiple ones selected that you switch back to the actual brush. Otherwise with multiple ones selected. And the box, it is going to be a little weird as you can see. It still works. But yeah, now we've actually made a mistake. Oh no, I don't want that here. What we can do is we can just take the eraser tool here and erase that. Now because we have two tiled selected, the eraser tool is also two tiles thick or big. And if we only have one selected and the size will get set to one. There's also a fill tool. Now, this is could also be useful. Maybe if we're like, I, actually, I actually don't want this to be green. I actually want this to be sort of concrete or I want this to be sort of this concrete that you go and then it is going to fill that as well. So that works out very well. So that's pretty cool already. Now. Maybe, oh man, baby, what we want is we want a street, right? So we're like, Okay, let's actually build a street. Let's see if we can do this. So this is by the way, a middle mouse button and right mouse button can move around. And then with the left mouse button you can basically select things. I hear we have some street rest of asphalt here. And so we could, for example say, well, let's actually take this asphalt and let's make a street like right in the middle here. Actually, I'm making sure that we also select this. Let's make a street here in the middle. That's pretty cool. And then all we could also have sort of this solids or we can actually add this as well. There you go. And then we can do this. And then let's add all, yeah, and then now we all know we have minimum stake. We're going to also do Control Z, of course, to do this, or we can of course paint over it or do that on all. Let's also put one of those in here. So that's pretty cool. Now we can actually cross this. And well, maybe what we have here is also a no, Maybe this is that that doesn't quite work. So let's see. What about, okay? So as you can see, sometimes It's kind of a little bit harder to do this, but you can see this one is actually really good for the corner they are. And then you can make a corner put in as well here, and then continue with this. Along. There you go. So there's a lot of things that you can do with this. And of course, this is now sort of an active example of a particular tile set. But you can see that after a little bit, it also already takes a little bit of form. And let's say, Well actually, what I really want is I really want a sort of benzene, this green area, but that is kind of not very good, right? So now the bench is, well, the Mencius sort of sitting in space. So that's not very nice. Exactly. Let's actually Control Z to get back here. And, and the reason for that is because we are right now using this tile map that is right here. And the idea is that, well that's just not enough. We actually need more. So what we want is we don't actually want to edit this. What we want is we actually want another tile map that is below this. So what we could do is we can basically simply say, okay, let us just take this tile map and then we're going to just control a deed duplicated and then call the other one, for example, base. So now and move this up. Personally prefer that. And then say negative one, actually move it down because. Oh, but make sure that it's below the grid. That's very important. So this one is down and then we have maybe something like the middle. And then we duplicate that one again. And then we have something at the top, which is going to be order one. Right? And now we have a three different layers. And now if we look at the active tile map, we can actually see that we can choose different ones here. So first of all, right, now the data on all of them is going to be the same. So let's actually do the following. Let's actually delete everything we can. Make it like a big one. The leading, there you go. So now the base layer is deleted. Let's go to the top layer. The top layer is deleted. And now if I were to do this, now the middle layer is deleted. Let's see. Now everything is gone. So I can change the selection with doing this year, top, middle and base. Or if I go back to having the, there you go. So now the base has something in it and also change it right here. So top, base and a middle. And now because we have set the order in layer, which we've already seen inside of amine numerous occasions, especially inside of the script. I'm sorry, the sprite renderer. Yeah, there you go. We know that well, this orders the actual sprites. If I now want to add this bench, as you can see now it is overlaid on top of the base layer because we are now in the middle layer. If we switch back to the base layer, as you can see, would override that base layer. But in the middle layer, it does not override it. And we can just simply add this nice bench year, maybe two benches, and then also maybe add a nice little tree as well. So we can, for example, take this one and then just add a tree here and H3 here for example. And then let's just finish this just so that it kinda looks a little bit nicer. So that we have, I'm a nicely ordered sort of green area with two benches and a tree here. And then on there. We can also have this and then have a nice little area they are as well. There you go. This one, this one. And then let's finish it with the top part as well. And now we have two areas. Now as you can see, what have we done? Well, we've actually made a full part because we've done this all in the middle layer, which is of course not quite what we wanted. All of that should have gone into the base layer. So it's a real pain is that we can't really change this. Sadly, what we can do is we can basically why we are selecting this and then also holding Control down. So control and then selecting it will actually sort of make it so that we can paint it as you can see. Then we can switch to the base layer. We can paint it on the base layer. And then on the middle layer, we would have to once again delete it. It's a little yeah, it's not very good that that works. How that works, but that is sadly how we're going to do it. There's no real way of changing the layers they are. And also what I wanted to mention, while I'm calling this layers, Unity calls on this tile maps. Absolutely confusing language like that is, I think that that's not a very good language because for whatever reason, you know, this is a tile set. So this is a title set and then this is the tile map as well. So this is called Telnet because I quote The My, let's see, sprites here, tile map. But I would definitely refer to this as layers. So those are different layers that you can put on top of each other. Tile map, I think is not the right term there. And yeah, let's actually then do the same here as well. So let's copy this one. And that's actually copying the base layer. We actually wanted to copy this. Now, the big issues that all know, now what we've done is they're also the trees there. So this is one thing that I sort of wanted to mention as well. It sometimes can happen that you are a, you have the wrong layer selected and then you have to redo this. I would definitely recommend making sure that you are on the right layer like this is one of the most important things if you're working with this. Because otherwise it's just going to lead to a lot of headaches. And it can be in the beginning, you know, a little bit tedious, a little bit kind of kind of rough. Oh no, I'm on the wrong layer again. It's just bound to happen at some time and that is just how it's going to be. So let's just add a few trees here, maybe another tree they are, they you go. And then we have our map finished. It's not the nicest map at the moment, but of course we can do some cool things with that. One of the examples of that would be, let's see. So if you actually download this and you're going to get another map and I'm going to quickly show you that as well. So that is, so it's sort of a little bit of a sneak peek into another map that I've made. Just a exactly for this. And that is going, and that's also something that we are going to be using next lecture as well. And that looks something like this. So that is the other map that I've made which, you know, that's pretty cool. All things considered, you know, we have a few people even if you cars, a few benches. And then we might have some we don't really have any top for the buildings at this case, but just flat. But who knows, maybe this is sort of a sound stage. But yeah, that is one of the examples that I've made as well that is available for download, which we're also going to be using in the next lecture as well. So, yeah, that would be it for this lecture right now, uh, with the tile sets, there really is no. It's just your creativity is basically what stops you from doing anything. At the tools there are really useful, really great, and can be used for all sorts of other things. And yeah, that is, is basically for this lecture for the moment. I hope you've found this useful and you'll learn something new. Tile maps, a great Sue tool sets and trial maps, a great tool to basically create your own levels. Receive any questions, remain, then of course, feel free to ask and I'll be sure to respond. And yeah. 90. (Unity Intermediate) Animation Basics: All right, let's continue the unity intermediate section here for the unity course. And in this lecture we're going to take a quick look at animations and how to do animations. So first things first, with our new map that you of course can get for the resource. Especially in this lecture. There should be a resource for the package where just the new tile set is located. And also of course, the tile set itself and then the sprites associated with it. If you want that, you don't necessarily need to have that. Your own tiles that would work as well. Or your old tile map, maybe even the one that we use before. It's just sort of a nice show visually when we're looking at our animations now. So let us duplicate this title map and let's do 10 animations. So let's rename that to L ten animations and also start that. And then we're going to import a new sprite. That of course is also available. This will be the adventurous bright. So this is there. And first of all, that will need to be changed a little bit. We will need to actually not too much, I think only point and then no compression here. And then of course multiple because those are multiple again. Then let's go into the Sprite Editor. Let me just quickly get this over here they go. And the size of those is 80 by 110. And then let's slice this up and as you can see, fits in perfectly there. And then we have the size for each of those. And what we're going to do is we're basically going to make a short little walk animation as well as an idle animation. So those are not going to be too crazy. However, they will be semi functional at least let's say, and then we're going to see what this entails. So let's apply this. So once again, we have the adventurer and all of the particular Multiple sprites below it. And then we actually need to specific windows. We need the animation here, Animation Window. And this open on another screen. We can simply put that in here. And then we also need animation and the animator window. And I also personally put this in here so that I have basically the animator and the animation window down here directly where the console is. And the first thing that we can do is basically, well, we can select a different pictures here. Let's actually put this one up so that we can actually see which picture this is. And the animation is basically going to switch between 02 here. It's not the best idle animation for this particular thing. What I think that, that, that actually works out fine and I especially like the crazy wonky look on this face. So that's actually pretty funny. So what you can do is what we've learned is if you just take one picture in there, so one sprite, then it just creates a game object. However, if we do too, so we select two sprites here. So by, for example, Bye. Selecting one of them and then pressing Control and then the other, we can select two different ones. And if I pull that one into the scene view, then as you can see, a new window here opens. It says create new animation because in this case, it actually wants us to create a new animation. And that's what we're going to do in sort of our animations folder. We're going to call this the player or let's call this the adventitia, raw adventure. Adventure at ventral idle. Because this is the idle animation. And let's save this. And now a whole bunch of stuff has been done for us. So if we go to our animations folder, you can see that the adventure underscore 0, an animation controller has been created as well as the adventurer idle animation clip. And the animation clip is what is very interesting to us and what we will be able to see in the animator, for example, if we select our adventure here is a, yeah, Well, sort of a summary of our animations that we have. And each of those boxes basically. So there's some different special boxes, the entry, this is sort of where it always enters. There is any state, so any state that the actual animation and animation can take. And then there's an extra note as well. And the idea is that what we want to define in this animator is basically the transitions between different states. So you can, for example, imagine this. If I'm standing still right now. So right now it's standing still. And then we play the animation, right? And then he, I don't know, sways from left to right and left, right. And then from this island nation, maybe I can either jump or I can walk. And then the, we can basically say, okay, we have an idle animation, we have a walk animation, and maybe even a jump animation. And then we want to define different transitions like this, right, right-clicking and then making a transition there. Now we're not gonna do that right now because we actually are going to make the second animation in just a little while. But all of these nodes, so each one of these nodes, each one of these animations has basically a timeline, you're connected with it. So if I were to click on the adventure idol here, then you see inside of the animation window, we now get this timeline. And this timeline currently changes. A one thing. So maybe you have worked with, you know, maybe Premiere Pro or some other video editing program or maybe you've seen pictures of it. This is basically where we can define keyframes. And the idea being that we can sort of add things to this animation that allows us to basically change certain things. So if I select our adventure romance again, then you can see I have this adventure idle clip now selected. And currently what is changing is the sprite. So as you can see at the moment 000, the sprite is this. And then if I move this along, then the sprite changes to this at the next second. Now if I were to play this, then as you can see, this is how the island nation would look at is of course, way too fast, right? Because it's only two frames long. And that would be not too good. So we can zoom out with just a mouse scrolling down. And we can look around here with the middle mouse button and then we can take one of those keyframes. So for example, this one, the second. Picture here. And we can drag it over to be, for example, something like, well, let's say five frames. So if I were to play this clip now as you can see, now, he would take in and stay for about one frame. But that of course, also isn't quite what I want, right? Because now this particular one is only shown for about a frame and then it returns to the other one. So that might not be what we want. What we want is maybe that it stays like this for a little while, longer. And well, how can we achieve that? Well, maybe for example, we take this and then we can, by the way, copy of something, so Control C. And then if I go for example to here, I can put in control V and paste it in. And now in theory, let's say I put it right here. So now it would stay there for a number of frames. So this would be another six frames, I guess. And let's look at this right now. Now it would look like this. And that's way more like a Island animation. Now it's not the best idle animation. Like I said, it's a little wonky, but it will suffice for now so that we have anything at all. So that's kind of a nice thing. Now you could, of course, make this way, way faster or slower like that. You could make this a little more or less depending on what you would want to do, right? We could drag this year or make this a little slower or faster. There is, of course up to you once again, I'm just providing the tools. What you do with them is sort of up to you. But what we can do now is also at other properties. So if I put it on the other properties, you can see that basically there are, I think all of them, or at least certain components are available here for me to change. As you can see, basically everything I can change inside of the sprite renderer. And then I could also, in theory, change things in the transform for an animation. And this is a really cool thing. So you can change certain things as a function of time when an animation plays. Now changing the transform is sometimes a little bit not too good. I just wanted to mention that because it can have wonky effects, especially if you're changing the position with some other stuff. So usually you should be careful about that, except if you were to have sort of the visual component of a particular game object be different from the actual position. So if you have sort of a, I'm a child and a parent game object, then there might be a way where this would work. Yeah, and then let's actually take a look at the other one. So the other through the walking animation that I would want is going to be also two different ones. This is going to be nine and 10, I believe. So nine and 10, That's the walking animation that I want to put in. And there's multiple ways that we can do it. Either we can also drag that in or the Y would not recommend that what I would recommend is simply going here and saying Create New Clip. And then we're going to say at Ventura. Walk and save that as well. And now if I select this adventure again and the adventure, a walk is here, and then I can basically drag over our individual sprites. I could also say at property sprite renderer and then say sprite plus. So now the sprite will change. Then I'll put in the nine here and then the 10 as well. We don't want that one. We actually are going to keep it like this. So actually, I also don't want him to stand and then it changes to walking. I actually want them to start with the walk and then change to this one. And then change into the walking stance again. So something like that. So let's see how that one would look. Well, that's, that's pretty much a walking animation already. A little bit too fast, so let's make it a little bit slower, maybe something like that. So 15 frames. Now that would be probably fine. And that would already work fairly well. So let's save that for now. And then we're actually going to get something from a very old, a very old lecture here. And that is going to be the movement script. So we're actually going to go to Scripts, Create New Folder, Elton animations. That is going to be the movements scripts, right? Let's get the movement script over here. And let's see. It's just going to reload for a moment and then they would go, Let's open that as well. And let's quickly add that to our adventurer as well. There you go. At the movement script there. Let me quickly get this over here and then we can take a look at this. So this simply allows us to move our character, and now we're actually going to add another component here. So another field then that is going to be the animator. This is the Animator. Now luckily, because this is on the same game object, we can simply say this dot get component animator. So that's actually really easy. And then what we're going to do is we're going to do the following. So when we are inside of our, um, basically move method. And then later in the indirection, what I want is I want to sort of set a speed component as well as I want to flip the visual components. So if I write now, if I were to just start this, what is going to happen is the following. It is going to go. If yep, There we go. Now started, he's just going to have the idle animation and now I can walk but the idle animation still place, which of course, that's not quite what I want. The reason why the idle animation plays. If I go to the animator, as you can see, the entry point is where we start. And then we have a transition to the adventure idol here. And then nothing towards the walk animation. We don't know when we should walk animation should be played. Therefore, we don't actually do anything here. And well, how can we fix that? How can we make certain things play? Well, we can make certain things played by doing the following. We can define parameters and that is to the left here. Instead of selecting players, we can select parameters. And those parameters are basically, well, they can be of different types. So float and integer, a bull or a trigger. We're going to select a float in this case, and this float is going to be speed. So this is the speed at which this character moves. And depending on the speed, we are going to either transition to the walk animation or we are going to transition back. So that's basically the idea there. So let's right-click the adventure idol here and make transition and then move it towards the adventure, a walk. And if we now click on this little arrow, you can see there's a few things here and we can either even see a preview. So this one should walk and then it switches to a walking animation. Now, this is not quite what we want. We can also sort of expand the settings here. And this is sort of a, this is a transition duration here. So we're basically looking at a transition from one to the other. Now what I personally think is we don't actually want an extra time and we also don't want a transition here. We actually just want him to basically change over. And let's see what this one says. This is doesn't have any extra time. Yes. We don't have any condition put in there yet. This is why we are getting this warning here. We're going to put in a conditional soon enough. So no exit time and no, well, no exit time and no duration. And now we actually have to specify a condition. So if we don't have an extra time, then we have to have a condition. And the condition is going to be speed is going to be, I mean, I guess just greater than 0.01. That's actually all that I want. 0.1. Let's do 0, 0, 1, the ego. So that's all that, really one. So as soon as the speed is more than one, then I want the ILO animation too, a crossover to the walk animation. And then I can also say, well, if we're in the walk animation, maybe at some point I want to go back to the island emission. So if I basically stopped moving, and this will basically happen if I go in here and once again, I go into the, I put off the extra time and no fixed duration, no transition for the duration. Actually, sorry, fixed ration is correct, but no transition duration there. Then once again, I get the warning a, I need a condition and this is simply going to be speed is less than 0.01. And that would be it for them. So as soon as we set the speed, then we can basically control in what animation our character finds itself it. Now, this speed doesn't necessarily have to correlate perfectly with our speed that the player actually has. So we will now be able to set the speed in a particular way. So if we look at the following, so what we can do is when we are inside of our move method. So this could be put in anywhere. But if we are, let's just do the following. Let's actually just do this. So inside of our animator, in the beginning, animator dot set float. Speed is going to be 0 f. So this is as simple as this goes. So we simply have the name of the actual variable as well as then what, wherever we set it to. Now we're setting this at the start, and then we're also setting this. For example, if we move in any direction. Now the thing about it is that we could of course, set this to the specific direction we're moving. So we could say, Hey, we want this to be whatever the direction is, times the speed. And then so it has a negative speed. We move into the, to the left and then the positive if you move to the right and so on and so forth, we're not gonna do that. We're just going to set it to itself right now so that it is positive when we move. And then we of course also have to reset it somehow so that this works as well. So while this one works in the beginning, it kinda doesn't work in later down the line. So what we probably want is we would probably want this to be called inside of the update method. And yeah, so that this happens. And when we're not moving, however, where we want this to be set at the beginning here, so that it doesn't interfere with anything. Now there's multiple ways, of course, once again, where we could do this with. We could, for example, say, well maybe if I'm not moving, then we set the and set the speed to 0. Also like this speed could also be set to 0, something like that. But this is going to be fine. This is going to work. And then there's also going to be private void flip visual, which we're already going to implement. So this is the direction here, no direction. This is what I want to call it. And let's not put anything in there right now because I will show you why we will need this in just a moment. But in this, with this setup, without the flipping, the visual, this should actually already work totally fine. So let's see if that actually is the case. So sometimes it can also be useful because right now we have the animator and the animations in our movement script as well. Sometimes it could be better if we actually separate those, but it is not strictly necessary. So right now we are in the island nation. Everything is working very well. And if I move myself and as you can see, we have transitioned immediately to the walk animation. Now, we are sort of Moonwalking here. Let me just maximize this so we can actually see what's going on. So we can walk. And then if I walk to the left that no, we are moonwalking. So we're working at the sort of, you know, behind us, which is of course not quite what we want. This is why I said that we can flip the x value here and then we simply flip the sprite renderer over. And this is what we're going to do with this flip method here. The flip visual simply going to say this dot get component sprite renderer. Flip x is equal to direction dot x is smaller than 0. So the flip x is simply a bool. And y-direction is, well, either going to be one or 0. And if it is, Yeah, exactly because the moving left, then this is negative one. So then yes, it is below 0. Therefore, flip x is going to be true, and otherwise it is going to be false. So now here, flip visual direction that you go. Of course, to be frank, the best thing to do here is of course also to say do this private sprite renderer. Sprite renderer up. Actually set this up here because let's, let's do it properly, how it is supposed to be done. Otherwise, why even bother with it? There you go. Sprite renderer dot flip x. And now everything is fine. So don't do the get component called right here. As I've said numerous times. And now it should flip the visual if we are moving to the left. And now we should actually have a fairly well workable animation. So the elimination, like I said, is not the best, but if we are moving to the right, that works. And if we're moving to the left, that also works. And then it also flips the image around. And the great thing about this is that it also stays there. So that is sort of one way that you could do this. Now if I move up or down, then the actual image will rotate back to the right. But that is a very minor thing that actually should be fixable very easily, right? And yeah, that would actually be it for the idea of the animations. So there's a lot more, of course, once again, to be done in animations, right? Like usual, these are very cursory glances of a lot of systems because he has so many systems to offer. It's really hard because, I mean, each of the systems could probably be its own course in its own right. I mean, most of them, I'm just thinking back about the particle system once again. So this is sort of a first look at the animations. There are incredible things that can be done with it and the tool is incredibly powerful, like you have seen. There are so many things that you can change with the animation here, as well as the animator offers you so many things to be done. And the best thing, like I said, that I can leave you with once again, is to just try out everything that you will sort of think about. So any, let your creativity run completely wild and just try out a few things and see if you can get something to work. And yeah, just just play around with it. That is always a great idea. And that would actually be it for the animation at this point. Like always, I hope you found this useful and you learn something new. I would very much appreciate a review from you. And if they remain any questions, of course, always feel free to ask and I'll be sure to respond. And yeah. 91. (Unity Intermediate) Scriptable Objects: All right, let's continue with the Unity intermediate section here for the unity course. And in this lecture, we're going to take a look at scriptable objects. Scriptable objects are a specific type of data container. So there are a way of storing data that is independent of a particular class basically. And what does that mean? Well, we're going to take a look at that. And for that we're going to create a new scene. Of course, this will be L 11 scriptable objects. There you go. So let's open that scene up. And then we're also going to make a new scripts folder. This is going to be L 11 script able objects. Now we're going to need two scripts for this one, this is going to be the C-sharp script, play card, play card. And then another C Sharp script. Let's actually close out of all of those. And then let's make another one. And this is going to be the play card script able object. Now you can also call this click art. So I think calling it play chords, scriptable objects, objects is actually wrong. Let's actually delete that again and make this scriptable objects. Because that is a better name. Scriptable objects would be a little bit weird to have it be named in the plural. So Play Card, play card, script, able up, eject. There you go. And that would be fine. So let's open each of those. So the play card and the scriptable objects. And then we can think or to ourselves, well, what could a play card half? So in our example, what we would want is we want a sort of a card name and maybe, you could imagine maybe HB and amount of value. So something that would be akin to sort of a playing card in, I don't like Magic The Gathering or Hearthstone or something like that. And the first thing that we're going to do is we're going to, instead of inheriting from motor behavior, we're going to inherit from scriptable objects here. And this will basically allow us to create something really nice and cool. And the next thing that we want here is above the public class, we actually want the brackets here and inside there we want to create Asset menu, file name equals play cards. So this is the, basically the name of the file name that we're going to create and then the menu name is going to be Palais card. We're going to look at what that does in a little while. First of all, let's think about this. So the data that we want to display court scriptable objects to have is, for example, a name, so card name. We want there to be a, an integer, for example, HP and a card manner. So let's do MP, actually called MPI and then also maybe change the sprite. So this would be a card sprite that could also be saved in sort of this scriptable objects. So that's all fine and well, but what does that give us? What does that do for us right now? Well, right now it doesn't. A whole lot for us, but what we can do now, and that is going to be like a really cool thing. We can right-click on our folder. And then we can go to the Create menu. And at the very top you'll see, oh, what is this? Play card is a new thing that we can add now. And this will add a scriptable objects. As you can see, this is a play called scriptable objects. And we can now change this to whatever we want. So for example, we can say, well, ace, ace of hearts is the name of the card. For example, you could say, well this has 10 HB and 25 manner. And then we can also add a card sprite here. So we can go down to our courts, for example, and then just simply add the court 0 because that is the ace of hearts. And yet now we actually have a new card. So let's call this ace of hearts as well. So this would be one of the possible data objects that the actual object can take. So let us also build ourselves a nice lieu of an object which with which we can basically sort of visualize this. So we're just gonna take the chord 0 here and we're going to call this the play card. And then we're going to add a canvas to it. So we're actually, let's just add the text Mesh Pro to it. And this canvas then will actually be in world space this time. I know this is absolutely crazy, of course, still with the main camera. And we will then also have two located at that and make it a little bit very much smaller. So let's make it a 100 by a 100 for now. Same with the text that is going to be a little bit smaller. Let's make the text a little bit smaller here for now. And then let's reduce the size. And then we can figure this out. So actually let's also just scale this down a little bit. Let's make this 0.5.5. And our starting to get to where we want it to be, 0.5.05.05. Now there we go. Alright, so now the Canvas 000 is at the size that we want to. Then we can put the text up here. And then we can actually make it bigger again, at least a little bit. There you go. So that would be fine. I think that if we let's make it auto size, that actually didn't quite work how I wanted it to text auto size. What is the minimum size there? That's probably the reason why it didn't work. There you go. It's 18, of course, make this 10. Then it's going to be at there. So this is the card name that we want. We want this basically sort of at the sides of the card like that and then will be the card name. That's fine. Actually, that could be even a little bit smaller. So this could even be, let's say an eight. Then also centroid. So that's kinda nice. And then we can basically copy this over, for example, down here, just so that we have it. We can make the HP and the manner of value something here and then here. And then of course, making sure that we actually rename this, so this card name text, Let's call it like that. Yes, this is the chord text and this is the card AMP texts for example. And so this would be, let's just put in a, you know, something like ten here. And a 10 here. Just have something in there. Yeah, That would be it. So of course, when we are in the game, the gizmos would be turned off. So this is what we would see for this card. So that's pretty cool. And now basically what we will do is we will first of all attached to the actual play chord scripts to it. So our script that we've made not the scriptable objects, but the moral behavior which we've not actually changed yet and will be what it is. Basically we can, we will be able to put in data. They are so a different scriptable objects, one of the ones we've already created, so let's just, for the hell of it, create another colleague card here. And that's going to be for the king of hearts. And the king of hearts. That's going to be like sort of a pretty, of course, first of all, king of hearts, the name of the card and then this is going to be like 25, about a 150 manner. And the king of hearts is the 12th year, so that's pretty good. So let's go back to king of hearts the 12th. Let's drag this over. And now we have two examples. So the ace of hearts and the king of hearts. And now of course, we still need to add the functionality for the lake heart itself, of course. And that is going to look something like this. The first thing that we're going to have is a private play card, scriptable objects, play chord script object does the court data, of course, right, so this is the data of the specific chord that is being displayed. Let's just add a serialized field to it so that we can basically set it with, you know, in the constructor. And then we will also have using t, using tmp row. We're going to have a private TMP, txt, TMP texts. There you go. There's going to be the card name text. And then let's copy this. We also have a, an HP text to HP text. And then let's also do an empty text. Let's also serialize those just though we can see what they are up to basically. Now those can be, of course, also set via the start method. But we're actually going to do that inside of the constructor as well. And then what we can say is that basically will private void set, set cards to basically cards data. That's a method that we're going to call. And then inside of there we're going to say get component sprite renderer. And we're cause we're only going to do this once in the store method. We're actually not going to need to be able to catch this, So that's going to be fine. And I'm going to say cord name text. The text is, text actually is equal to the card data, taught the dot coordinate. And then let's just copy this over the HP texts here. Simply equal to card data dot-dot-dot court HP and MP text is equal to card mp. Now this is of course toString because those are integer values here and they have to be set to string. And then we can basically call onStart the set card to card data. And we could, for example, also have in theory a do, do an update method and have an input dot. Keydown, keycode.edu for update, for example. And then also call this method they are. And then basically update what to whatever data we have put in there. So this should actually already work very well. So let's see. First of all, we of course have to set the texts here, so name text, HP and MP text. And then also give it one of our scriptable objects. Let's put in the king of hearts first. So then this should change. So let's just start the scene or soft the game. As you can see, king of hearts, the king of hearts, bright shows up with 25 HB and a 150 manner. Now if we were to switch out the ace of hearts and repressed you, then it will update to our new card. Of course, in theory, we could do is something like a if the actual data changes, then we might be able to update the visuals as well. But that is also not quite necessary. And yeah, and now basically we can just create new play cards here. So for example, we can do the queen of clubs if I can find the queen of clubs. So that's going to be an interesting one. So I believe that that was clubs. So queen of clubs for P53, I believe. So. Queen of clubs, where is it There? It is 53. Let's add that there as the sprite. And this is the queen of clubs. And this would have like maybe 65 HB and a 140 MP. So that's like really strong card. And the great thing is then, now I can simply switch this out here. And as soon as I start up, the data is loaded in. Now in this case, it's a little bit too big, but that's okay. That's not an issue. That is something that we can very easily fixed. So they are, an auto size would probably be better. So we can basically do overwrite it with an auto size and say, well actually, let's do a minimum of six and a maximum of 15, something like that. And as soon as we do that, even then, when the actual name is too big, it will still work very well. So that's really cool. So that's like one of the sort of things that you can do with scriptable objects. And in the future, we're actually going to see a good application for scriptable objects where we actually have multiple types of enemies with that. So scriptable objects really nice to stores like huge amounts of data in so to speak. And yet they are now, we can basically have multiple of those objects here, store different types of data. And with that, they are basically independent of any class. And yeah, that would be for the scriptable objects lecture. Like I said, a proper application we're going to see when we make our next game. But that will be it for this lecture. I once again hope you found it useful and you learn something new. If there are any questions, like always, feel free to ask and I'll be should respond. And yeah.