# How To Make an INCREMENTAL Game In UNITY 2026

## Метаданные

- **Канал:** Blackthornprod
- **YouTube:** https://www.youtube.com/watch?v=Fm0YlZ8QAxI
- **Дата:** 20.05.2026
- **Длительность:** 41:25
- **Просмотры:** 4,905
- **Источник:** https://ekstraktznaniy.ru/video/51781

## Описание

Get The Project Files: https://www.blackthornprod.school/how-to-make-a-incremental-game

In this video, we will guide you step by step to making a complete incremental style video game using Unity and C#.

## Транскрипт

### Segment 1 (00:00 - 05:00) []

Welcome back to this Blackthorn Prod tutorial. In this video, I'm going to show you how to create a very simple but fully functional 2D incremental video game inside of Unity. By the end of this video, you will have a game where you could chop down trees to gain gold during a resource collection phase and then use that gold in a upgrade tree to make chopping down trees even more efficient. If you want to follow along with this video and use the same sprites as I will be using, we've prepared a complete free little Unity package. You can go ahead and download using the link in the description. Once you have it installed, just create a brand new Unity 2D project. Drag and drop the Unity package into the asset folder, import everything, and then open up the tutorial scene. All right, let's go. Okay, so step one to make our incremental game is to spawn our trees on our game area. So, I'm going to right click inside of the hierarchy and I'm going to create a new empty game object that I will call tree spawner. Then, I'm going to go inside of the scripts folder and I'm going to create a brand new C model behavior script that I will call tree spawner. Once it has been created, I'll drag and drop the script onto my tree spawner empty game object. Now, we can double click on the script to open it up inside of Visual Studios. At the very top of the script, I'll start by making the variables I need. Let's make a private game object array called tree prefabs, which will simply store all of our different tree prefabs. Then, we'll make a private transform array called spawn points, which will store all of the positions where we'll want our tree prefabs to spawn at. Finally, I'll make a private int variable called number of trees. This variable will dictate how many trees do we want to go ahead and spawn. We want all three of these variables to be accessible from within Unity. So I will add the serialize field tag in front of each one. Now that we have all the variables we need, let's make a private void function called spawn trees. The first thing we will do is create a list of transforms called available points. That will just be equal to a new list of transforms. And in between the parenthesis, we'll pass in our spawn points array. So, we've just made a list containing all of our spawn points. And we're making a list so that we can remove spawn points whenever we spawn a tree to avoid us from spawning a tree twice at the same spawn point position. Next, let's make a simple for loop. So, I equals Z to start off. And let's continue to loop as long as I is less than our number of trees variable. Each time we go through the loop, we'll increment our variable I by one. Inside of this loop, the first thing we want to do is to pick a random spawn position. So I'll make a int variable called random index that I will set equal to random. range between zero and available points. celt. Then right after this I'll make a transform variable called random points that will just be equal to our available points list with an index of random index. Okay. So thanks to these two lines of code, we've retrieved a random spawn points. Now we can simply spawn in a tree prefab at the spawn points. Let's now get a random tree prefab. So I'll make a game object variable called random tree prefab that I will set equal to my tree prefabs array with an index of random. range between zero and tree prefabs. length. So to spawn in an object, I'll use the instantiate function. And inside of this function, we need to first pass in the prefab we want to spawn. Then the position at which we want to spawn it at. And finally the rotation. So for the prefab, I'll put our random tree prefab variable. For the position, we'll use our random point. position. And for the rotation, we can use our random point. And finally, once we've finished spawning in our tree, we can simply remove the spawn point we just spawned our tree at, so that we make sure two trees never spawn at the same position. We could do so by saying available points dot remove at and just pass in our random index. Great. Now that we have this cool function that spawns in trees for us, we can simply come inside of the start function and call spawn trees. We can save the script and go back to Unity. Let's select our tree spawner game object and fill in our variables. So, we could come to the top right of the inspector and click on this lock icon to lock the inspector. And now, simply drag and drop all of our tree prefabs into the tree prefab slots. Then, we can expand the game area and you'll find a

