0

I have: GameViewController, where I setup a 3D scene and a function "fire". Then I have another SKScene, which is overlaid, so I cannot click the nodes on the 3D scene. On the SKScene I have a SKSpriteNode, "fireNode". After click of this fireNode I want to call a "fire "function in GameViewCOntroller. How can I do this?

mptaurus
  • 21
  • 4

1 Answers1

1

If your GameViewController is rootViewController I would go with something like this:

func fire() {
   guard let keyWindow = UIApplication.shared.windows.first(where: { $0.isKeyWindow })
   else { return }
        
   if let rootViewController = keyWindow.rootViewController as? GameViewController {
      rootViewController.onFire()
   }
 }

Edit:
Or you can just post notification with Notification Center to your view controller.

Stamenkovski
  • 959
  • 1
  • 6
  • 10
  • I was looking for an answer for a long time, and you solved the problem quickly and perfectly. It is working as I expected, Thanks a lot ! – mptaurus Feb 20 '21 at 08:18