if player.hp <= 0 { // If you are dead. // Enter to GameOver State stateMachine?.enter(GameOverState.self) } } } class ClearState: GKState { override func didEnter(from previousState: GKState?) { let gameOverLabel = SKLabelNode(text: "Game Over") addChild(gameOverLabel) } } class GameScene: SKScene { private var stateMachine: GKStateMachine! override func didMove(to view: SKView) { super.didMove(to: view) stateMachine = GKStateMachine(states: [ ReadyState(), FleeState(), ChaseState(), ClearState(), ]) stateMachine.enter(MainState.self) } }