Hello everyone,
I have tried many things but I could not make interstitial ads display. I want to show interstitial ads after users select a wrong answer and before the score page (“Notice” scene) displays. Here is my code, I just copied relevant parts:
using UnityEngine;
using UnityEngine.UI;
using System.Text;
using System.Xml;
using System.Collections;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Serialization;
using System.IO;
using GoogleMobileAds;
using GoogleMobileAds.Api;
public class responder : MonoBehaviour
{
private InterstitialAd interstitial;
private int gecis;
public Text questionsorular;
public Text responseA;
public Text responseB;
public Text responseC;
public Text responseD;
public Text infoResponses;
public Text infoResponses1;
public Text example;
public Text dogrusayisi;
private float corrects;
private float questoesquestions;
private float media;
private int Notice;
}
void Start()
{
RequestInterstitial();
}
public void response(string alternative)
{
RequestInterstitial();
if (alternative == "A")
{
if (responseA.text == infoResponses.text)
{
corrects += 1;
nextQuestion();
}
else
{
Invoke("wrong", 1);
}
}
else if (alternative == "B")
{
if (responseB.text == infoResponses.text)
{
corrects += 1;
nextQuestion();
}
else
{
Invoke("wrong", 1);
}
}
else if (alternative == "C")
{
if (responseC.text == infoResponses.text)
{
corrects += 1;
nextQuestion();
}
else
{
Invoke("wrong", 1);
}
}
else if (alternative == "D")
{
if (responseD.text == infoResponses.text)
{
corrects += 1;
nextQuestion();
}
else
{
Invoke("wrong", 1);
}
}
}
void wrong()
{
ShowInterstitial();
Application.LoadLevel("Notice");
}
private void RequestInterstitial()
{
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = "MY ADS ID";
#elif UNITY_IPHONE
string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";
#else
string adUnitId = "unexpected_platform";
#endif
// Create an interstitial.
interstitial = new InterstitialAd(adUnitId);
// Load an interstitial ad.
interstitial.LoadAd(createAdRequest());
}
private AdRequest createAdRequest()
{
return new AdRequest.Builder()
.AddTestDevice(AdRequest.TestDeviceSimulator)
.AddTestDevice("0123456789ABCDEF0123456789ABCDEF")
.AddKeyword("game")
.SetGender(Gender.Male)
.SetBirthday(new DateTime(1985, 1, 1))
.TagForChildDirectedTreatment(false)
.AddExtra("color_bg", "9B30FF")
.Build();
}
private void ShowInterstitial()
{
if (interstitial.IsLoaded())
{
interstitial.Show();
}
}
Following code works perfectly for banner ads when I attached it to camera:
using UnityEngine;
using GoogleMobileAds.Api;
public class Ads : MonoBehaviour
{
void Start()
{
BannerView adsObject = new BannerView(
"MY ADS ID", AdSize.SmartBanner, AdPosition.Bottom);
AdRequest getAds = new AdRequest.Builder().Build();
adsObject.LoadAd(getAds);
}
}