Hi, is there a way to remove specific instance of component if there are more components of same type? Say, I have X component that is doing something, when it ends it should delete itself, normally I use
Destroy(GetComponent(typeof(X)));
but there is no quarranty that it will return this specific instance. Also
Destroy(this);
not works too.
Thanks in advance,
Paul
I realize this is a SUPER old post, but I was also trying to achieve this. I figured I’d leave the approach I ended up using just in case anyone else needs it.
//Get a reference to all of the BoxCollider2D components
BoxCollider2D[] BoxList = this.GetComponents<BoxCollider2D>();
//if there are more than 0, then search through each one
for(int i = 0; i< BoxList.Length;i++)
{
//check a paramater here to compare
if (BoxList*.size.x>.5f)*
{
//execute code for matched parameters
Destroy(BoxList*);*
}
}
Hope this helps @legion_44 or anyone else. Happy coding