0
當我嘗試設置父爲實例化對象,我得到這個錯誤:與對象設置父問題
Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption.
UnityEngine.Transform:SetParent(Transform)
我搜索谷歌因爲同樣的錯誤,它似乎不是成爲問題在我的情況。
代碼:
[SerializeField] GameObject scoreboardItem;
[SerializeField] Transform playerList;
GameObject itemGO = (GameObject) Instantiate(scoreboardItem);
itemGO.transform.SetParent(playerList);
解決什麼解決?
確保playerList變換拖放到檢查器來自「Hierarchy」面板而不是「Project」面板。 – Hellium
如果我這樣做了,那麼我就不能使用預製件。我也試圖通過GameObject.FindGameObjectWithTag()找到playerList,但是同樣的錯誤。 –