- Home /
Yeild and WaitForSeconds and Instantiate
I am having trouble with waitforseconds and instantiating my player.
function Dead()
{
Destroy(gameObject);
Instantiate(deadPlayer, transform.position, transform.rotation);
yield WaitForSeconds(2);
Instantiate(Player, spawnPoint.transform.position, transform.rotation);
enabled = false;
}
Yield seems to be working perfectly in my enemy script where it is supposed to destroy itself.
Thanks!
Answer by m4s4m0r1 · Apr 02, 2013 at 02:02 AM
its simple, You destroy itself ,,, if that script is attached to your Character,it will Dsetroy The whole Object,,, So, before yield work, You destroy the Whole Script. However, you can make a "Spawn script" with a simple State but make sure you write the Script to a new Script. and make a Parent for your character, then Attach your new Spawn Script to your Parent Object,,, so Maybe something like this :
Var MyChild : GameObject;
function Dead()
{
Instantiate(deadPlayer, transform.position, transform.rotation);
Destroy(MyChild);
yield WaitForSeconds(2);
Instantiate(Player, spawnPoint.transform.position, transform.rotation);
enabled = false;
}
Your answer
Follow this Question
Related Questions
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
Destroy then Clone Help please? 2 Answers
Instantiate an object as soon as another object is destroyed 2 Answers
Destroy doesn't work when also instantiating new objects 1 Answer
Destroy the current GameObject? 7 Answers