ontriggerenter wont destroy object Weird Beauvoirm,

Hi,

I have no idea what is going on in this small script, the other.gameobject wont destroy if its in a IF statement but if I put it in the open ontriggerenter it will destroy but then it destroy generally all triggers… I’ve been puzzled over this for 2 days. anyone know what am I doing wrong? Thanks.

void OnTriggerEnter(Collider other)
{
bool kill = false;
int layerNum = other.gameObject.layer;
if (layerNum == 14)
{
kill = true;
temp = elemnts[other.tag];
GameObject fx = (GameObject)Instantiate(temp, other.transform.position, Quaternion.Euler(0, 0, 0));
fx.transform.parent = this.transform;
}
if (kill)
{
Debug.Log(“inKill”);//however this is called
Destroy(other.gameObject);//this wont work
}

}

First, lets start with code tags Using code tags properly - Unity Engine - Unity Discussions
They are a huge help in making your code readable.

Does your first IF statement run correctly?

hmm I see, I’m not certain but from what I see:

int layerNum = other.gameObject.layer; and
Destroy(other.gameObject);//this wont work,

If you have any other “.layer(s)” assigned to “other.gameObject”
they will be destroyed when you destroy the parent “other.gameObject”,

maybe something like “Destroy(other.gameObject.layer(14));” if you can write it like that.

Thanks, It was a bug in the Curvy Asset I use to instantiate the other object.