- Home /
Clones not being Destroyed
using UnityEngine;
using System.Collections;
public class ClickButton : MonoBehaviour {
public string Previous = "";
public GameObject PopUp;
void OnMouseDown()
{
Destroy(GameObject.Find(Previous));
Instantiate(PopUp);
}
}
Everytime I run and click on the button the clone object stays and instantiates the new object however if the object is not a clone it works fine. However it being a clone is necessary
Answer by GamezAtWork · Nov 29, 2016 at 04:41 AM
Hm, I believe that might be because cloned objects usually have a name like "PrefabName (Clone)", perhaps. You usually would have to set the name of the cloned objects directly, like, newObject.name = Previous. Could you see what the name of the instantiated objects are?
The name of the prefab in question is Options, I've tried typing in Options(Clone) into the string but ins$$anonymous$$d of not destroying itself and instantiating a new prefab it fails to do both. It's just strange how it works when is not a clone
I might be wrong, but isn't there a space in between? Like, Options (Clone).
No space. Also when it doesnt delete the clone the next one has a name Options(clone)(clone) and so on, if that helps,
It was acting weird Yesterday but I tried your first answer today and it worked. Thanks
Your answer
Follow this Question
Related Questions
Destroy Child of Game Object 2 Answers
Deleting a GameObject 2 Answers
Instantiate and Destroy an object while crossing a line with its clone also 1 Answer
GameObject.Find(TextFieldVariable) - Doesnt seem to work! 1 Answer
How do I properly destroy an instance of a prefab from within its own script? 1 Answer