I want to change the text of a SKLabelNode created in the scene editor named myScoreLabel to update a score on collision of two objects. Here's the relevant code:
class holeOne: SKScene, SKPhysicsContactDelegate {
var myScoreLabel: SKLabelNode!
var myscore:Int = 0
func addScore() {
myscore += 1
myScoreLabel.text = "\(myscore)"
}
func didBegin(_ contact: SKPhysicsContact) {
addScore()
}
}
At the moment after the collision the app crashes with "unexpectedly found nil while unwrapping an Optional value". What am I doing wrong and how can I do it right? Thanks!