x


When one thing spawn another will be destroyed

Hey, I'm wondering if it's possible to add a script to an object and when that object spawn's another thing I've assigned to the script will be destroyed.

If so, could someone link me an answered question or example if u know of any cuz I've been searching around and couldn't find anything.

more ▼

asked May 13 '11 at 08:23 PM

simpleone gravatar image

simpleone
110 36 40 46

It is possible, but you can do it in hundred of different ways. We could only guess how you want this implemented, but we are likely to guess wrong. So can you be more specific?

May 13 '11 at 08:29 PM OrangeLightning

Erm, I got a gameobject that is going to be spawned after 50 seconds and when it spawns I want a few other gameobjects in the game to be destroyed... so I was thinking if it was possible to add a script to this gameobject that is going to be spawned and in the inspector I wanna assign this gameobjects that is going to be destroyed when it spawns...

  • sorry if it was confusing.
May 13 '11 at 08:40 PM simpleone
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first
public GameObject spawnObject; // assign the prefab you want to spawn after X time.
public float spawnTime = 50; // time after which spawnObject is spawned

public GameObject[] destroyObjects; // Objects to be destroyed when spawnedObject is spawned.

void Start()
{
    Invoke( "SpawnAndDestroy", spawnTime );
}

void SpawnAndDestroy()
{
    if( spawnObject != null )
        Instantiate( spawnObject );

    if( destroyObjects != null )
    {
        foreach(GameObject destroyObject in destroyObjects)
        {
            Destroy(destroyObject);
        }
    }
}

Untested.

more ▼

answered May 14 '11 at 12:23 AM

Antony Blackett gravatar image

Antony Blackett
981 9 12 19

thx for the answer... it was a few errors in that script but it doesn't mather cuz I got it to work on another way.

May 14 '11 at 09:36 AM simpleone
(comments are locked)
10|3000 characters needed characters left
Your answer
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:

x764
x441
x72

asked: May 13 '11 at 08:23 PM

Seen: 598 times

Last Updated: May 13 '11 at 08:23 PM