Cookie Clicker Clone

For my Cookie Clicker Clone prototype, my intentions where to think outside the box and explore how a well known game such as Cookie Clicker, could be adapted.

In order to achieve this, I created a Cookie Clicker Clone called Grass Cutter. It has the same basic principles as Cookie Clicker but where it differs is that each second the number of grass increases and the player’s objective is to get that number to zero.

An excellent Unity feature is the ability to reference a UI element such as a text box in a script, and then connect it in Unity by dragging it into the reference. In the clicking script, I referenced the text box that displays the amount of grass left. I also created two floats (a more precise integer) for the number of the counter and the amount of grass subtracted each click.

In the “void Start()” function, I set the number of grass to 2000. Putting it in the Start function is essential as it sets the counter to 2000 as soon as the game starts.

In the same script, in the Update function it is checking if the counter number is greater than zero. If it is, the amount of grass is displayed. However, if the counter is less than or equal to zero, then the player has won and a congratulations message is displayed.

This could be improved by creating a winning screen that displayed the time it took the player to beat the game, rather than just changing the counter text to tell the player they have won.

For the per click upgrade which increases the amount of grass cut each time it is bought, I created a PurchaseUpgrade function. This function contains an if statement that checks if the player has enough money to buy the upgrade. It also increases the price of the upgrade each time it is bought.

This is done by the Mathf built in class that allowed me to use a variety of maths functions, in this case – rounding. This is another positive feature of Unity, as it allowed me to quickly and efficiently use maths in my code, rather than having to write a huge block of code for the current price to be rounded.

The UpdateText function updates the description for the per click upgrade each time it is bought. The function is called in the built in Unity function OnMouseEnter. This, alongside the OnMouseExit function, are useful built in functions as they allowed me to code UI elements such as text boxes to only be seen when the player hovers the mouse over a specific button.

This script automatically increases the grass counter by one every second. In this script I have used a coroutine. A coroutine is like a function but with the ability to pause the execution. This was useful in creating my game as the coroutine returns the yield after pausing for one second. To start a coroutine I needed to use IEnumerator.

This script is identical to my AutoGrower script, however, it decreases the amount of grass – unlike the other script which increased it.

This is the script for my second upgrade which automatically decreases the amount of grass. I have referenced the AutoCutter script alongside the Clicking and MakeMoney scripts. This is a very useful function when coding for Unity games as it allows you to access functions and variables that were created in other scripts.

in the Start function, I have set the nextCuttingPerSec variable to -1, which is later added to the decrease amount that was declared in the AutoCutter script. This essentially means that each time you buy the upgrade it decreases the amount of grass by one each second.

One problem with this is that when you buy the upgrade for the first time, it stops the grass increasing but it does not decrease it. This is because the decreaseAmount and increaseAmount variables are -1 and 1 respectively at that moment in time. To fix this, I could write an if statement declaring that on the first time buying this upgrade the decrease amount is set to -2 and after that goes down by one every time it is bought.

This script controls the coins that are gained with each click. At the moment, coins are only gained by clicking the cut grass button. This is a potential issue as when upgrades start costing hundreds of coins, the player has to click the button that many times.

To fix this issue, I could implement another upgrade that automatically increases the amount of coins you have once every second. This would also fix the issue of only having two upgrades. With a larger variety of upgrades, it would keep the player interested in the game for much longer.

The main negative of Unity is how awkward it can be to build the game. For my first build the game would not run when uploaded to itch.io. After researching and seeing that many others had the same issue, I found that the solution was to turn the compression off by going to the player settings. This allowed the game to run perfectly fine on itch.io.

LINK TO MY GAME : https://ethanconyers.itch.io/grass-cutter

Leave a Reply

Your email address will not be published. Required fields are marked *