### Segment 2 (05:00 - 10:00) [5:00]

bunch of empty gil checks called spawn points. Let's simply shift select all of them and drag them all inside of the spawn points array. Finally, I'll set number of trees to let's say five. Pressing play, you'll see that five beautiful trees are spawning in at random areas on our game area. Excellent. Now, just don't forget to unlock the inspector by pressing on the lock icon once again. Okay, let's move on to step number two in creating our incremental game, which is just about creating a health system for our trees and enabling us to deal damage to them to chop them down. So, I'll go inside of the scripts folder and I'll rightclick and make a new C monoBehavior script called tree. Once it has been created, I'll go ahead and select my tree prefab and I'll go to add component and search for my tree script and add it there. Now, let's double click on the script to open it up inside of our text editor. In here, I'll just make a serialized field private int variable called health that I will set to 100. Then we're going to make a public void function called take damage that'll taken as a parameter a int variable called damage amount. Inside of this function, we will simply decrement the health variable by the damage amount parameter. After that, we'll just check with an if statement if health is less than or equal to zero. And if that's the case, then we could call the pickup function. Let's go ahead and quickly make this private void pickup function which will just destroy this game object. Okay, we can then save the script and go back to Unity. Now that we have that, we can move on to step number three, which is all about using this health system we made to actually go ahead and deal damage to the trees within a certain radius. So, I'll right click in the hierarchy and I'll make a new empty G object called tree chopping. Then I'll go inside of the scripts folder and I'll make a new C# model behavior script called tree chopping. Once it has been created, I'll drag and drop it onto the tree chopping empty game object. Let's now open it up. In here, I will start off by making all the variables I need. So a serialized fields private float variable called radius which will control the radius in which trees will be chopped. Then let's make a serialized field private int variable called damage per chop. So as the name suggests this variable will control how much damage we want to deal to a tree whenever we perform a chop. Then let's make another serialized field private float variable. This time called time between chops. So this variable will dictate how often do we want to perform a new chop. And finally we will just make a private float variable called chop timer. This variable will simply be used to track when is the next time we want to perform a new chop. Let's also make a serialized field private transform variable called chop radius visual. Let's start off by making our visual radius the same size as our radius variable. And let's make it follow the mouse cursor around. So inside of the start function, we'll set our chop radius visual. lo scale to be equal to vector 3. 1 multiplied by our radius variable and multiplied by two to get the diameter. We can also hide the default cursor by saying cursor. visisible visible equals false. Then inside of the update function, we want to update the position of our chop radius visual so that it follows the mouse cursor around. Let's first of all make a little private vector 2 function called get mouse position which will be in charge of returning our current mouse position. To do so, I'll make a vector 2 variable called mouse screen position that will be equal to mouse. currens. position. position dot read value. This will retrieve our mouse's current screen position. Now we just need to convert this screen position into a world position. So underneath this line, I'll make another vector 2 variable called this time mouse world position. And to convert a screen position into a world position, we simply need to call the camera. main. creentoorld point function and pass in our mouse screen position variable. Now we can simply return our mouse world position

### Segment 3 (10:00 - 15:00) [10:00]

