How to display score in different scene

183 views Asked by At

I'm making a game and I have a function that calculates the score and displays it on the screen. When the game ends it transitions into a new scene, (game over screen). I was wondering what method I can use to display my score on the second scene after it transitions. My code is:

var score = 0
var scoreLabel = SKLabelNode()

func updateScore() {

    score++
    scoreLabel.text = String(score)
}
1

There are 1 answers

0
Seth Rodgers On

When initializing the scene that you are going to change to, you can pass the value. You will need to make an int for the score in the next scene, and can say nextScene.score = score