I want to make a game when a player touches screen, a gem is showing up on the screen, but I have an error Fatal error: Unexpectedly found nil while unwrapping an Optional value. How to fix it?
I doing this:
var gem : SKSpriteNode!
override func touchesBegan(_ touches: Set<UITouch>, with the event: UIEvent?) {
gem = SKSpriteNode(fileNamed: "CoolGem")!
gem.position = CGPoint(x: 0, y: 0)
addChild(gem)
gem.run(SKAction.move(to: CGPoint(x: Double.random(in: -100...100), y: Double.random(in: -100...100)), duration: 1))
}
The error tells me this: Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value on the 3rd line