variable. Now back to the update function, we can set chop radius visual. position to be equal to our get mouse position variable. We can now save the script and go back to Unity. Let's quickly fill in these variables. So, I'll set the radius to one. I'll set damage per chop to 35 and time between chops to 0. 75. Let's also drag and drop the chop radius visual inside of this slot. Pressing play, we can see that the chop radius visual is correctly being resized and it's following our mouse cursor around. Awesome. Okay, now let's deal damage to all the trees that are within the radius. Okay, so now inside of the update function, we're going to make our simple timer system. So I will increment our chop timer variable by time. delta time, which will just increase our chop timer using real time. Then we will check using an if statement if the chop timer variable is greater than or equal to our time between chops variable. If that's the case, then we want to reset chop timer back to zero. And then we want to call a function called damage all trees in radius. Let's now go and make this private void damage all trees in radius variable. Before we fill in this function, let's make another function that will retrieve all the trees within our radius. So I'll make a private list of trees function called get trees in radius. So this function will be in charge of detecting all the trees that are inside the chop radius and return them out of the function. I'm going to make a collider 2D array called colliders that we'll set equal to physics 2D overlap circle all and we'll pass in our get mouse position function as well as our radius. So this overlap circle all function is going to cast an invisible detection radius at our mouse's position with a radius of radius size variable. Any game object with a collider that is within this radius will get added to the collider array. Now we would only like to have tree prefabs get added to the colliders array, not any game object. So we can come up to the top of the script and create a serialized field private layer mask variable called tree layer mask. And we can pass in this layer mask as a third parameter in the overlap circle function. Layer mask will just let us choose a layer so that our overlap circle will only detect objects with that specific layer attached to them. Now that we have retrieved all the tree prefabs that are within our radius, I'm going to make a list of trees. So a list of that tree script we made in step two called trees and it will be equal to a new list of trees. Then I'm going to loop through all of the colliders that are inside of the colliders array by using a for each loop. Each time we go through the loop, we'll retrieve the tree script that is attached to it by creating a tree variable called tree and setting it equal to collider. get component tree. And then we'll add this tree to our trees list by saying trees. add and passing in tree. Then we could come out of this loop and simply return our trees list. Perfect. So now that we have this function that retrieves all of the trees that are within our radius, we could come back to the damage all trees in radius function. In here we will loop through the trees in range using a for each loop. So for each tree in get trees in radius. For each tree we will simply call tree. take damage which is the function we made in step two. And we will pass in our damage per chop variable. Okay, we can now save our script and go back to Unity. Let's select one of our tree prefabs and let's come up to the layer dropdown and let's create a brand new layer called tree. Once it has been created, I will shift select all of my tree prefabs and that will attach to them this tree layer. Now we can select our tree chopping object and we can select the tree layer inside of the layer mask. Pressing play, you'll see that after a little bit of time, our trees that are within our ridges are getting destroyed. So, we know it's working correctly. Awesome. Okay, let's move on to step number four, which is to add a little bit of game juice and feedback to make the chopping of trees feel much better, which is a very important part of these incremental style games. Inside of each tree prefab

### Segment 4 (15:00 - 20:00) [15:00]

we have this axe game object, which at the moment has his sprite renderer deactivated. We want to go ahead and activate and deactivate the ax sprite renderer depending on if the tree is inside of the chop radius. To do so, I'm going to first go inside of the tree script. Inside of it, I'm going to make a serialized field private game object variable called X. We're also going to make a private sprite renderer variable called X renderer. Inside of the start function, I will set X renderer to be equal to X dot get component sprite renderer. Now let's make a public void function called set X visible and it will take in as a parameter a bool called visible. All this function will do is set ax renderer. enabled enabled to be equal to the visible bool. So if we set visible to false then it will hide the sprite renderer and if we set it equal to true it will show the sprite renderer. Let's also wrap this line of code inside of an if statement that checks if x renderer is not equal to null which will just make sure we don't get any bugs later on. Now let's go back to the tree chopping script. In here, I'm going to make a private list of trees called active trees. And I'll set it equal to a new list of trees. This list will be in charge of storing the trees that we are currently chopping down. And so the ones that we want the axe to be active on. So now I'm going to make a update axis function that will be in charge of activating the axis on the trees that are within the radius. So first of all, we want to hide all the axes on all trees that were currently active. So I'll loop through all the active trees using a for each loop and we will say tree setx visible to false. Then outside of this loop, we will clear out our list so that we start with a fresh clean list. So active trees do clear. Now let's loop through all the trees in the regious by saying for each tree in get trees in regious. regious I'll set tree setx visible to true and we'll add the tree to the active tree list by saying active trees do add tree. Let's now simply call our update access function inside of the update function. Okay, so now we can save the script and go back to Unity. Now we just simply double click on a tree prefab and make sure to drag and drop the X into this new X slot. Then just repeat this process for every tree prefab. Pressing play, you'll now see that whenever the tree is within the chopping radius, the ax is getting shown and when it leaves a radius, it's getting hidden. Perfect. Now, whenever we deal damage to a tree, we want to play the chop animation on the axe. So, back inside of the tree script, I'm going to make a private animator variable called Xanom. Inside of the start function, we'll set Xanom to be equal to X dot get component of type animator. Great. We now have access to the animator component on the X. Now, simply inside of the take damage function, we will say X do set trigger chop. And this will make the chop animation play. If we save the script and go back to Unity and press play, you'll see that a chop animation is playing each time our tree takes damage. Now, you will notice a little problem, and that's that the last chop animation is not getting played since the tree is getting dealt the last damage and getting destroyed before the animation has the time to play. So, let's quickly fix that by using a cor routine. So I'm going to make a I enumerator corine called take damage sequence they'll taken as a parameter a int called damage amount. A cool routine is simply a function where we can pause the execution of it during a certain amount of time which is exactly what we want to do. We want to first play the chop animation then pause for a little bit of time before actually dealing the damage to the tree. So let's select all the code from the take damage function and cut it and paste it inside the cor routine. After this chop animation line of code, I'll use the yield return new wait for seconds line of code to pause for a certain amount of time before running the rest of the codes. I'll put in 0. 2 fc. Now, inside of the take damage function, we can simply call the cor routine by saying start corine take damage sequence and let's pass in the damage amount

