Search Unity

Question Interstitial Ads on GameOver

Discussion in 'Unity Ads & User Acquisition' started by PapayaLimon, Nov 29, 2022.

  1. PapayaLimon

    PapayaLimon

    Joined:
    Aug 22, 2018
    Posts:
    85
    Hello! I'm new at coding stuff and I know this is a noob question. I have my game ready but I'm having issues adding my InterstitialAds to show when GameOver.

    I have my code working Onclick button as samples provided. But how do I tell my main code to LoadAd on GameOver? I have my game script on one file and all the InterstitialAds in another script file. May I attach both files on the same game object? And if thats the case, how do I call my InterstitialAds script to execute on my main game script? Thanks in advance and sorry for such dump question.
     
  2. PapayaLimon

    PapayaLimon

    Joined:
    Aug 22, 2018
    Posts:
    85
    I have followed this tutorial:



    But if I add:

    Code (CSharp):
    1. public class Game : MonoBehaviour {
    2. private InterstitialAd interstitialAd;
    (My InterstitialAd script is called InterstitialAd.cs)

    Unity is keep me calling this error:

    Code (CSharp):
    1. The type or namespace name 'InterstitialAd' could not be found (are you missing a using directive or an assembly reference?
    Why is not reading my script? I have Game.cs and InterstitialAd.cs on same object.

    Ideas?
     
  3. Yasuyuki

    Yasuyuki

    Unity Technologies

    Joined:
    Sep 11, 2014
    Posts:
    153
    Hello,
    Can you please paste the entire scripts of Game.cs and InterstitialAd.cs? So I can investigate further :)
     
  4. PapayaLimon

    PapayaLimon

    Joined:
    Aug 22, 2018
    Posts:
    85
    I have fixed just copying from original file, now works, but was the same code :confused:. Still a noob on this stuff, but learning in the process. Just change InterstitialAd.cs to InterstitialAds.cs

    Code (CSharp):
    1. public class Game : MonoBehaviour
    2. {
    3.    private InterstitialAds interstitialAds;  
    4. }
    Code (CSharp):
    1. void Awake ()
    2.     {
    3.         interstitialAds = GetComponent<InterstitialAds>();
    4.     }
    Code (CSharp):
    1. public void GameOver()
    2.     {
    3.         interstitialAds.ShowInterstitial();
    4.    }