- Home /
Destroying and instantiating parent GameObject
Hallo everybody,
While building my game i've encountered a problem when i try to remove a parent game object (with all its children) and reinstantiating the prefab. Because the game objects already exist in my scene it seems as if i have to treat the already existing objects & the prefab objects as different objects. When i try to instantiate the prefab i have encountered numerous problems and i have tried numerous approaches to the problem. Some problems where that the instantiated prefab doesn't instantiate or that the Destroy function does not remove the objects. Anyway here is where i am at now.
#pragma strict
var letters : GameObject;
var isDead = true;
var allLetter : GameObject;
var existingLetters : GameObject;
function Respawn ()
{
if(isDead)
{
Destroy(existingLetters);
isDead = false;
Debug.Log("i was here" + isDead);
Instantiate(letters);
allLetter = letters;
}
if(isDead == false)
{
Instantiate(letters);
allLetter = letters;
Debug.Log("done this");
Destroy(letters);
Debug.Log("this");
}
}
The respawn function is called from another script. Is this because I'm trying to instantiate a parent object or am i failing big time code wise?
Thanks in advance.
You should give allLetters an explicit type, like you do for letters and existingLetters.
Your answer
Follow this Question
Related Questions
How many time does a prefab takes to load?? 1 Answer
How to spawn a new prefab when the last one was destroyed?? 2 Answers
Trouble with destroying an instantiated prefab 2 Answers
help for start my project... 2 Answers
Destroying Objects. 1 Answer