### Segment 5 (20:00 - 25:00) [20:00]

parameter. Let's add more feedback by playing a shake animation on the tree and also by spawning a little particle effect each time we deal damage to the tree. So, I'll create a serialized field private game object variable called chop effects. And we will also make a private animator variable called enm. Inside of the start function, we will set the enm variable to be equal to the animator component that is attached to the tree by using get component animator. So now after we've waited for the 0. 2 seconds, we will perform the animation by saying anim set trigger shake and we will spawn in the particle effect by saying instantiate chop effect at the treere's current position. So transform. position and at the tre's current rotation. So transform. rotation. So let's save the script and go back to Unity. Now we can shift select all of our tree prefabs. And make sure to drag and drop the chop effect into the chop effect slots. Pressing play. You'll now see that the chopping feels much better already with just a tiny bit of feedback and game juice. You can of course take it much further by adding sound effects, screen shake and so on, but for the purpose of this tutorial, we'll just keep it nice and simple. Okay, step five is to add gold to our gold counter each time we completely chop down a tree. And we'll also want to update our gold UI. So, I'm going to right click in the hierarchy and create a new empty G object called resource manager. Then once I've made this empty G object, I'm going to go inside of the scripts folder and I'll create a new model behavior script called resource manager. Once the script has been created, I'll drag and drop it onto the resource manager game object. Let's double click on the script to open it up. In here, I'm simply going to make a public int variable called gold, as well as a serialized field private int variable called tree value. This variable will dictate how much gold we should earn whenever we fully chop down a tree. Now, we're going to make a public void function called add gold. All this function will do is increment our gold variable by the tree value amount. Now, we're going to create a serialized field private tmp_ext variable called gold display. Make sure to add in the top of the script using tmp raw. Then right after we increment our gold variable, we will update the UI text by saying gold display. ext equals gold. 2 string. Okay, awesome. Now we simply need to call this add gold function whenever we fully chop down a tree. So let's go inside of the tree script. I'm going to make a private resource manager variable called resource manager. Inside of the start function, we will set resource manager to be equal to find first object by type resource manager. This line of code will search our scene for an object that has the resource manager script attached to it and it will store that script inside of our resource manager variable since we now have access to it from within the script. So now we can come down to the pickup function and right before we destroy the tree we can say resource manager do add gold. Okay, perfect. So now let's save the script and head over back to Unity. Let's not forget to select our resource manager and I'll put 10 for the tree value. Let's then drag and drop the gold text into the gold display slot. Pressing play, we can now see that whenever a tree has been chopped down, we are increasing our gold counter. Amazing. Okay, step six is to now add a simple timer for our resource collecting session. Once the timer reaches zero, we want to have the choice to either start a new resource collecting session or open up the upgrade panel. So, I'm going to go inside of the tree chopping scripts. In here, I'm going to make a serialized field float variable called session time. As the name suggests, this variable will be in charge of controlling how long a resource collecting session will last. We're also going to make a private float variable called current session time, which will be in charge of storing the current time left in the current session. We'll also make a serialized field private tmp_ext variable called timer display. And don't forget to add using tmp raw at the top of the script. Let's go ahead and make a private void function called start session. Inside of this function, we'll set our current session time variable to be equal to the session time variable.

