2
我想寫一個簡單的腳本,獲取一個遊戲對象的孩子計數,然後銷燬最後一個孩子(我希望它基本上像一個刪除鍵的功能),但我會得到錯誤:Can't remove RectTransform because Image (Script) depends on it
。有人能告訴我如何解決這個問題嗎?簡單的方法來刪除遊戲對象的最後一個孩子
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
public class DeleteSymbol : MonoBehaviour, IPointerClickHandler
{
public GameObject deleteButton;
public GameObject encodePanel;
public GameObject decodePanel;
#region IPointerClickHandler implementation
public void OnPointerClick (PointerEventData eventData)
{
int numChildren = encodePanel.transform.childCount; // get child count
Debug.Log("There are " + numChildren + " children");
if (numChildren > 0)
{
Destroy(encodePanel.transform.GetChild(numChildren - 1)); // destroy last child
}
}
#endregion
}