Hi, I’m veeery new to game development and C#, and I was wondering how I can delete a certain number of clones from my scene. I’m making a tycoon-like game where points are symbolized by cubes and when you buy an upgrade the cubes (points) that you spent disappear. Heres a snippet of my code:
//Adds to score and gives the user a cube
if (Input.GetKeyDown(KeyCode.Mouse0))
{
Instantiate(cubePrefab, new Vector3(0, 10, 0), Quaternion.identity);
score++;
Debug.Log(score);
}
//Gives the user a golden cube but subtracts 50 from score
if (Input.GetKeyDown(KeyCode.Mouse1) && score >= goldCost)
{
Instantiate(goldenCubePrefab, new Vector3(0, 10, 0), Quaternion.identity);
score = (score - goldCost);
goldCubes = (goldCubes + 1);
Debug.Log(score);
StartCoroutine(AddGoldScoreRoutine());
//Destroys 50 regular cubes
Destroy(GameObject.Find("cube(Clone)"), 50);`
Not sure if “Destroy(GameObject.Find(“cube(Clone)”), 50)” is the correct method or I’m doing something wrong, because whenever I “Buy” something the cubes don’t get removed from the scene. Does anyone have a solution?