This is one of the last things I need to work out to get my game done, fixing this code to make my enemies respawn at the vector3 respawnhere, ive only managed to get them to…
A. become inactive but never come back
B. Spawn Clones with scripts that dont work
C. Respawn at the respawn point instantly
All i want is a timer before respawnhere is called and until it is called the gameobject to be invisible… thaank you!! here is my code in C##
if (curHealth <= 0) {
// respawn enemy.. hide for x amount of seconds.
PlayerAttack ZS = (PlayerAttack)target.GetComponent ("PlayerAttack");
ZS.DeselectTarget ();
ZS.SpawnEXP();
PlayerHealth eh = (PlayerHealth)target.GetComponent ("PlayerHealth");
eh.AdjustCurrentEXP (20);
ItemDrop ID = (ItemDrop)GetComponent ("ItemDrop");
ID.RandomizeItems();
}
healthBarLength = (Screen.width / 2 ) * (curHealth / (float)maxHealth);
}
Heres some codes that I scrapped up but none work just to give an idea out…
public void respawn() {
curHealth = maxHealth;
transform.position = respawnhere;
gameObject.SetActive(true);
}
public void despawn() {
gameObject.SetActive(false); //using SetActive() since that's how the Unity documentation does it these days
Invoke("respawn",respawnDelay); //calls "respawn" after respawnDelay seconds
}
IEnumerator death()
{
transform.position = deadspace;
yield return new WaitForSeconds(2);
transform.position = respawnhere;
curHealth = maxHealth;
spawn = 1;
}