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): using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class PeopleDestroy : MonoBehaviour { void Update() { if (Input.GetMouseButtonDown(0)) { Debug.Log("Working fine"); Destroy(gameObject); } } }
Every time you place a person, increase an Int variable by 1. Code (CSharp): if(Input.GetMouseButtonDown(0)) { SpawnPeople(); } void SpawnPeople() { Instantiate(blah blah blah); peopleCounter++; }
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.