所以基本上我尝试将绿色设置为我的立方体,但我收到此错误:C 希望大家能帮助我
这是我的代码:
func randomFloat(min: Float, max: Float) -> Float {
return (Float(arc4random()) / 0xFFFFFFFF) * (max - min) + min
}
let zCoords = randomFloat(min: -2, max: -0.2)
let cubeNode = SCNNode(geometry: SCNBox(width: 0.1, height: 0.1, length: 0.1, chamferRadius: 0))
cubeNode.position = SCNVector3(0, 0, zCoords)
let mate = SCNMaterial()
mate.diffuse.contents = UIColor.green
cubeNode.materials = [mate]
sceneView.scene.rootNode.addChildNode(cubeNode)
最佳答案
您会收到该错误,因为只有 SCNGeometry
具有属性 materials
,而 SCNNode
没有。因此,您必须访问节点的几何图形
才能向其添加SCNMaterial
。
cubeNode.geometry.materials = [mate]
但是,由于您只添加单一 Material ,因此也可以使用
cubeNode.geometry.firstMaterial = mate
关于swift - 如何修复 Xcode ARKit 中类型 'SCNNode' 的值没有成员 'materials',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50200301/