Question by
QQQ_QQQ · Nov 29, 2019 at 10:45 AM ·
gameobjectscript.destroyprefab-instance
Instantiated bullet wont destroy
Hello, I have a strange problem. My prefab should be destroyed when touching an Enemy. It is OK when I drag my prefab from Assets to Hierarchy and start a game. But when i instantiate this prefab during the game from another script it is not destroying.
Prefab consists of empty game object and 2 child objects inside (2 bullets). Script on this prefab is like this:
private void OnTriggerEnter2D(Collider2D collision) {
if (collision.gameObject.tag == "Enemy")
{
FX();
collision.GetComponent<EnemyBehaviour>().ReceiveDamage();
Destroy(gameObject);
}
}
FX() is starting fine Damage is fine but the last step wont work.
Comment
Answer by Sgt_Spike · Nov 29, 2019 at 08:18 PM
Hey, can't say for certain as haven't tried it but instead of 'Destroy(gameObject)' try 'Destroy(collision.gameObject)'.