Hey guys this is my first post asking for awnsers and i am wondering how i would go about picking a random child from a parent of 125 children and destroying ONE alone, not all at once.
Here is my current code
for(var i = 0; i < 4;i++)
{
var AmountDestroy = Random.Range(1,100); // The amount of children to be destroyed
var createdchunk = Instantiate(PreChunk,Vector3(1*i,1*i,1*i), Quaternion.identity);
for (var del = 0; del < AmountDestroy; del++)
{
// Need the Child destruction here
}
Thank you to whoever is willing to help
Can you assign a unique name with a number in it to your children?
If yes, I’ll go with something like that :
for(var i = 0; i < 4;i++)
{
var AmountDestroy = Random.Range(1,100); // The amount of children to be destroyed
var createdchunk = Instantiate(PreChunk,Vector3(1*i,1*i,1*i), Quaternion.identity);
for (var del = 0; del < AmountDestroy; del++)
{
var randChildNr=Random.Range(1,125);
destroy(transform.find("sometexthere"+randChildNr))
}
The easiest way is to use GetChild together with childCount. GetChild is no longer described in the documentation, but as afaik it’s still there.
for(var i = 0; i < 4;i++)
{
var AmountDestroy = Random.Range(1,100); // The amount of children to be destroyed
var createdchunk = Instantiate(PreChunk,Vector3(1*i,1*i,1*i), Quaternion.identity);
for (var del = 0; del < AmountDestroy; del++)
{
var index = Random.Range(0,tranform.childCount);
Destroy(transform.GetChild(index).gameObject);
}
}