// Help Pleaseこのコードは動作しません。これをXcodeからフィードバックします。 致命的なエラー:Swift NSUserDefaultsが予期せずnilを見つけたときにオプション値
var savedScore = NSUserDefaults.standardUserDefaults().objectForKey("HighestScore") as! Int
import SpriteKit
class GameScene: SKScene {
var highestScore:Int = 2
var score = Int()
override func didMoveToView(view: SKView) {
/* Setup your scene here */
//To save highest score
//To get the saved score
var savedScore = NSUserDefaults.standardUserDefaults().objectForKey("HighestScore") as! Int
print(savedScore)
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
/* Called when a touch begins */
score += 1
print("Score - \(score)")
if score > highestScore
{
highestScore = score
NSUserDefaults.standardUserDefaults().setObject(highestScore, forKey:"HighestScore")
NSUserDefaults.standardUserDefaults().synchronize()
print("Beat")
}
else {
print("Not Beat")
}
}
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
}
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
}
}
ようこそ!新しい問題を含めるために質問を編集しないでください。代わりに、新しい質問を作成します。 – Matt