x


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.

more ▼

asked Nov 08 '11 at 01:07 PM

hatzalex gravatar image

hatzalex
61 7 9 10

You should give allLetters an explicit type, like you do for letters and existingLetters.

Nov 08 '11 at 01:22 PM syclamoth
(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1668
x1250
x764
x183
x183

asked: Nov 08 '11 at 01:07 PM

Seen: 899 times

Last Updated: Nov 08 '11 at 02:39 PM