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.
no problem - ive got expierience in both languages. Thanks for answer!
– Sacristan_Gchecked the marked answer, and found an error, so I ajusted my own code to be correct.
– BerggreenDKNice snippet, thats what I found out too after some testing!
– ocimum