 In episode 1.1, I'm going to be teaching you how to make a data class to separate your player's variables such as money, upgrade levels, stuff like that, and I'll be teaching you guys what classes are. And in the previous episode, I showed you guys how to make something basic like this. Cool. Hello, guys, it's CryptoGround here. Welcome back to another Unity idle game tutorial video. This is the 2021 edition and this is episode 1.1. If you enjoyed this video, make sure you smash the like button to show some support, comment your feedback, questions, all that good stuff below, spam those comments. Subscribe to my channel if you're new and turn on the bell for future notifications of videos and live streams. Anyways, let's just get straight into this. So last time we made a script called controller and I explained how we were going to make a different one for our data. Let's do that. So what we're going to do is right click scripts, go to create and click C sharp script. And I'm just going to call this something very basic called data. Now you can just call this game data, whatever you'd like. So this will just be called data. So we're going to open up the script here. And we're going to actually keep these things at the top here because we will need them in the future. However, we won't need anything related to start or update. And we can get rid of this mono behavior because we're not going to be using any Unity engine stuff. So this class is purely for storing data, just that and also be used for a full reset. So in here we have a variable called flash. So we're actually going to get rid of this and we're going to keep this red error for now. Now in our data, we're going to actually move this back here. So we're going to recreate this double variable called flash. Now we're going to make something called a constructor. It basically defines all the data that we assign it to in data. So if we create a constructor, all we gotta do is type public data, and then parentheses. And in here, we're just going to set flash equal to zero. So by default, when we create our data class, we're going to make a flash equals zero by default. Now we can make it equal 10, we can make it all this large number, we can make it equal whatever we want. But we want to start as zero. So now on full reset, I'll show you guys how to do that in the future. But it's basically just creating a brand new data class. And I'm going to show you guys that in a second. So our data is fine. It's good to go. Let's head back to our controller. So in order to access the flash now, we're going to create an object. So now the difference between an object and a variable, an object is base, it's basically a class, but it's a set of variables within an object. So if we do public data data like this, so again, we can call this whatever we'd like, data is our class. And we're basically just storing it inside data here. So now if we do flash instead, we can do data dot flash. Okay, so now we're accessing flash from data here. Now we're not accessing directly. So we can actually have multiple instances of these. So if we just copy and paste this and rename this to data two, we now have two completely different sets of it. So if we change data dot flash, but not data two dot flash, and you try to show the difference between these two. So let's say, let me show you guys an example here. So what we're going to do is we're going to set data dot flask equal to 10 for example, but we're going to leave data two dot flask. Okay, so now what this should show is 10 flasks, and then a new line, zero flasks. Okay, so these are two completely different objects. Okay, so I'm going to show you guys that actually I need to comment this out. Commenting is basically where the code just doesn't reach it. It's good for taking notes or explaining what things are. You just do the double forward slash. Okay, so now if we press play, okay. So when I press play, the one thing you're going to get is a new reference exception. So to fix this, we actually need to create a new data. So this is what I mean by creating a new object. So we're going to create a new method called start. Now this is also unities as well. And this will be called at the very start of the game. However, there's another one called awake, which is called before start. Okay, so we're going to do data equals new data. And same thing with to data to equals new data. So the full reset is literally doing this exact same thing, data to or data equals new data is literally the exact same thing, which is very nice about actually having a data class like this. So now we should not get this no reference error, which means it doesn't exist. Okay, so now you can see we have 10 flasks and zero flasks as we try to do this here. So now you should understand that this is just basically creating a copy of the original data class. So I'm going to get rid of all this and keep everything like this. So now in order to change data dot flash, we need to do the same thing, data dot flash plus equals one, and it should still function like normal. Nice. Okay, Crypto ground. So you explain the benefits of having a class and creating a data class separately. And you also explain how to access them, how to create different types of them. Well, you never actually explained what a class is. My apologies. So what is a class? So a class is basically an object where you can have different variables inside of it. So again, we have our controller class here. It's basically where all of our predefined code exists. Now, if you ever want to create a public void, start or an update in order to get something to run, or if you want to create variables, it must be done inside of a class. Now you can find tons of complex definitions on there like on the Microsoft docs. So basically explains what declaring classes are, which is what we did before creating objects, which is exactly what we did with the new data. And you can do the same thing by creating an object variable with the type data. That's basically how you say it. So when we're creating a new data here, we're basically saying, okay, we're going to set our variable data here equal to a new data object, which is this right here. I hope that makes sense. Basically, if you want to think of it a different way, you can just say that a class is like a blueprint. Okay, if you want to have like a school, okay, what does a school have? It has classrooms, it has the amount of number of students, number of teachers, stuff like that. I have a crash course on this on C sharp. If you're interested, you can browse on my channel and you can find an episode on classes. And I explained pretty much very detailed on what they are. Okay, so in this episode, we created a data class and I explained what they are. I think that's it for this one. If you learned something new, make sure you smash that like button. It really supports the channel. Subscribe to my channel if you're new. And anyways, I hope you guys have a great day and night. Shout out to my Patreons and YouTube members. If you guys are interested in joining as well, check out the join button below the video. And also check out my Patreon in the description below. Anyways, I'll catch you guys in episode 1.2, which will be on explaining what access modifiers are, which is what public and private is. Anyways, thank you guys for watching. Peace.