How can I destroy instantiated prefabs when many are created with the same name?

Hi everyone,

I’m trying to make a plant that grows in 4 stages, each stage is a prefab, my script is attached to an empty GameObject, everything is working just fine in my scene except when this script is active multiple times at once, because then more than one instance of this script is running and they instantiate prefabs with indentical names, then they interfere with each other and causing unwanted results like destroy the wrong prefab, I was wondering how do you think I should fix that?

thank you for the help, here is my script if you want to have a look.

using UnityEngine;
using System.Collections;
public class PlantCycle : MonoBehaviour
{
public float plantGrowth = 1;
public float plantSize;
public bool plantStage01 = true;
public bool plantStage02 = false;
public bool plantStage03 = false;
public bool plantStage04 = false;
void Start ()
{
Instantiate (Resources.Load ("Prefabs/Prefab_PlantStage01"), this.transform.position, this.transform.rotation); //Initialate Plant Phase 1
}
void Update ()
{
plantSize = plantSize + plantGrowth * Time.deltaTime;
if (plantSize >= 10 && plantStage02 == false)
{
Instantiate (Resources.Load ("Prefabs/Prefab_PlantStage02"), this.transform.position, this.transform.rotation);
plantStage02 = true;
Destroy (GameObject.Find("Prefab_PlantStage01(Clone)"));
}
else if (plantSize >= 20 && plantStage03 == false)
{
Instantiate (Resources.Load ("Prefabs/Prefab_PlantStage03"), this.transform.position, this.transform.rotation);
plantStage03 = true;
Destroy (GameObject.Find("Prefab_PlantStage02(Clone)"));
}
else if (plantSize >= 30 && plantStage04 == false)
{
Instantiate (Resources.Load ("Prefabs/Prefab_PlantStage04"), this.transform.position, this.transform.rotation);
plantStage04 = true;
Destroy (GameObject.Find("Prefab_PlantStage03(Clone)"));
}
}
}

What you want to do is keep a list using System.Collections.Generic. By each PlantCycle script keeping a list of all the plants it has created it can destroy individual object it has created as well without destroying the wrong one. I suggest giving the object a name and appending the instanceID of the current gameObject to the name this way you can find he object as each component has a unique instance ID. hope this helps.

Since you will only have one active plant state at a time you can just store a reference to the current plant.

Gameobject newPlant = Instantiate();
Destroy(curPlant);
curPlant = newPlant;