Search Unity

[Admob] Interstitial script The type `InterstitialAd' does not contain a constructor

Discussion in 'Scripting' started by maurostancato, Mar 22, 2019.

  1. maurostancato

    maurostancato

    Joined:
    Jul 14, 2017
    Posts:
    2
    Hello everyone, how are you? I'm fine.
    I'm trying to write the scripts for monetizate my game with Google AdMob.
    I have to make two scripts, one for my BannerAd and the second for the interstitial.

    This is my script for interstitialAd. I have written the code that loads and shows the ad.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using GoogleMobileAds.Api;
    5.  
    6. public class InterstitialAd : MonoBehaviour {
    7. private InterstitialAd interstitial;
    8.  
    9. private void requestInterstitial() {
    10.     //Los siguientes adUnitId son anuncios de prueba, antes de publicarlo debo reemplazar adUnitId con el id del bloque de anuncios
    11.     #if UNITY_ANDROID
    12.         string adUnitId = "ca-app-pub-3940256099942544/1033173712";
    13.     #elif UNITY_IPHONE
    14.         string adUnitId = "ca-app-pub-3940256099942544/4411468910";
    15.     #else
    16.         string adUnitId = "unexpected_platform";
    17.     #endif
    18.    
    19.     // Initialize an InterstitialAd. //Id Del bloque de anuncios
    20.     this.interstitial = new InterstitialAd("ca-app-pub-3940256099942544/1033173712");
    21.     // Use this for initialization
    22.      // Create an empty ad request.
    23.     AdRequest request = new AdRequest.Builder().Build();
    24.     //Load the interstitial with the request interstitial
    25.      this.interstitial.LoadAd(request);
    26. }
    27.     //ShowAd
    28. private void showInterstitial() {
    29.  
    30.     if (Time.time % 45 == 0 && Time.timeSinceLevelLoad > 60 && this.interstitial.IsLoaded()) {
    31.                 this.interstitial.Show();
    32.                
    33.             }
    34. }
    35.        
    36.  
    37.  
    38. }
    39.  
    40.  


    But I have an error that says

    Assets/Scripts/InterstitialAd.cs(20,25): error CS1729: The type `InterstitialAd' does not contain a constructor that takes `1' arguments

    Assets/Scripts/InterstitialAd.cs(25,24): error CS1061: Type `InterstitialAd' does not contain a definition for `LoadAd' and no extension method `LoadAd' of type `InterstitialAd' could be found. Are you missing an assembly reference?

    Assets/Scripts/InterstitialAd.cs(30,79): error CS1061: Type `InterstitialAd' does not contain a definition for `IsLoaded' and no extension method `IsLoaded' of type `InterstitialAd' could be found. Are you missing an assembly reference?

    Assets/Scripts/InterstitialAd.cs(31,23): error CS1061: Type `InterstitialAd' does not contain a definition for `Show' and no extension method `Show' of type `InterstitialAd' could be found. Are you missing an assembly reference?


    Hope you can help me ! Thanks, Mauro
     
  2. maurostancato

    maurostancato

    Joined:
    Jul 14, 2017
    Posts:
    2
    I continue with the problem, hope someone can help me ! Thanks a lot
     
  3. sliptrixx

    sliptrixx

    Joined:
    Mar 24, 2016
    Posts:
    12
    The problem is that you have the class name as 'InterstitialAd' which overrides the class in Admob, so rename it to something else like 'InterstitialAdScript'.
     
    SametJR and unity_-rSdmh4K0rc9aw like this.
  4. ishan711997

    ishan711997

    Joined:
    Apr 11, 2020
    Posts:
    19