D
D
durnevdanya2017-04-18 18:40:10
Game development
durnevdanya, 2017-04-18 18:40:10

How to make an object created every second, and "behind the scenes" deleted?

Hello. I have a scene in which I use a road spawn script - so that the road appears every second, we pass it and it should disappear. I only made it appear, but after I pass it, it does not disappear. I tried to write, but it turns out that it deletes exactly the object that I use to create this very road through Instantiate. How should I do? I want it to only delete what I drove, not delete the road object that the game uses to create further objects.
Right now I just get a message saying that the road has been removed and cannot be spawned.
nOlYXjv.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Demigodd, 2017-04-19
@durnevdanya

Throw this script on Prefab Roads.988e547dde4c4ca2a166a347bdb34e4c.png

E
Espleth, 2017-04-18
@Espleth

Instantiate returns an Object which is actually created. That's what you need to remove.
GameObject go = (GameObject)Instantiate(prefab);
Destroy(go);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question