Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Unity Ads don't work once the game is exported.

Discussion in 'Scripting' started by cheapcpps, Jun 28, 2021.

  1. cheapcpps

    cheapcpps

    Joined:
    Jul 15, 2020
    Posts:
    53
    Hi! I have a game called windows clicker and one of the main mechanics of the game is you can get a small boost or cosmetic item with rewarded ads. I also made it so every 5 minutes an interstitial ad shows up. Everything works just fine in the editor, however once the game is exported or on the play store. Ads don't show up. Here's some info you may need to help me. Game link
    Code:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Advertisements;
    5.  
    6. public class AdManager : MonoBehaviour, IUnityAdsListener
    7. {
    8.     public EconomyManager eco;
    9.     public string lastType;
    10.     public float elapsed  = 0f;
    11.     /* game id was replaced*/private string store_id = "GameID";
    12.     void Start()
    13.     {
    14.         Advertisement.AddListener(this);
    15.         Advertisement.Initialize(store_id);
    16.     }
    17.     void Update()
    18.     {
    19.         elapsed += Time.deltaTime;
    20.         if (elapsed >= 300f)
    21.         {
    22.             elapsed = elapsed % 1f;
    23.             Debug.Log("clock restarting");
    24.             if (Advertisement.IsReady("video"))
    25.             {
    26.                 Advertisement.Show("video");
    27.             }
    28.         }
    29.     }
    30.     public void startRewardedAd(string type)
    31.     {
    32.         lastType = type;
    33.         if (Advertisement.IsReady("rewardedVideo"))
    34.         {
    35.             Advertisement.Show("rewardedVideo");
    36.         }
    37.     }
    38.     public void OnUnityAdsDidFinish(string surfacingId, ShowResult showResult) {
    39.         if (showResult == ShowResult.Finished)
    40.         {
    41.             if (surfacingId.Equals("rewardedVideo")) {
    42.                 if (lastType.Equals("gems")) {
    43.                     eco.Gems += 10;
    44.                 }
    45.                 if (lastType.Equals("cash")) {
    46.                     eco.addMoney(eco.Money / 4);
    47.                 }
    48.             }
    49.         }
    50.     }
    51.     public void OnUnityAdsReady(string surfacingId)
    52.     {
    53.  
    54.     }
    55.  
    56.     public void OnUnityAdsDidError(string message)
    57.     {
    58.  
    59.     }
    60.  
    61.     public void OnUnityAdsDidStart(string surfacingId)
    62.     {
    63.  
    64.     }
    65.  
    66.     public void OnDestroy()
    67.     {
    68.         Advertisement.RemoveListener(this);
    69.     }
    70. }
    71.  
     
  2. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,731
  3. cheapcpps

    cheapcpps

    Joined:
    Jul 15, 2020
    Posts:
    53
    I'm looking at logcat, it appears you need to plugin your phone to your pc to use it? Is that correct. My android device is buggy with my game so I just use bluestacks for convenience if there's anyway to view logs that way.
     
  4. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,731
    I always use an actual device plugged into my PC and not an emulator so I can't answer that, sorry. Maybe someone else that debugs builds with emulator software can provide the answer.