using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using GoogleMobileAds.Api;
using GoogleMobileAds.Common;
using System;
using System.Collections.Generic;
using System.Collections;
using UnityEngine.SceneManagement;
public class Admobb : MonoBehaviour
{
public GameObject yukleniyor;
public GameObject yukleniyor2;
public string _adUnitId ="ca-app-pub-3940256099942544/1033173712";
private InterstitialAd reklamObjesi;
void Start()
{
MobileAds.Initialize( reklamDurumu => { } );
YeniReklamAl( null, null );
}
public void ShowAd()
{
if (reklamObjesi != null && reklamObjesi.CanShowAd())
{
Debug.Log("Showing interstitial ad.");
yukleniyor.SetActive(false);
reklamObjesi.Show();
}
else
{
Debug.LogError("Interstitial ad is not ready yet.");
}
}
public void YeniReklamAl( object sender, EventArgs args )
{
if (PlayerPrefs.GetString("durum") == "menu")
{
SceneManager.LoadScene("Menu");
PlayerPrefs.SetString("durum","bos");
Time.timeScale = 1f;
}
if (PlayerPrefs.GetString("durum") == "oyun3")
{
SceneManager.LoadScene("oyun3");
PlayerPrefs.SetString("durum","bos");
Time.timeScale = 1f;
}
if (PlayerPrefs.GetString("durum") == "oyun2")
{
SceneManager.LoadScene("oyun2");
PlayerPrefs.SetString("durum","bos");
Time.timeScale = 1f;
}
if (PlayerPrefs.GetString("durum") == "oyun1")
{
SceneManager.LoadScene("Oyun");
PlayerPrefs.SetString("durum","bos");
Time.timeScale = 1f;
}
if( reklamObjesi != null )
reklamObjesi.Destroy();
AdRequest request = new AdRequest.Builder().Build();
InterstitialAd.Load(_adUnitId,request, (InterstitialAd ad, LoadAdError loadad) =>
{
if (loadad != null)
{
Debug.LogError("interstitial ad failed to load an ad " +
"with error : " + loadad);
return;
}
else
if (ad == null)
{
return;
}
Debug.Log("Interstitial ad loaded");
reklamObjesi = ad;
});
reklamObjesi.OnAdFullScreenContentClosed += () =>
{
if (PlayerPrefs.GetString("durum") == "menu")
{
SceneManager.LoadScene("Menu");
PlayerPrefs.SetString("durum","bos");
Time.timeScale = 1f;
}
if (PlayerPrefs.GetString("durum") == "oyun3")
{
SceneManager.LoadScene("oyun3");
PlayerPrefs.SetString("durum","bos");
Time.timeScale = 1f;
}
if (PlayerPrefs.GetString("durum") == "oyun2")
{
SceneManager.LoadScene("oyun2");
PlayerPrefs.SetString("durum","bos");
Time.timeScale = 1f;
}
if (PlayerPrefs.GetString("durum") == "oyun1")
{
SceneManager.LoadScene("Oyun");
PlayerPrefs.SetString("durum","bos");
Time.timeScale = 1f;
}
}; // Kullanıcı reklamı kapattıktan sonra çağrılır
reklamObjesi.OnAdImpressionRecorded += () =>
{
ReklamIstegiOlustur();
};
}
private AdRequest ReklamIstegiOlustur()
{
return new AdRequest.Builder().Build();
}
void OnDestroy()
{
if( reklamObjesi != null )
reklamObjesi.Destroy();
}
public void Reklam()
{
yukleniyor.SetActive(true);
yukleniyor2.SetActive(false);
ShowAd();
}
}