Search Unity

"Cookie Clicker" Score

Discussion in '2D' started by SEVEN-ARTS, Feb 17, 2021.

  1. SEVEN-ARTS

    SEVEN-ARTS

    Joined:
    Aug 31, 2020
    Posts:
    40
    Hey there,
    I'm working on a "cookie clicker" in which you can buy people, then place them on the world and get +1 per person (not yet solved, but not the problem what it is about). My problem, however, is that I would like to see how many I have already placed. The people you place is a prefab that is always cloned when you buy them.
    This is the script of the people, you can place:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class PeopleDestroy : MonoBehaviour
    7. {
    8.     void Update()
    9.     {
    10.         if (Input.GetMouseButtonDown(0))
    11.         {
    12.             Debug.Log("Working fine");
    13.             Destroy(gameObject);
    14.         }
    15.     }
    16. }
     
  2. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,465
    Every time you place a person, increase an Int variable by 1.

    Code (CSharp):
    1. if(Input.GetMouseButtonDown(0))
    2. {
    3.     SpawnPeople();
    4. }
    5.  
    6. void SpawnPeople()
    7. {
    8.     Instantiate(blah blah blah);
    9.     peopleCounter++;
    10. }
     
  3. SEVEN-ARTS

    SEVEN-ARTS

    Joined:
    Aug 31, 2020
    Posts:
    40
    But this creates the prefab after one click, but I want that after you have bought it. (the prefab moves with your cursor) and when you then click, the prefab should be deleted and only then should it be increased.
     
  4. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,465
    The logic is still the same. Add an Int variable and have it increase whenever you click.
     
    SEVEN-ARTS likes this.