### Segment 6 (25:00 - 30:00) [25:00]

And we'll update timer display. ext to be equal to mathf. round current session time dotto string. So rounding the current session time and then converting that into a string. Then inside of the update function at the very top, we can decrement our current session time with time dot delta time to decrease the timer over time. And we'll update the UI text by using this same line of code as up here. Now before everything, we will make an if statement that checks if current session time is less than or equal to zero. If that's the case, then it means that our current session time is over and we want to stop picking up resources. So we will simply say return to return out of the function, meaning that all of the code after this will stop running, which is exactly what we want to enable us to stop collecting resources. Now let's simply call our start session function at the bottom of the start function. Okay, we can save the script and go back to Unity. Let's select the tree chopping script and I'll set session time to 10. And let's also drag and drop the timer display inside of this slot. Pressing play, we'll now see that we have a nice little timer. And as soon as it reaches zero, we can no longer pick any resources. Perfect. Okay. Next, we want to activate the session end panel, which contains two buttons. One to start a new session and one to open up the upgrade panel. So inside of the tree chopping script, I'm going to make another serialized field private game object variable called session ends panel. We're then going to make a private void function called session end. This is the function we're going to call at the end of a session. Inside of this function, we'll simply say session end panel dot set active true to activate that panel. Now inside of the if statements that checks if current session time is less than or equal to zero, we will simply call our session end function. Then inside of the start session function, we'll make sure to hide the session end panel by saying set active false. We also want to go ahead and destroy all trees and spawn in new ones when we start a new session. So I'm going to create up here a private tree spawner variable called tree spawner. And inside of the start function at the very top we will set it equal to find first object by type tree spawner. Like that we now have access to the tree spawner script from within this script. Now at the top of the start session function we can simply call treespawner dospawn trees. Now you'll see we're getting a red error and that is because we need to go inside of the tree spawner script and we need to turn this spawn trees function public so that we can access it and call it from within the tree chopping script. Also at the top of this spawn tree function we want to go ahead and destroy all the current trees. To do so I'll create a tree array called all trees that I'll set equal to find objects by type tree. And in between parenthesis, we have to also type find object sort mode dotn none. So this line of code will scan our scene for all the game objects that have the tree script attached to them and it will add all those game objects inside of our tree array. Now we can simply loop through our array using a for each loop. So for each tree in all trees and we can simply destroy tree. game game objects to destroy the game object that has the tree script attached to it. We can now remove entirely the start function from the script since we will now be spawning in the trees entirely from within the tree chopping script when we start a new session. Back inside of the tree chopping script inside of session ends, we want to hide the chop radius visual by saying chop radiuses visual objects do set active false. And we want to reenable the cursor with cursor dovisible equals true. And of course in start session we will activate the radius visual with chop radius visual. gameobject dot set active true and hide the cursor with cursor. visisible equals false. Then we could copy this line of code that changes the scale of the chop radius. And we could paste it after we've enabled it here. We could then remove this line as well as the cursor. visisible visible equals true line from the start function since it's now getting taken care of inside the start session function. Lastly, let's make the start session function public so we could call it from the onclick events of buttons in Unity, which is what we're going to want to do. Now, let's save the script and go back to Unity. I'll now make sure to drag and drop the session end panel inside of

### Segment 7 (30:00 - 35:00) [30:00]

