Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Interstitial code

Discussion in 'LevelPlay' started by PapayaLimon, Dec 15, 2022.

  1. PapayaLimon

    PapayaLimon

    Joined:
    Aug 22, 2018
    Posts:
    85
    HellO! I have reading the Interstitial Integration for Unity Plugin - IronSource Knowledge Center tutorial but I think it's not clear how to load an interstitial. I have already get to add the banner with this code.

    Code (CSharp):
    1. IronSource.Agent.loadBanner(IronSourceBannerSize.BANNER, IronSourceBannerPosition.BOTTOM);
    2.  
    But when I tried to follow the tutorial for interstitial is not quite clear how to call it. i just want to call interstitial when GameOver, as in other forum I called like this in mediation:

    Code (CSharp):
    1. public class Game : MonoBehaviour
    2. {  private InterstitialAds interstitialAds; }
    Code (CSharp):
    1. void Awake ()
    2.     {  interstitialAds = GetComponent<InterstitialAds>();  }
    Code (CSharp):
    1. public void GameOver()
    2.     {   interstitialAds.ShowInterstitial();  }
    How do i call it in levelplay?
     
  2. PapayaLimon

    PapayaLimon

    Joined:
    Aug 22, 2018
    Posts:
    85
    Any ideas in this?
     
  3. LugaW22

    LugaW22

    Unity Technologies

    Joined:
    Aug 9, 2022
    Posts:
    1
    For the LevelPlay interstitial, following that doc, you can relace that GameOver() function with:

    Code (CSharp):
    1. void Awake ()
    2. { IronSource.Agent.loadInterstitial();  } // Step 2
    Code (CSharp):
    1. public void GameOver() {
    2.     if (IronSource.Agent.isInterstitialReady()) { // Step 3
    3.         IronSource.Agent.showInterstitial(); // Step 4
    4.     }
    5. }
     
  4. PapayaLimon

    PapayaLimon

    Joined:
    Aug 22, 2018
    Posts:
    85
    Ok, it's really frustrating about can't preview on editor. A lots of builds and don't get the code working OnGameOver. So I decided to make a sample scene and added same code as the tutorial and works fine. But when I remove LoadInterstitial Button and replace it with an OnAwake, it doesn't show up! Is anything wrong with code? Help? :(

    Code (CSharp):
    1.   void OnEnable()
    2.     {
    3.         IronSourceEvents.onSdkInitializationCompletedEvent += SdkInitializationCompletedEvent;
    4.         IronSourceEvents.onInterstitialAdReadyEvent += InterstitialAdReadyEvent;
    5.         IronSourceEvents.onInterstitialAdLoadFailedEvent += InterstitialAdLoadFailedEvent;
    6.         IronSourceEvents.onInterstitialAdShowSucceededEvent += InterstitialAdShowSucceededEvent;
    7.         IronSourceEvents.onInterstitialAdShowFailedEvent += InterstitialAdShowFailedEvent;
    8.         IronSourceEvents.onInterstitialAdClickedEvent += InterstitialAdClickedEvent;
    9.         IronSourceEvents.onInterstitialAdOpenedEvent += InterstitialAdOpenedEvent;
    10.         IronSourceEvents.onInterstitialAdClosedEvent += InterstitialAdClosedEvent;
    11.     }
    12.  
    13.     void Awake()
    14.     {    
    15.         IronSource.Agent.loadInterstitial();
    16.         Debug.Log("Ad Loaded");
    17.     }
    18.  
    19.     public void ShowInterstitial()
    20.     {
    21.         if (IronSource.Agent.isInterstitialReady())
    22.         {
    23.             IronSource.Agent.showInterstitial();
    24.         }
    25.     }
    26.  
    27.  
    28.     void SdkInitializationCompletedEvent()
    29.     {
    30.         Debug.Log("unity-script: I got SdkInitializationCompletedEvent");
    31.     }
    32.  
    33.     void InterstitialAdReadyEvent()
    34.     {
    35.         Debug.Log("unity-script: I got InterstitialAdReadyEvent");
    36.     }
    37.  
    38.     void InterstitialAdLoadFailedEvent(IronSourceError error)
    39.     {
    40.         Debug.Log("unity-script: I got InterstitialAdLoadFailedEvent, code: " + error.getCode() + ", description : " + error.getDescription());
    41.     }
    42.  
    43.     void InterstitialAdShowSucceededEvent()
    44.     {
    45.         Debug.Log("unity-script: I got InterstitialAdShowSucceededEvent");
    46.     }
    47.  
    48.     void InterstitialAdShowFailedEvent(IronSourceError error)
    49.     {
    50.         Debug.Log("unity-script: I got InterstitialAdShowFailedEvent, code :  " + error.getCode() + ", description : " + error.getDescription());
    51.     }
    52.  
    53.     void InterstitialAdClickedEvent()
    54.     {
    55.         Debug.Log("unity-script: I got InterstitialAdClickedEvent");
    56.     }
    57.  
    58.     void InterstitialAdOpenedEvent()
    59.     {
    60.         Debug.Log("unity-script: I got InterstitialAdOpenedEvent");
    61.     }
    62.  
    63.     void InterstitialAdClosedEvent()
    64.     {
    65.         Debug.Log("unity-script: I got InterstitialAdClosedEvent");
    66.     }
    67.  
     
  5. lujiawang22

    lujiawang22

    Joined:
    Jan 30, 2019
    Posts:
    1
    I suppose should initialize before load?
    Code (CSharp):
    1. IronSource.Agent.init(gameId);
     
  6. PapayaLimon

    PapayaLimon

    Joined:
    Aug 22, 2018
    Posts:
    85
    It works! Finally, thanks a lot!!! :):):)