Clicker Game Tutorial Unity C#, Part 2 - androidgamestore.net

Clicker Game Tutorial Unity C#, Part 2

Simon Something
Views: 44619
Like: 635
Hi everyone! I want to thank everyone from the bottom of my heart, super cheesy I know but all this support has been really great and I’m so glad you’ve appreciated these tutorials they’ve been super fun to make.

In this tutorial we’re adding items that you can buy to increase our gold per second. In the next tutorial we’ll make the game a bit prettier with custom fonts, a background, and we’ll also change the look of our buttons slightly to give it a nicer look to it.

If you want to see more, show your appreciation by subscribing, liking the video, and leave a comment; I read every single one of them so if you need help with anything, just let me know 🙂

If you haven’t downloaded unity 4.6 you can get it here:

If you’re COMPLETELY new to Unity this might be helpful:

, although it’s not necessary if you follow the tutorial step by step.

Unity Documentation: (In the topright search bar just search for Coroutine for example)

Great tutorials on how loops work:

Thanks for watching!

84 Comments

  1. I changed the click power on one of my upgrades to a million to see how high my number can go and it went to like 7.062283E+08 will this be fixed later on should i deal with it now

  2. after i made my itemmanager script my items began to cost 0 after 1 upgrade??? why?

  3. From 19:03 to 19:15 what was that, that you have typed down it was public void ——>……………..<- since you are no longer zoomed in on the tutorial i can't see what it says very clearly :/

  4. need some help
    Severity Code Description Project File Line
    Error CS0116 A namespace cannot directly contain members such as fields or methods Assembly-CSharp D:UNITYUnity ProjectsclickerClickerAssetsScriptsIronPerSec.cs 29
    Error CS0103 The name 'ipsDisplay' does not exist in the current context Assembly-CSharp D:UNITYUnity ProjectsclickerClickerAssetsScriptsIronPerSec.cs 25
    Error CS0103 The name 'GetIronPerSecond' does not exist in the current context Assembly-CSharp D:UNITYUnity ProjectsclickerClickerAssetsScriptsIronPerSec.cs 30
    Error CS0103 The name 'click' does not exist in the current context Assembly-CSharp D:UNITYUnity ProjectsclickerClickerAssetsScriptsIronPerSec.cs 30
    Error CS0103 The name 'AutoTick' does not exist in the current context Assembly-CSharp D:UNITYUnity ProjectsclickerClickerAssetsScriptsIronPerSec.cs 8
    Error CS0103 The name 'AutoIronPerSec' does not exist in the current context Assembly-CSharp D:UNITYUnity ProjectsclickerClickerAssetsScriptsIronPerSec.cs 34
    Error CS0116 A namespace cannot directly contain members such as fields or methods Assembly-CSharp D:UNITYUnity ProjectsclickerClickerAssetsScriptsIronPerSec.cs 32

    and heres my code:

    using UnityEngine;
    using System.Collections;

    public class IronPerSec : MonoBehaviour {

    // Use this for initialization
    void Start() {
    StartCoroutine(AutoTick ());

    }
    public UnityEngine.UI.Text IPCDisplay;
    public Click click;
    public ItemManager[] items;
    public int GetIronPerSec(){
    int tick = 0;
    foreach (ItemManager item in items)
    {
    tick += item.count * item.tickValue;
    }
    return tick;
    }

    // Update is called once per frame
    void Update () {
    ipsDisplay.text = GetIronPerSec () + " iron/sec ";
    }
    }

    public void AutoIronPerSec () {
    click.iron += GetIronPerSecond ();
    }
    IEnumerator AutoTick() {
    while (true) {
    AutoIronPerSec ();
    yield return new WaitForSeconds(1);
    } }

  5. from about 22:00 to the end of the video. i follow your example and got the game to run and are able to buy both gold per click and gold per second upgrades but the game will not tick. it probability i typo but i have check the code through and it the same as yours. any insight would be appreciated.

  6. I was struggling to get a handle on the new GUI system, but you really helped a lot man… Many Thanks 🙂 🙂

  7. How the Save is in the folder automaticly? It does nothing to me please help

  8. Your code has a lot of errors. Please clean it.

  9. Dunno if you still reply to comments here, but here goes!

    If i make an item higher than Item2, like the ones in your video, the gold per sec doesnt work. ItemManager works as the count goes up, but i don't get any gold per sec..

    Say the third item would have a tick of 4 and cost of 40… 40 gold gets withdrawn, but i never get the 4 gold/sec. Any idea why??

    As far as i can see the items dont differ at all.. dunno what the problem is..

  10. It keeps saying that there is unexpected symbol and then a parsing error

    heres the code:

    using UnityEngine;
    using System.Collections;

    public class ItemManager : MonoBehaviour {

    public UnityEngine.UI.Text itemInfo;
    public Click click;
    public float cost;
    public int tickValue;
    public int count;
    public string itemName;
    private float baseCost;

    void Start(){
    baseCost = cost;
    }

    void Update(){
    itemInfo.text = itemName + "nCost: " + cost + "nOnions: " + tickValue + "/s"
    }

    public void PurchasedItem(){
    if (click.onion >= cost) {
    click.onion -= cost;
    count += 1;
    cost = Mathf.Round (baseCost * Mathf.Pow(1.15f, count);
    }
    }

    }

  11. I Get Around 20 errors on GPS…Can Someone help me plz?

  12. What's wrong?

    using UnityEngine;
    using System.Collections;

    public class GPS : MonoBehaviour {

    public UnityEngine.UI.Text gpsDisplay;
    public Click click;
    public ItemManager[] items;

    void Start()
    {
    StartCoroutine(AutoTick());
    }

    void Update()
    {
    gpsDisplay.text = "GPS: " + GetGoldPerSec();
    }

    public int GetGoldPerSec()
    {
    int tick = 0;
    foreach(ItemManager item in items)
    {
    tick += item.count * item.tickValue;
    }
    return tick;
    }

    public void AutoGoldPerSec()
    {
    click.gold += GetGoldPerSec();
    }

    IEnumerator AutoTick()
    {
    while (true)
    {
    AutoGoldPerSec();
    yield return new WaitForSeconds(1);
    }
    }

    }

  13. is it normal for a 12 year old to be making video games by himself

  14. Error: CS0501: `GoldPerSec.gpsDisplay()' must have a body because it is not marked abstract, extern, or partial

    Code:
    using UnityEngine;
    using System.Collections;

    public class GoldPerSec : MonoBehaviour {

    public UnityEngine.UI.Text gpsDisplay();
    public Click click;
    public ItemManager[] items;

    void Start() {
    StartCoroutine(AutoTick());
    }

    void Update() {
    gpsDisplay.text = GetGoldPerSec() + " gold/sec";
    }

    public int GetGoldPerSec(){
    int tick = 0;
    foreach (ItemManager item in items) {
    tick += item.count * item.tickValue;

    }
    return tick;
    }

    public void AutoGoldPerSec() {
    click.gold += GetGoldPerSec();
    }

    IEnumerator AutoTick() {
    while (true) {
    AutoGoldPerSec();
    yield return new WaitForSeconds(1);
    }
    }
    }

    Any help would be appreciated.

  15. Could someone help? I got an error which says this:

    Assets/Script/MoneyPerSec.cs(37,1): error CS8025: Parsing error

    My code is this:

    using UnityEngine;
    using System.Collections;

    public class MoneyPerSec : MonoBehaviour {

    public UnityEngine.UI.Text mpsDisplay;
    public Click click;
    public ItemManager[] items;

    void Start() {
    StartCoroutine (AutoTick ());
    }

    void Update() {
    mpsDisplay.text = GetMoneyPerSec () + " money/sec";
    }

    public int GetMoneyPerSec() {
    int tick = 0;
    foreach (ItemManager item in items) {
    tick += item.count * item.tickValue;
    }
    return tick;
    }

    public void AutoMoneyPerSec() {
    click.money += GetMoneyPerSec ();
    }

    IEnumerator AutoTick() {
    while(true) {
    AutoMoneyPerSec();
    yield return new WaitForSeconds(1);
    }

    }

    Thanks if you helped me <3

  16. My IronPerSec text updates but i dont get iron when i have bought my item(Im using iron instead of gold)

    using UnityEngine;
    using System.Collections;

    public class IronPerSec : MonoBehaviour {

    public UnityEngine.UI.Text ipsDisplay;
    public OreClick click;
    public ItemManager[] items;

    void Start() {
    StartCoroutine (AutoTick ());
    }

    void Update() {
    ipsDisplay.text = GetIronPerSec () + " iron/sec";
    }

    public int GetIronPerSec() {
    int tick = 0;
    foreach (ItemManager item in items) {
    tick += item.count * item.tickValue;
    }
    return tick;
    }

    public void AutoIronPerSec() {
    click.iron += GetIronPerSec ();
    }

    IEnumerator AutoTick() {
    while (true) {
    AutoIronPerSec ();
    yield return new WaitForSeconds (1);
    }
    }

    }

  17. recommended for people with no c# knowlegede what so ever

  18. I need help im gettin(19,6) error CS1525 unexpected symbol "="

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

    public class GoldPerSec : MonoBehaviour {
    public UnityEngine.UI.Text gpsDisplay;
    public Click click;
    public ItemManager[] items;

    void start(){
    StartCoroutine (AutoTick ());
    }

    void Update(){
    gpsDisplay.text = GetGoldPerSec () + "gold/sec";
    }

    public int GetGoldPerSec(){
    int = 0;
    foreach(ItemManager item in items) {
    tick +=item.count * item.tickValue;

    }
    return tick;
    }

    public void AutoGoldPerSe(){
    click.gold += GetGoldPerSec ();
    }

    IEnumerator AutoTick(){
    while (true) {
    AutoGoldPerSec();
    yield return new WaitForSeconds (1);
    }
    }

    }

  19. I have one more question when I mine the gold and buy the first upgrade my cost goes to zero and when I buy the GPS upgrades I don't get anything if you want I could upload a video so u can see what it's doing

  20. I need help with my game. I doing in unity first time and i dont know anything. How i can switch the scenes on click button?
    PS:
    Sorry for my english but i from poland.

  21. I get 999+ errors:

    NullReferenceException : Object reference not set to an instance of an Object
    click.Update () (at Assets/Clicker Game/Skript/click.cs:14)

    can somebody help me??

  22. What's wrong? It says: Operator `*' cannot be applied to operands of type `string' and `string'           (I'm using Dollars)

    using UnityEngine;
    using System.Collections;

    public class ItemManager : MonoBehaviour { 

    public UnityEngine.UI.Text itemInfo;
     public Break click;
     public float cost;
     public int tickValue;
     public int count;
     public string itemName;
     private float baseCost; 

    void Start () {
      baseCost = cost;
     }
     
     void Update () {
      itemInfo.text = itemName * "nCost: " + cost + "nDollars: " + tickValue + "/s";
     } 

    public void PurchasedItem () {
      if (click.Dollars >= cost)
       click.Dollars -= cost;
       count += 1;
       cost = Mathf.Round (baseCost * Mathf.Pow(1.15f, count));
     }
    }

  23. public ItemManager[] items;

    Assets/Scripts/DinheiroSegundo.cs(9,9): error CS0246: The type or namespace name `ItemManager' could not be found. Are you missing an assembly reference?

    What is the problem? Cant found "ItemManager"

  24. yeild return new WaitForSeconds doesn't work

    Heres my code

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

    public class GoldPerSec : MonoBehaviour {

    public UnityEngine.UI.Text gpsDisplay;
    public Click click;
    public ItemManager[] items;

    void Start()
    {
    StartCoroutine(AutoTick());
    }

    void Update()
    {
    gpsDisplay.text = GetGoldPerSec () + " gold/sec";
    }

    public int GetGoldPerSec()
    {
    int tick = 0;
    foreach(ItemManager item in items)
    {
    tick += item.count * item.tickValue;

    }
    return tick;
    }

    public void AutoGoldPerSec()
    {
    click.gold += GetGoldPerSec();
    }

    IEnumerator AutoTick()
    {
    while(true)
    {
    AutoGoldPerSec();
    yeild return new WaitForSeconds(1);
    }
    }

    }

  25. *I got this when I finished… *

    Assets/Scripts/UpgradeManager.cs(4,14): error CS0101: The namespace `global::' already contains a definition for `UpgradeManager'

    Here is my script for UpgradeManager.cs:

    using UnityEngine;
    using System.Collections;

    public class UpgradeManager : MonoBehaviour {

    public Click click;
    public UnityEngine.UI.Text itemInfo;
    public float cost;
    public float count = 0;
    public int clickPower;
    public string itemName;
    private float baseCost;

    void Start() {
    baseCost = cost;
    }
    void Update() {
    itemInfo.text = itemName + "nCost: " + cost + "nPower: +" + clickPower;
    }

    public void PurchasedUpgrade () {
    if (click.stone >= cost) {
    click.stone -= cost;
    count += 1;
    click.stoneperclick += clickPower;
    cost = Mathf.Round (baseCost * Mathf.Pow (1.15f, count));
    }
    }
    }

  26. good guide, tho im having trouble in one place, it says type or namespace name Waitforseconds could not be found
    im making a script on visual studio 2015, here is the full script.
    Any tip or help will save me, thx in advance.

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

    public class GoldPerSek : MonoBehaviour
    {

    public UnityEngine.UI.Text gpsDisplay;
    public ClickScript click;
    public ItemManager[] items;

    void Start()
    {
    StartCoroutine(AutoTick());
    }
    void Update()
    {
    gpsDisplay.text = GetGoldPerSec() + " gold/sec";
    }
    public float GetGoldPerSec()
    {
    float tick = 0;
    foreach (ItemManager item in items)
    {
    tick += item.count * item.tickValue;
    }
    return tick;
    }

    public void AutoGoldPerSec()
    {
    click.gold += GetGoldPerSec() / 10;
    }
    IEnumerator AutoTick()
    {
    while (true)
    {
    AutoGoldPerSec();
    yield return new WaitFotSeconds(0.1f);
    }
    }
    }

  27. I know this video's sort of old but I have two errors that I don't know how to fix.
    Assets/Scripts/MemesPerSec.cs(22,38): error CS1026: Unexpected symbol `;', expecting `)'
    Assets/Scripts/MemesPerSec.cs(23,2): error CS1026: Unexpected symbol `)', expecting `)'

    Here's my script:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class MemesPerSec : MonoBehaviour {

    public UnityEngine.UI.Text mpsDisplay;
    public Click click;
    public ItemManager[] items;

    void Start() {
    StartCoroutine (AutoTick ());
    }

    void Update() {
    mpsDisplay.text = GetMemesPerSec () + " memes/sec";
    }

    public int GetMemesPerSec(){
    int tick = 0;
    foreach (ItemManager item in items) (
    tick += item.count * item.tickValue;
    )
    }

    public void AutoMemesPerSec() {
    click.memes += GetMemesPerSec ();
    }

    IEnumerator AutoTick() {
    while (true) {
    AutoMemesPerSec ();
    yield return new WaitForSeconds (1);
    }
    }

    }

  28. I am having trouble trying to create a variation in this. I want multiple buttons to be able to add gold. But only one works for some reason. Though in the inspector it shows that the gold is updating however the text in the game doesn't update. Here is what I did:
    public class Click : MonoBehaviour {

    public float gold;
    public float gpc;
    public Text goldCount;
    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {
    goldCount.text = "$" + gold;
    }
    public void Clicked()
    {
    gold += gpc;
    }
    }
    Then I added the function to all of the buttons and set a different gps value for each of them. I also dragged the Text UI item into each of the required fields. Still no luck.

  29. I like the tutorial and it's maybe a little bit late to tell you, but the person in the background that is smashing his keyboard is really annoying…

  30. Hi, This is the code I entered but i must have gotten it wrong as nothing happens when i play the game and buy an upgrade:

    public class Goldpersec : MonoBehaviour {

    public UnityEngine.UI.Text gpsDisplay;
    public Click click;
    public ItemManager[] items;

    void Start(){
    StartCoroutine (AutoTick ());
    }

    void Update(){
    gpsDisplay.text = GetGoldPerSec () + " Gold/Sec";
    }

    public int GetGoldPerSec(){
    int tick = 0;
    foreach(ItemManager item in items) {
    tick += item.count * item.tickValue;

    }
    return tick;

    }

    public void AutoGoldPerSec(){
    click.gold += GetGoldPerSec ();

    }

    IEnumerator AutoTick(){
    while (true) {
    yield return new WaitForSeconds(1);

    }

    }
    }

    Can someone please tell me where i have gone wrong

  31. i fix it

    using UnityEngine;

    using System.Collections;
    public class Click : MonoBehaviour {

    public UnityEngine.UI.Text ClickPower;
    public UnityEngine.UI.Text goldDisplay;
    public float gold = 0.00f;
    public int goldperclick = 1;

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

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

    }

  32. i fix it

    using UnityEngine;
    using System.Collections;

    public class UpgradeManager : MonoBehaviour {

    public Click click;
    public UnityEngine.UI.Text itemInfo;
    public float cost;
    public int count = 0;
    public int clickPower;
    public string itemName;
    private float baseCost;

    void Start (){
    baseCost = cost;
    }

    void Update(){
    itemInfo.text = itemName + "nCost: " + cost + "nPower: +" + clickPower;
    }

    public void PurchasedUpgrade () {
    if (click.gold >= cost) {
    click.gold -= cost;
    count += 1;
    click.goldperclick += clickPower;
    cost = Mathf.Round (baseCost * Mathf.Pow (1.15f, count));
    }
    }

    }

  33. CASH PER CLICK OR GOLD PER CLICK SCRIPT
    ________________________________________________________________________________________

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

    public class Cash : MonoBehaviour {

    public UnityEngine.UI.Text cpsDisplay;
    public Click click;
    public ItemManager[] items;
    public int GetCashPerSec() {
    int tick = 0;
    foreach (ItemManager item in items) {
    tick += item.count * item.tickValue;
    }
    return tick;
    }

    public void AutoCashPerSec() {
    click.Cash += GetCashPerSec ();
    }

    IEnumerator AutoTick() {
    while (true) {
    AutoCashPerSec ();
    yield return new WaitForSeconds (1);
    }
    }
    }

  34. in my item manager script it says The name 'Math' does not exist in the current context error CS0103

  35. Hey nice beginning with part 1 but gosh the fonts are so small in part 2 I cant see anything what actually is written here. I have bad eyes and even in full screen I can't figure it out. Well still a huge help with this. Thanks 😀

  36. so in the button that says 1 gold per click (GPC) it doesnt update it stays in the 1 gold per click when upgrade please help!

  37. I know this is an old tutorial but hoping someone will be able to help when applying gold per second code to the text it tells me "the associated script can not be loaded. Please fix any compile errors and assign a valid script."

  38. Help pls Assets/Scripts/GoldPerSec.cs(21,25): error CS0103: The name `Item' does not exist in the current context

    My Script:
    using UnityEngine;
    using System.Collections;

    public class GoldPerSec : MonoBehaviour {

    public UnityEngine.UI.Text gpsDisplay;
    public Click click;
    public ItemManager[] items;

    void Start () {
    StartCoroutine (AutoTick ());
    }

    void Update () {
    gpsDisplay.text = GetGoldPerSec () + " gold/sec";
    }

    public int GetGoldPerSec () {
    int tick = 0;
    foreach (ItemManager item in items) {
    tick += item.count * Item.tickValue;
    }
    return tick;
    }

    public void AutoGoldPerSec() {
    click.gold += GetGoldPerSec();
    }

    IEnumerator AutoTick() {
    while (true) {
    AutoGoldPerSec ();
    yield return new WaitForSeconds (1);
    }
    }

    }

  39. I know this is old but im just starting to get into C# and designing games with unity. Im having a weird issue where items 1 and 2 both only add 1 GPS.

  40. I cant upgrade?Even when I have enough currency (Sulfur) I cant.
    code!! :
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class UpgradeManager : MonoBehaviour
    {

    public Click click;
    public UnityEngine.UI.Text itemInfo;
    public float cost;
    public int count = 0;
    public int clickPower;
    public string itemName;
    private float newCost;

    void Update()
    {
    itemInfo.text = itemName + "nCost: " + cost + "nPower: +" + clickPower;
    }
    public void PurchasedUpgrade()
    {
    if (click.Sulfur >= cost)
    {
    click.Sulfur -= cost;
    count += 1;
    click.Sulfurperclick += clickPower;
    cost = Mathf.Round(cost * 1.15f);
    newCost = Mathf.Pow(cost, newCost = cost);

    }
    }
    }

  41. Doesn't work the Gold Per Second here is the script + i got 0 ERRORES.
    using System.Collections;
    using System.Collections.Generic;
    using TMPro;
    using UnityEngine;

    public class MoneyPerSecond: MonoBehaviour
    {

    public TextMeshProUGUI cpsDisplay;
    public ClickScript click;
    public ItemManager[] items;

    void Start()
    {
    StartCoroutine(AutoTick());
    }

    void Update()
    {
    cpsDisplay.text = "CPS: " + GetMoneyPerSec();
    }

    public int GetMoneyPerSec()
    {
    int tick = 0;
    foreach (ItemManager item in items)
    {
    tick += item.count * item.tickValue;
    }

    return tick;
    }

    public void AutoMoneyPerSec()
    {
    click.money += GetMoneyPerSec();
    }

    IEnumerator AutoTick()
    {
    while (true)
    {
    AutoMoneyPerSec();
    yield return new WaitForSeconds(1);
    }
    }

    }

  42. Every time I click play my "0 gold/sec" disappears, I tried to fix it and then I got over 205 errors on that GPS button…

    FIXED – Had to redo my buttons and add the componets and shiz back into it

  43. you are the best tutorial man ever

Leave a Reply

Your email address will not be published.