- Home /
The question is answered, right answer was accepted
Can't remove component. MeshRenderer depends on it
What can I do about this error?
Currently I have an object that should die (Destroy currently) when health <= 0 and instead I get this error
here is the code that should rid me of the object:
// vars var health : float = 100; var armour : float = 0; var shield : float = 0;
// supporting vars var damage_hull : float = 0; var damage_shield : float = 0; var temp : float = 0;
// control vars var replace : boolean = false;
// objects var explosion : Transform; var replacement : Transform; var origional : Transform;
function Update () { if (health > 0.0 && shield <= 0.0) { if (armour > 0) { armour = armour - ( damage_hull / 2 ); temp = damage_hull - armour; if (temp > 0) { damage_hull = temp; } }
health = health - damage_hull;
}
if (health <= 0.0)
{
if (replace == false)
{
//Instantiate(explosion,transform.position, transform.rotation);
Destroy (origional);
}
else
{
Instantiate(replacement,transform.position, transform.rotation);
Destroy (origional);
}
}
}
function Hull_Damage_receiver (hull : float) { damage_hull = hull; }
function Shield_Damage_receiver (shield : float) { damage_shield = shield; }
Why? Does it make a difference in Unity? - I'm fairly new to it.
Answer by Molix · Feb 03, 2011 at 03:53 AM
Since "origional" is a Transform, I think you probably want:
Destroy( origional.gameObject );
If you Destroy the Transform (a Component), it is like trying to remove the Transform component from the GameObject. However, all Components expect there to be a Transform in their GameObject, so it complains.
Follow this Question
Related Questions
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
Game object with animations 0 Answers
Animation : Mesh Renderer - Issue 0 Answers
Can't render GameObject 3 Answers