小编EAY*_*AJB的帖子

Unity GameObject.Destroy() 不适用于直接引用

我正在努力找出列表中预制件上的 GameObject.Destroy(destroyCell) 函数的问题。我已经表明,在调用 Destroy 并将其从列表中删除之前,通过调用 destroyCell.Select() {内部函数以突出显示 Cell 对象},可以直接引用该对象。列表计数显示对象已被删除,但 Destroy 未生效。

总体思路是从相对于距原点拖动距离的单元格添加到容器对象的位置单击并拖动,并在移回原点时删除单元格。

添加和删​​除单元的机制如下所示:

if (mouseDistFromOrigin < prevDragInteractFloorValue && cellsToModify.Count > 1)
{
    // REMOVE CELL
    cellsAvailableToGenerate++;
    energyAvailable += CellHelper.EnergyGainPerCell;

    nextCellYOffset /= CellHelper.NewCellGrowthRatio;
    dragInteractFloorValue = prevDragInteractFloorValue;
    prevDragInteractFloorValue -= nextCellYOffset * cellsToModify[cellsToModify.Count - 1].transform.localScale.y;

    //var containerCells = container.GetComponentsInChildren<Cell>();
    //Debug.Log("CELLS " + containerCells.Length);
    //var destroyCell = containerCells[containerCells.Length - 1];
    //GameObject.Destroy(destroyCell);
    //GameObject.Destroy(containerCells[containerCells.Length - 1]);

    Debug.Log("CELLS: " + cellsToModify.Count);

    var destroyCell = cellsToModify[cellsToModify.Count - 1];
    destroyCell.Select();
    cellsToModify.Remove(destroyCell);
    GameObject.Destroy(destroyCell);

    Debug.Log("CELLS: " + cellsToModify.Count);
} else if …
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine

2
推荐指数
1
解决办法
3302
查看次数

标签 统计

c# ×1

unity-game-engine ×1