- Home /
Melle system destroy game object not working despite no errors and declining health
so my script was working fine yesterday with no changes, when the enemy has less than health or 0 health it would be destroyed, how ever now the destroy function isn't working, health will go into minuses so i know every thing is working but the destroy bit
down below will be the attack function of my melee system not including animation functions and my enemy health script.
function Update ()
{
if (Input.GetButtonDown("Fire1"))
{
//attack animation
TheMace.animation.Play("MaceSwing");
//attack function
var Hit : RaycastHit;
if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), Hit))
{
Distance = Hit.distance;
if (Distance < MaxDistance)
{
Hit.transform.SendMessage("ApplyDamage", Damage, SendMessageOptions.DontRequireReceiver);
}
}
}
#pragma strict
var Health = 100;
function update ()
{
if (Health <= 0)
{
Dead();
}
}
function ApplyDamage (Damage : int)
{
Health -= Damage;
}
function Dead()
{
Destroy (gameObject);
}
help please :)
the scripts didn't get separated, function update is my melle system and #pragma scrict is my enamy health script
Answer by Stevenup-7 · Oct 03, 2014 at 11:11 PM
As far as I can see, you are attempting to destroy the separate gameObject property, not the object itself.
Try to replace "Destroy(gameObject)" with:
"Destroy(this.gameObject);" or "Destroy(this.transform);"
This way, you'll destroy the object itself with all what's inside it (for example, childs).
Good Luck!
Your answer
Follow this Question
Related Questions
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
Enemy sound detection 5 Answers
Countdown code not working 1 Answer
Destroy gameobject 2 Answers