使用SCNNode和hitTest

时间:2017-12-04 00:50:47

标签: ios swift scenekit

当hitTest()返回命中的节点时,如何访问节点的属性/方法?

我有一个SCNNode,我添加到我的场景并将name属性设置为“ball1”,但是当我执行hitTest()时,我无法访问原始节点属性。这是为什么?

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    if touches.first != nil {

        // We use center because that is where the crosshair is
        let hitList = sceneView.hitTest(centerPointOfScreen, options: nil)


        if let hitObject = hitList.first {
            let node = hitObject.node
            print(node.name) // I get an error saying that is property 
            doesn't exist
        }

    }
}

0 个答案:

没有答案