基本上我尝试将绿色设置为我的立方体,但是我得到了这个错误: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)
答案 0 :(得分:1)
您收到该错误,因为SCNGeometry
只有materials
属性,SCNNode
没有。因此,您必须访问节点的geometry
才能向其添加SCNMaterial
。
cubeNode.geometry.materials = [mate]
但是,由于您只添加了一种材料,因此您也可以使用
cubeNode.geometry.firstMaterial = mate