Instantiate dead replacement (Project attached)

Hi, all,

If you can import the attached Unity package into a project you will see a simple 2D scene. There are four green dots within a sun object. When pressed, each green dot subtracts hitpoints from the sun and is replaced by a gold dot. Upon death, the sun disappears.

What I want to do is call another dead replacement (Dot replacement 2) three seconds after the gold dot instantiates, effectively destroying the gold dot and replacing it with the object called: Dot replacement 2.

To recap the order of events: Press green dot, dot destroys self then fades up gold, 3 second pause then gold dot replaced with another green dot (Dot replacement 2). - it is this last step that I cannot do. I can’t seem to instantiate the second replacement green dot and make it a child of the sun object.

Sorry if this is convoluted, but it’s the only way I can think to explain my problem at the moment.

Thanks for your help!

Greg

183688–6515–$exercise_1_788.unitypackage (485 KB)

Most of that timing stuff I’ve been doing with a

yield new WaitForSeconds(1);

So something like:

function Start(){
  myState=green;
  myHP=startHP;
}

function TakeDamage(amt){
  myHP-=amt;
  if (myHP<=0){Die();}
}

function Die(){
  myState=gold;
  yield WaitForSeconds(3);
  Instantiate(gameObject,transform.position,transform.rotation);
  Destroy(gameObject);
}

Thanks, Quentinp,

Do you know how you’d recode the above to become a child of a parent object?

Thanks,

Greg

Yeah just make the transform.parent another transform.

function Start(){
  myState=green;
  myHP=startHP;
}

function TakeDamage(amt){
  myHP-=amt;
  if (myHP<=0){Die();}
}

function Die(){
  myState=gold;
  yield WaitForSeconds(3);
   var newObject=Instantiate(gameObject,transform.position,transform.rotation);
  newObject.transform.parent=someTransformOrOther;
  Destroy(gameObject);
}