this slot on my tree chopping scripts. Let's also select the new session button which is inside the session end panel. Let's add a on click event to it by pressing this little plus sign. Then let's drag and drop the tree chopping script and search for the start session function inside of the tree chopping script. You'll now see that as soon as my session ends, my radius visual gets hidden, my cursor comes back and our session end panel gets activated. And if we click on new session, the panel and cursor get hidden. The visual radius comes back and new trees spawn. Amazing. The very final step to complete this little incremental video game is to work on the simple upgrades. The first thing we need to do is to be able to open up the upgrade panel. So I'll jump inside of the tree chopping script and I'll make a serialized field private gic variable called upgrade panel. Then I'm going to make a public void function called open upgrades which will simply set upgrades panel set active to true. Inside of the start session function, we'll also make sure to hide the upgrade panel in case it's open by saying upgrade panel set false. We can save the script and go back to let's now select the upgrade button. Click on the plus sign to add a onclick event to it. drag and drop the tree chopping script onto it and select the open upgrades function that's inside of the script. As we are at it, I'll also select the new session button that's inside of the upgrade panel. We'll also add a on click event to it. And we will drag and drop the tree chopping game object and find the new session function. Let's also select the tree chopping gear object and drag and drop the upgrade panel onto the upgrade panel slots. Great. We can now open up the upgrade panel at the end of a session. Let's now take care of the actual upgrades. So, I'm going to go inside of the scripts folder and I'm going to create a brand new model behavior script called upgrades. Once it has been created, I'll shift select all of my upgrade buttons that are inside of the upgrade panel and I will attach to them the upgrade script. Let's now double click on the scripts to open it up. We'll start off by creating a serialized field private string variable for the upgrades description. Then we'll make another cost. Next, we need a reference to the upgrade info G object that we want to activate when we hover over the button. So, I'll make a serialized field private gome object variable called upgrade info. We also need a tmp_ext upgrade info cost and description. Of course, make sure to import the using tmp raw name space. So now we want to activate the upgrade info g object and update the cost text and description text of it with the correct info from this upgrade whenever we hover over the button. So to be able to detect and run some codes when we hover over UI, we can use the I pointer enter handler and I pointer exit handlers. With those added, we now have access to the public void onpointer enter function as well as the public void onpinter exits that both take in as a prem the pointer event data called event data. So these are really useful functions that get automatically called by Unity whenever our cursor hovers over and hovers out of upgrade buttons. So inside of the onpointer exit, we will simply hide the upgrade info by saying upgrade info dot set active false. Inside of the onpointer enter, we will show the upgrade info by saying this time upgrade info do set active true. And after that we need to update the actual info getting displayed. So we will set upgrade info cost. ext to cost. 2 string and upgrade info description. ext to description. We can now save the script and go back to Unity. Let's shift select all of our upgrade buttons and let's drag and drop the upgrade info game object into the upgrade info slots. Then drag and drop the gold cost into the gold cost slots. And finally, the description into the description slot. I can select my first upgrade, set its cost to, let's say, 50, and put as a description plus one chop radius. Pressing play, you'll now see that when we hover over our upgrade button, our info is getting activated and updated with the info of the upgrade button we're currently hovering over. Excellent. Okay. Next, let's take care of what actually happens when we click on an upgrade to purchase it. So, back inside of the upgrade script, we're going to first of all get a bunch of

### Segment 8 (35:00 - 40:00) [35:00]

