Hi so I am having a strange issue. I have a banner ad that shows up a few seconds after starting the game that I developed. Test ads work just fine, the Unity Ads test ad shows up in the banner after a few seconds the game has started. But I am trying to get production ads to work (real ads), and I have set testMode to false. I have also Forced test mode OFF in the operate dashboard. But when I start the game and when the banner is supposed to show up, the game just closes itself on my Android device. Here are the logs from logcat:
05-01 21:59:15.238 30169 30188 I Unity : Unity Ads initialized: True
05-01 21:59:15.238 30169 30188 I Unity : App_Initialize:Start()
05-01 21:59:15.238 30169 30188 I Unity :
05-01 21:59:15.238 30169 30188 I Unity : (Filename: ./Runtime/Export/Debug.bindings.h Line: 45)
05-01 21:59:15.238 30169 30188 I Unity :
05-01 21:59:15.240 30169 30188 I Unity : Unity Ads is supported: True
05-01 21:59:15.240 30169 30188 I Unity : App_Initialize:Start()
05-01 21:59:15.240 30169 30188 I Unity :
05-01 21:59:15.240 30169 30188 I Unity : (Filename: ./Runtime/Export/Debug.bindings.h Line: 45)
05-01 21:59:15.240 30169 30188 I Unity :
05-01 21:59:15.241 30169 30188 I Unity : Unity Ads is showing: False
05-01 21:59:15.241 30169 30188 I Unity : App_Initialize:Start()
05-01 21:59:15.241 30169 30188 I Unity :
05-01 21:59:15.241 30169 30188 I Unity : (Filename: ./Runtime/Export/Debug.bindings.h Line: 45)
05-01 21:59:15.241 30169 30188 I Unity :
05-01 21:59:19.429 2591 2611 I ActivityManager: Start proc 30241:com.android.chrome:sandboxed_process0/u0i25 for webview_service com.NoCompany.BalloonBeachRun/org.chromium.content.app.SandboxedProcessService0
05-01 21:59:20.338 2591 3670 I ActivityManager: Process com.android.chrome:sandboxed_process0 (pid 30241) has died: fore TOP
05-01 21:59:20.339 2591 3670 W ActivityManager: Scheduling restart of crashed service com.NoCompany.BalloonBeachRun/org.chromium.content.app.SandboxedProcessService0 in 1000ms
05-01 21:59:20.358 2591 3567 I ActivityManager: Process com.NoCompany.BalloonBeachRun (pid 30169) has died: fore TOP
05-01 21:59:20.359 2591 3567 W ActivityManager: Force removing ActivityRecord{83cbcfb u0 com.NoCompany.BalloonBeachRun/com.unity3d.player.UnityPlayerActivity t20745}: app died, no saved state
05-01 21:59:20.386 2591 2664 W ActivityManager: setHasOverlayUi called on unknown pid: 30169
My ads code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.Advertisements;
using UnityEngine.UI;
public class App_Initialize : MonoBehaviour
{
public GameObject inMenuUI;
public GameObject inGameUI;
public GameObject gameOverUI;
public GameObject player;
public GameObject adButton;
public GameObject restartButton;
private bool hasGameStarted = false;
private bool hasSeenRewardedAd = false;
#if UNITY_IOS
public const string gameID = â3064768â;
#elif UNITY_ANDROID
public const string gameID = â3064760â;
#elif UNITY_EDITOR
public const string gameID = â1111111â;
#endif
public string bannerPlacement = âbannerâ;
public bool testMode = false;
public bool show = false;
void Awake()
{
Shader.SetGlobalFloat(â_Curvatureâ, 2.0f);
Shader.SetGlobalFloat(â_Trimmingâ, 0.1f);
Application.targetFrameRate = 60;
}
// Start is called before the first frame update
void Start()
{
// show = false;
// Debug.Log("Unity Ads test mode enabled: " + Advertisement.testMode);
Advertisement.Initialize(gameID);
Debug.Log("Unity Ads initialized: " + Advertisement.isInitialized);
Debug.Log("Unity Ads is supported: " + Advertisement.isSupported);
Debug.Log("Unity Ads is showing: " + Advertisement.isShowing);
StartCoroutine(ShowBannerWhenReady());
player.GetComponent().constraints = RigidbodyConstraints.FreezePosition;
inMenuUI.gameObject.SetActive(true);
inGameUI.gameObject.SetActive(false);
gameOverUI.gameObject.SetActive(false);
}
public void PlayButton ()
{
if(hasGameStarted == true)
{
StartCoroutine(StartGame(1.0f));
}
else
{
StartCoroutine(StartGame(0.0f));
}
}
public void PauseGame ()
{
player.GetComponent().constraints = RigidbodyConstraints.FreezePosition;
hasGameStarted = true;
inMenuUI.gameObject.SetActive(true);
inGameUI.gameObject.SetActive(false);
gameOverUI.gameObject.SetActive(false);
}
public void GameOver ()
{
player.GetComponent().constraints = RigidbodyConstraints.FreezePosition;
hasGameStarted = true;
inMenuUI.gameObject.SetActive(false);
inGameUI.gameObject.SetActive(false);
gameOverUI.gameObject.SetActive(true);
if(hasSeenRewardedAd == true)
{
adButton.GetComponent().color = new Color(1, 1, 1, 0.5f);
adButton.GetComponent().enabled = false;
adButton.GetComponent().enabled = false;
restartButton.GetComponent().enabled = true;
}
}
public void RestartGame ()
{
Debug.Log(ârestartâ);
SceneManager.LoadScene(0);
}
public void ShowAd ()
{
// hasSeenRewardedAd = true;
if(show == false)
{
StartCoroutine(StartGame(1.5f));
StartCoroutine(ShowBannerWhenReady());
}
show = true;
Debug.Log("Unity Ads is showing: " + Advertisement.isShowing);
// if (Advertisement.IsReady(âbannerâ))
// {
// var options = new ShowOptions { resultCallback = HandleShowResult };
// Advertisement.Show(âbannerâ, options);
// }
Debug.Log("Unity Ads is showing: " + Advertisement.isShowing);
}
private void HandleShowResult(ShowResult result)
{
switch (result)
{
case ShowResult.Finished:
Debug.Log(âThe ad was successfully shown.â);
hasSeenRewardedAd = true;
StartCoroutine(StartGame(1.5f));
break;
case ShowResult.Skipped:
Debug.Log(âThe ad was skipped before reaching the end.â);
break;
case ShowResult.Failed:
Debug.LogError(âThe ad failed to be shown.â);
break;
}
}
// void Start()
//{
//}
IEnumerator ShowBannerWhenReady()
{
while (!Advertisement.IsReady(âbannerâ))
{
yield return new WaitForSeconds(0.5f);
}
Advertisement.Banner.Show(bannerPlacement);
// yield return new WaitForSeconds(3.5f);
// Advertisement.Banner.Hide();
}
IEnumerator StartGame(float waitTime)
{
inMenuUI.gameObject.SetActive(false);
inGameUI.gameObject.SetActive(true);
gameOverUI.gameObject.SetActive(false);
yield return new WaitForSeconds(waitTime);
player.GetComponent().constraints = RigidbodyConstraints.None;
player.GetComponent().constraints = RigidbodyConstraints.FreezePositionY;
}
}
4494973â414499âApp_Initialize.cs (5.04 KB)