void CreateCubesBesideWaypoints()
{
const int lightCount = 20;
Vector3[] lightPositions = new Vector3[lightCount];
for (int i = 0; i < waypoints.Length - 1; i++)
{
posToChunkDistances(waypoints[i].transform.position, waypoints[waypoints.Length - 1].transform.position, lightPositions, lightCount);
for (int x = 0; x < lightPositions.Length; x++)
{
lightPrefab.GetComponent<Renderer>().material.color = Color.red;
GameObject cloneLightPrefab = Instantiate(lightPrefab, lightPositions[x], Quaternion.identity);
cloneLightPrefab.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
cloneLightPrefab.tag = "LightPrefab";
//cloneLightPrefab.transform.SetParent(lightPrefab.transform);
}
}
}
這種方式工作正常。但如果我使用該行:爲什麼當我克隆/複製gameobject內存使用率達到98%?
cloneLightPrefab.transform.SetParent(lightPrefab.transform);
然後內存使用率達到98%,我需要重新啓動電腦。 lightPrefab是一個立方體遊戲對象,我拖動到這個腳本。 而我想要做的是將所有新的cloneLightPrefab gameobjects放在lightPrefab下作爲孩子。
和子問題,在上線內環:
for (int x = 0; x < lightPositions.Length; x++)
我應該將其更改爲:
for (int x = 0; x < lightPositions.Length - 1; x++)
lightPrefab.GetComponent().material.color = Color.red;多次打電話...您可以移動它。 –