- Home /
Destroy then Clone Help please?
I'm trying to write a script that Destroys an object after 3 seconds, then waits 2 more seconds, then clones that object so it can continue. The problem I'm having is the object never gets destroyed. Here's my code:
//Sphere Countdown
//Public Variables
var wait : int = 5;
//Private Variables
function CoUpdate ()
{
Destroy(gameObject,3);
yield WaitForSeconds(wait);
Instantiate(gameObject);
}
Also, is there any way I could call in another script when the object clones itself?
it's impossible since the script is destroyed with the object so it never gets to the point of instantiate.
Answer by MobinS · Aug 18, 2011 at 06:57 PM
First hi Then Come On! :D the script will go on till " Destroy(gameObject,3); " then it will destroy the object that script is in it! so it wouldn't continue... you can do 3 way : 1.move the script to onother gameobject 1. move the script to another gameobject and then use " gameobject.find " to find the object that need to be destroyed & then destroy it 2. 3 or you can easily put destroy on the last line ... and if you want to disapear it just for a few sec and then destroy it use " gameobject.renderer == false " ....
lol I felt so stupid once you pointed out that it will destroy that game object and the scripts
Answer by Anxo · Aug 18, 2011 at 07:07 PM
On the object to be destoryed
public var GameControl : GameObject;
function GetRidOff()
{
GameControl.BroadcastMessage("SpawnNew");
Destory(gameObject,3)
}
On the GameControl Object
function SpawnNew(){
yield WaitForSeconds(5);
Debug.Log("Instantiating");
}
Your answer
Follow this Question
Related Questions
Yeild and WaitForSeconds and Instantiate 1 Answer
Instantiate an object as soon as another object is destroyed 2 Answers
Respawn after delay 3 Answers
Respawn after delay 3 Answers
instatiate gameobject after 1 second 1 Answer