結構:
Root
|---- Child A
|---- Child B
|---- Child C
需求:
在代碼中讓Unity刪除一個GameObject下的所有子項
思路:
Unity中不能對GameObject對象使用GetComponent
所以可以用Transform來代替
解決:
Transform[] childs = Root.GetComponent<Transform>();
然後對childs[i].gameObject使用destroy等即可
注:記得i=0即是root本身,子項序號從i=1開始,這裏沒有再測試,請自行確認