I made a respawn script, to respawn an enemy once it has died. Everything works so far, but I want to place respawn gameobjects multiple times in the level. Here's my script:
var beholder : Transform;
var targetThing : Transform;
var Weapon: Transform;
private var isClose : boolean = false;
Beholder.thing = targetThing;
Beholder.weapon = Weapon;
var deathTimer : int = 0;
var maxRespawns : int;
static var respawnCount : int = 0;
function Update ()
{
if(Vector3.Distance(targetThing.position,transform.position) <= 30)
{
isClose = true;
}
else
{
isClose = false;
}
if(Beholder.death && isClose)
{
deathTimer++;
if(deathTimer == 50 && respawnCount < maxRespawns)
{
deathTimer = 0;
respawnCount++;
Beholder.death = false;
var newBeholder = Instantiate(beholder, transform.position, transform.rotation);
}
}
}
Edit:
By multiple objects, I meant that I wanted to make multiple versions of the object this script is attached to so that they can have different respawnCount variables. That way i could have different respawn places that have seperate numbers of possible enemies to respawn. Then when it adds one to respawnCount of one respawn object, it doesn't to the other.