Destroying Part of a prefab

Is it possible to use C# script to destroy a part of a prefab?
I have a prefab that is made from 3 cubes and in a certain condition I want to destroy one of those cube…
Any suggestions?

Thank you

The GameObject that you have the script attached to can’t access its children directly. That GameObject does, however, have a transform that can then reference the children.
It would look something like this (untested but I think it should work):

//The parent gameobject in the example below is called "prefab"
foreach (Transform child in prefab.transform) {
    //check the name of the child to get the one you want to delete
    if (child.name == "name of child you want to delete") {
        Destroy(child.gameObject);
    }
}
1 Like