我想从我的场景中删除一个实体。
我在 UpdateUIView 函数中创建了我的实体,如下所示:
// create anchor and model-Entity
let anchor = AnchorEntity(plane: .horizontal)
let cube = MeshResource.generateBox(size: 0.1, cornerRadius: 0.03)
let material = SimpleMaterial(color: .gray, roughness: 0.2, isMetallic: true)
let cubeEntity = ModelEntity(mesh: cube, materials: [material])
anchor.addChild(cubeEntity)
uiView.scene.addAnchor(anchor)
现在我想通过在我的用户界面中按一个按钮来删除它。通过按下按钮,我将 var 从 false 更改为 true。然后我在 UpdateUIView 函数里面写了:
if remove == true {
uiView.scene.removeAnchor(anchor)
}
当我按下按钮时,它会将布尔值更改为 true,但实体不会消失。
关于如何解决这个问题的任何建议?