Hi!
I want to destroy gameObject children, but gameObject dont.
First i tried:
var children = player.GetComponentsInChildren(Transform);
for (var c in children)
{
Destroy(c.gameObject);
}
Destroyed children as i wanted, but with a little bonus - it also destroyed the parent that I dont want
Second approach:
var children = player.GetComponentsInChildren(Transform);
for (var c in children)
{
if(c.gameObject&&c.gameObject!=player) Destroy(c.gameObject);
}
Doesnt destroy anything at all - weird.
Third approach:
var children = player.GetComponentsInChildren(Transform);
for (var c in children)
{
if(c.gameObject&&!c.gameObject.CompareTag("Player")) Destroy(c.gameObject);
}
The same as third approach.
Can someone point what im doing wrong?
Maybe i am too tired and cant see the problem.