I have simple emmiter which sending enemies toward player in center of screen. Player can shoot missile (also emmiter). I want to destroy enemy AND missile in same time.
Here is my code attached to Enemy
public GameObject player;
public GameObject missile;
void OnTriggerEnter2D(Collider2D collider)
{
if (collider.gameObject.name == player.name)
{
Destroy(gameObject);
Application.LoadLevel("Retry");
}
if (collider.gameObject.tag == missile.tag)
{
Destroy(gameObject);
Destroy(missile.gameObject);
Score.killed++;
}
}
But after missile hit enemy, error in unity occur
Destroying assets is not permitted to avoid data loss.
Well... im programmer but new in unity. So my question is not that simple : i think im destroying object which is still in use. Am i right? How can i destroy both objects? When i can destroy GameObject? I tried to use this
GameObject mssle = Istantiate(missile,missile.transform.position,Quaternion.identity);
Destroy(mssle);
as was suggested by good people on unityanswers. Didnt work, missile is stil alive and my answer got rejected. Am i destroying whole prefab or what? This is little confusing for me