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;多次打电话...您可以移动它。 –