使用未解析的标识符 'path' SKShapeNode

Use of unresolved identifier 'path' SKShapeNode

我正在尝试使用 SKShapeNode 创建常量。在过去的一个小时里,我遇到了这个 1 错误。请帮助我,我将不胜感激。

import SpriteKit

class GameScene: SKScene {
    override func didMove(to view: SKView) {

        func setupPlayerAndObstacles() {
            addObstacle()
        }

        func addObstacle() {
            addCircleObstacle()

            let section = SKShapeNode(path: path.cgPath) //this line is showing error. Use of unresolved identifier 'path'//
            section.position = CGPoint(x: size.width/2, y: size.height/2)
            section.fillColor = .yellow
            section.strokeColor = .yellow
            addChild(section)
        }

        func addCircleObstacle() {

            let path = UIBezierPath()
            path.move(to: CGPoint(x: 0, y: -200))
            path.addLine(to: CGPoint(x: 0, y: -160))
            path.addArc(withCenter: CGPoint.zero, radius: 160, startAngle: CGFloat(3.0 * .pi / 2), endAngle: CGFloat(0), clockwise: true)
            path.addLine(to: CGPoint(x: 200, y: 0))
            path.addArc(withCenter: CGPoint.zero, radius: 200, startAngle: CGFloat(0.0), endAngle: CGFloat(3.0 * .pi / 2), clockwise: false)

        }

        setupPlayerAndObstacles()

    }
}

变量 path 在 addObstacle 函数中不可见。 如果您要在其他函数中使用它,请将其声明为 class var。

class GameScene: SKScene {
var path = UIBezierPath()
 ...
}