I am fairly new to AdMob. I tried looking up problem online and here but I can't find a solution that works for me.
So basically I am trying to create this game using Swift and in the gameviewcontroller
I create 3 functions that create the ad and then I want to call them in my StartMenu scene.
Here is my functions for ad interstitial in gameviewcontroller
:
func getInterstitialAd(){
interstitial = GADInterstitial(adUnitID: "AdMob Unit ID")
let interstitialRequest = GADRequest()
interstitial.load(interstitialRequest)
}
func showAd() {
print(interstitial.isReady)
if interstitial.isReady {
interstitial.present(fromRootViewController: self)
} else {
interstitial = createAd()
print("Ad wasn't ready")
}
}
func createAd() -> GADInterstitial{
let interstital = GADInterstitial(adUnitID: "AdMob Unit ID")
interstitial.load(GADRequest())
return interstital
}
and in my StartMenu Scene:
var viewController = GameViewController()
I have this in my game over function and it basically gets called when the player dies:
viewController.getInterstitialAd()
viewController.showAd()
And every time the player dies it prints false
and ad wasn't ready.