mercredi 31 mai 2017

If (Variable == Variable + 5) in Swift3

I am trying to show a certain medal in my scene depending on what your high score is based on the goal of the level.

// Get Medal Colour
    if levelHighscore < goalScore {
        scoreMedal = SKSpriteNode(imageNamed: "noMedal")
    } else if levelHighscore == goalScore {
        scoreMedal = SKSpriteNode(imageNamed: "bronzeMedal")
    } else if levelHighscore > goalScore {
        scoreMedal = SKSpriteNode(imageNamed: "silverMedal")
    }

At the moment i get the high score and compare it to the goal - if it is less than the goal show noMedal image. If it equals the goal show a bronzeMedal, If the high score is 5 more than the goal show silverMedal and if the high score is 10 higher than the goal show a goldMedal.

Been on this for a while trying all different bits and bobs and for some reason it works in the setup above but when i write

    // Get Medal Colour
    if levelHighscore == goalScore+5 {
        scoreMedal = SKSpriteNode(imageNamed: "silverMedal")
    } 

it shows nothing.

Aucun commentaire:

Enregistrer un commentaire