- Home /
Question by
JesseSomerville · Feb 02, 2014 at 04:30 PM ·
javascriptinstantiateenemy
Health drop, and picking it up.
I have all of the code I need for the health pickup to drop when I kill an enemy, but I have been working for about 3 days with no luck on how to get it to destroy once it's instantiated. Sorry for the messy wording but here is my code:
function Dead()
{
Instantiate(healthDrop, enemy.transform.position, Quaternion.identity);
gameObject.SetActiveRecursively(false);
}
This is where I am destroying the enemy and instantiating the health drop
#pragma strict
var player : Transform;
var enemy : GameObject;
function Update ()
{
healthDropLogic();
}
var distance = Vector3.Distance(player.transform.position, transform.position);
function healthDropLogic ()
{
yield WaitForSeconds(3);
Destroy(gameObject);
}
This code is on the health drop
Any help would be much appreciated!
Comment
Answer by Manco Capac · Feb 02, 2014 at 04:54 PM
If you want to destroy the health drop 3 secs after you instantiate it use this in the health drop script:
Destroy (gameObject, 3);
And destroy your enemy the same way. You can make a prefab of the health drop with the script attached.
I did make a prefab of the healthDrop. That's how I'm instantiating it. The logic of the code posted does not work for me.