How can I implement destroying the enemy object after death, after a set time? Here is the script I have so far:
ar maximumHitPoints = 100.0;
var hitPoints = 100.0;
var deadReplacement : Rigidbody;
var GOPos : GameObject;
private var scoreManager : ScoreManager;
function Start(){
var GO = gameObject.FindWithTag("ScoreManager");
scoreManager = GO.GetComponent("ScoreManager");
}
function ApplyDamage (damage : float) {
if (hitPoints <= 0.0)
return;
// Apply damage
hitPoints -= damage;
scoreManager.DrawCrosshair();
// Are we dead?
if (hitPoints <= 0.0)
Replace();
}
function Replace() {
// If we have a dead barrel then replace ourselves with it!
if (deadReplacement) {
var dead : Rigidbody = Instantiate(deadReplacement, GOPos.transform.position, GOPos.transform.rotation);
scoreManager.addScore(20);
// For better effect we assign the same velocity to the exploded barrel
dead.rigidbody.velocity = rigidbody.velocity;
dead.angularVelocity = rigidbody.angularVelocity;
}
// Destroy ourselves
Destroy(gameObject);
}
var maximumHitPoints = 100.0;
var hitPoints = 100.0;
var deadReplacement : Rigidbody;
var GOPos : GameObject;
private var scoreManager : ScoreManager;
function Start(){
var GO = gameObject.FindWithTag("ScoreManager");
scoreManager = GO.GetComponent("ScoreManager");
}
function ApplyDamage (damage : float) {
if (hitPoints <= 0.0)
return;
// Apply damage
hitPoints -= damage;
scoreManager.DrawCrosshair();
// Are we dead?
if (hitPoints <= 0.0)
Replace();
}
function Replace() {
// If we have a dead barrel then replace ourselves with it!
if (deadReplacement) {
var dead : Rigidbody = Instantiate(deadReplacement, GOPos.transform.position, GOPos.transform.rotation);
scoreManager.addScore(20);
// For better effect we assign the same velocity to the exploded barrel
dead.name = "I am dead";
dead.rigidbody.velocity = rigidbody.velocity;
dead.angularVelocity = rigidbody.angularVelocity;
}
yield WaitForSeconds(2);
Destroy( GameObject.Find( "I am dead" ) );
// Destroy ourselves
Destroy(gameObject);
}