references to other scripts. I'll start off by creating a private resource manager variable called resource manager. We're going to need this to access our gold amounts. Then, I'll make a private tree chopping variable called tree chopping. We'll need this to apply upgrade effects to our chop radius, our session time, and our tree damage. Finally, I'll make a private tree spawner variable called tree spawner. We'll need this to apply a upgrade effect to our number of trees that spawn in the session. Okay. So then inside of the start function, we need to get a reference to each one. So I'll set resource manager to be equal to find first object by type resource manager. tree chopping tree chopping and finally tree spawner spawner. Now that we have all the references we need, we could come down here and create a public void function called on purchase. This is the function we're going to call when we click on the upgrade button. In here, the first thing that I want to check is if we have enough gold to get this upgrades. So I'll use an if statement and check if resource manager. g gold is greater than or equal to cost. If that's the case, then we want to go ahead and remove our cost from our gold. To do so, I'll go inside of my resource manager scripts and I'm going to quickly create a new public void function called remove gold that'll take in as a param a int called amount. This function will simply decrement our gold variable by our amount param. And then once that has been done, we will simply update our gold's UI by saying gold display. ext equals gold. 2 string. We can now save the script and go back to our upgrade script. And now we can use this resource manager remove gold function and we can pass in as a pram our cost variable. Okay. Next, we need to actually go ahead and apply our upgrade effect. For this tutorial, I'm going to add four very basic upgrades. increasing chopping radius, increasing session time, increasing damage per hit, and increasing the number of trees that spawn at the start of a session. So, I'm going to make a serialized field private int variable for each one. So, session time bonus, damage per chop bonus, tree spawn count bonus, and chop radius bonus. Then let's go inside of the tree chopping script. And let's make sure to turn the radius, damage per chop, and session time variables to public so we can access them from our upgrade scripts. Likewise, we'll go inside of the tree spawner script and we'll turn the number of trees variable public as well. Now, back to the upgrade script, we will say tree chopping. plus equals chop radius bonus. Tree chopping dot session time plus equals session time bonus. Tree chopping dot damage per chop plus equals damage per chop bonus. And finally, tree spawner dot number of trees plus equals tree spawn count bonus. All right, awesome. We also want to have the flexibility to activate new upgrades that we can purchase once we purchase an upgrade. So at the top here, I'll create a serialized field private game object array called upgrades to unlock. Then inside of the unpurchase function, we'll simply loop through all those upgrades to unlock using a for each loop. So for each gear object upgrades in upgrades to unlock and we will just say upgrades set active true. All right, awesome. One last thing, we want to keep track if we have purchased this upgrade or not. So that we can't purchase it multiple times. So I'll create a private bull variable called purchased. Then inside of the if statement where we check if we have enough gold, I'll add a double and sign and check if purchased equals false. So if we have enough gold and we haven't yet purchased this upgrade, then we could go ahead and purchase it. And inside the if statement, we will of course set purchase equal to true. Okay, we're all done. So, let's save the script and go back to Unity. So, I'll select my first upgrade. And as you can see based on the icon, this upgrade is meant to increase our chopping radius. So, I'll set the chop radiuses bonus to one. I also want to activate two other upgrades when I purchase it. So, I will drag and drop these two upgrades inside of the array. Lastly, I'll click on the plus sign and add a onclick event to this upgrade button. I'll then drag and drop the upgrade script into the slot and search for the on purchase function that's inside of the upgrade script. So then you just need to repeat this process for the other upgrade buttons, choosing each

### Segment 9 (40:00 - 41:00) [40:00]

time the upgrade cost, the description, the effects, and what other upgrades it unlocks. And also don't forget to add the onclick event. Drag and drop the upgrade script and find the on purchase function inside of it. All right, pressing play, we can enjoy our very simple but fully functional incremental game that has the full game loop of chopping down trees during our session to gain golds. Then going to the upgrade panel and using our gold to purchase upgrades, which unlocks even more upgrades. Then going back and chopping more trees even more efficiently thanks to the upgrades. and continuing this process until we max out our upgrade tree, for example. You now have a really solid base that you can expand on to create your own incremental style game or even just continue to expand on this one by designing a really large upgrade tree. For example, you could add regrowing of trees during a session, critical hits that can instantly chop down a tree. You can maybe purchase wood cutters to help chop down trees for you, and so on. The possibilities are endless. The biggest challenge then revolves around the balancing of the upgrade tree. So, what upgrades we can unlock and how much they cost. Thanks for watching. I really hope this helped you out. If it did, don't forget to hit the like button and subscribe so you don't miss out future tutorials. See you soon. Cheers.
