- Home /
Gameobject Respawn
I was attempting to make my enemies disapeer and come back in say. 60 seconds. I tried to use transform.active = false; inside of a waitforseconds Coroutine but the object never came back.. so all Im trying to do is make the gameobject after it hits 0 life to disapeer for 60 seconds and come back with full life.
thank you in advance!
if (curHealth == 0) {
//DISAPEER FOR 60 SECONDS
//COME BACK.
transform.position = respawnhere;
curHealth = maxHealth;
PlayerAttack ZS = (PlayerAttack)target.GetComponent ("PlayerAttack");
ZS.DeselectTarget ();
ZS.SpawnEXP();
PlayerHealth eh = (PlayerHealth)target.GetComponent ("PlayerHealth");
eh.AdjustCurrentEXP (20);
}
Answer by kannan21 · Jan 17, 2014 at 09:37 AM
Gameobject[] enemies = all your enemies;
Void Respawn()
{
foreach(gameobject obj in enemies)
{
obj.setactive(true);
obj.transform.position = respawn position;
(get script form obj).health = maxhealth;
}
}
Void CleanUpEnemies()
{
foreach(gameobject obj in enemies)
{
obj.setactive(false);
}
}
Ienumerator CallThisFunction()
{
CleanUpEnemies();
yield return new WaitForSeconds(60);
Respawn();
}
please format your code. You can do this by highlighting all your code, then clicking the 10101 button at the top of the edit window.
Im using C## so I have no idea how to convert this..
Your answer
![](https://koobas.hobune.stream/wayback/20220613130656im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Enemy Respawn Bug 3 Answers
How to make an enemy respawn? 0 Answers
Enemy Respawn causes player to unable to attack 1 Answer
Can't set timer 1 Answer
How to spawn a 'boss' after all enemies defeated and then kill that 'boss'? 1 Answer