Game Programming in Unity! How To Make Cool Clicker Game!

I want to show people that it’s really not that hard to do game programming. But it takes Focus and dedication. In this tutorial that will be split up in many parts I want to show how you can create a clicker game. This is a 2D based game. We will be creating it in the game engine called Unity. Which allows you to create games for multiple platforms at the same time!

*Create a New Project


*Create a Canvas


*Main camera change background colour gray


*Canvas > UI > Button


*Create new Folder and Create C# Script Inside Folder


*Go to Button Add Component Click Script bind it to Button

*Add this code inside the C# script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Click : MonoBehaviour {

public UnityEngine.UI.Text goldDisplay;
public int gold = 0;
public int goldPerClick = 1;

void Update() {
goldDisplay.text = "Gold: " + gold;
}

public void Clicked() {
gold += goldPerClick;
}
}

What this code is doing the first part is including some default functions in Unity. Next we have our main class that we will work inside. Then we create a UI Text called goldDisplay that will be updated. We also need to store out gold and we do it inside an integer and start from 0.

Then we need to have an integer that shows how much gold should increase per click. Next we have an update function that will run to change the text element we created. First we will have some standard text but then we will include the integer for our gold. This one will always be updated.

Next we need to create a function that get’s run when we click the button. We call this function Clicked(). Inside it we just tell to update the current gold with our goldPerClick integer. Easy as that!

*In click script add the GoldDisplay to the new text element created

*On Click under runtime add Click and also add it under function to be run

*Try play in Unity and click the button now it should be updated everytime you click!

This is how it should look like:


Clicker Part 1 by phoneinf

Please follow and like us: