Hello there, I'm trying to show Interstitial ads in my game after I die in my game
it already shows this
![alt text][1]
so, when I build the game in Android Platform
and then test to die
the ad doesn't show up and the scene doesn't rebuild (I think duo to the code is not working so the codes below it will not work)
anyway, here is codes of my ads
Interstitial ad code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Advertisements;
public class InterstitialAds : MonoBehaviour, IUnityAdsLoadListener, IUnityAdsShowListener
{
[SerializeField] string _androidAdUnitId = "Interstitial_Android";
[SerializeField] string _iOsAdUnitId = "Interstitial_iOS";
string _adUnitId;
void Awake()
{
_adUnitId = (Application.platform == RuntimePlatform.IPhonePlayer) ? _iOsAdUnitId : _androidAdUnitId;
LoadAd();
}
public void LoadAd()
{
Debug.Log("Loading Ad: " + _adUnitId);
Advertisement.Load(_adUnitId, this);
}
public void ShowAd()
{
Debug.Log("Showing Ad: " + _adUnitId);
Advertisement.Show(_adUnitId, this);
LoadAd();
}
public void OnUnityAdsAdLoaded(string adUnitId) { }
public void OnUnityAdsFailedToLoad(string adUnitId, UnityAdsLoadError error, string message)
{
Debug.Log($"Error loading Ad Unit: {adUnitId} - {error.ToString()} - {message}");
}
public void OnUnityAdsShowFailure(string adUnitId, UnityAdsShowError error, string message)
{
Debug.Log($"Error showing Ad Unit {adUnitId}: {error.ToString()} - {message}");
}
public void OnUnityAdsShowStart(string adUnitId) { }
public void OnUnityAdsShowClick(string adUnitId) { }
public void OnUnityAdsShowComplete(string adUnitId, UnityAdsShowCompletionState showCompletionState) { }
}
Ads code
using UnityEngine;
using UnityEngine.Advertisements;
public class Ads : MonoBehaviour, IUnityAdsInitializationListener
{
[SerializeField] string _androidGameId = "4946063";
[SerializeField] string _iOSGameId = "4853962";
[SerializeField] bool _testMode = true;
private string _gameId;
void Awake()
{
InitializeAds();
}
public void InitializeAds()
{
_gameId = (Application.platform == RuntimePlatform.IPhonePlayer)
? _iOSGameId
: _androidGameId;
Advertisement.Initialize(_gameId, _testMode, this);
}
public void OnInitializationComplete()
{
Debug.Log("Unity Ads initialization complete.");
}
public void OnInitializationFailed(UnityAdsInitializationError error, string message)
{
Debug.Log($"Unity Ads Initialization Failed: {error.ToString()} - {message}");
}
}
I'm pretty sure I used the correct Game ID as you can see in picture
![alt text][2]
idk, if I should put my game id or not, if not, make sure to tell me so I can delete it
oh, almost forgot, to show ads I wrote this code in Die Script
FindObjectOfType< (InterstitialAds) >().ShowAd();
forget about these () in InterstitialAds, unity answers can't just recognize it normally
I hope someone give me solution for this as soon as possible
[1]: /storage/temp/200192-screenshot-2022-09-26-203749.png
[2]: /storage/temp/200190-screenshot-2022-09-26-204847.jpg
↧