Search Unity

Updated to Unity Monetization - now can't get it working

Discussion in 'Unity Ads & User Acquisition' started by NavpointSoftware, Mar 22, 2020.

  1. NavpointSoftware

    NavpointSoftware

    Joined:
    Apr 30, 2011
    Posts:
    102
    Hi All.

    Annoyingly I had to put a project on hold around November and have just gone back to it. I had the older versions of UnityAds working fine then but found Unity had updated to the new Unity monetization System recently.

    Im struggling to get the new system working properly and was wondering if someone can cast their eye over as to where im going wrong.

    The problem is the Reward Ad will not 'Finish'...it displays everything is fine in the game (test)...I click 'close' in the test window and nothing happens, no Time Added (which is the reward). Same thing happens on Mobile bur the 'Unity ads Video' plays. Where am I going wrong please?

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Advertisements;
    5.  
    6. public class UnityAdsStandard : MonoBehaviour, IUnityAdsListener
    7. {
    8.     Timer timer;
    9.     public GameObject panelRewardsAds;
    10.  
    11.     public bool userQuitIngame = false;
    12.  
    13.     public int minRoundsAds = 2;
    14.     public int maxRoundsAds = 5;
    15.     public int curRoundAds = 0;
    16.     public int requiredRoundsForAds = 0;
    17.     private GameObject PanelMask;
    18.  
    19.     string gameId = "3508323";
    20.     bool testMode = true;
    21.     string myBasicAd = "BasicAd";
    22.     string myRewardAd = "rewardedVideo";
    23.  
    24.  
    25.     void Awake()
    26.     {
    27.         timer = GetComponent<Timer>();
    28.         panelRewardsAds = GameObject.Find("Panel_Reward_Ad");
    29.  
    30.     }
    31.  
    32.  
    33.     // Start is called before the first frame update
    34.     void Start()
    35.     {
    36.        // Advertisement.AddListener(this);
    37.         Advertisement.Initialize(gameId, testMode);
    38.         SelectAdRound();
    39.     }
    40.  
    41.     // Update is called once per frame
    42.     void Update()
    43.     {
    44.    
    45.  
    46.         if (Advertisement.isShowing == true)
    47.         {
    48.  
    49.             Time.timeScale = 0;
    50.         }
    51.         else
    52.         {
    53.             Time.timeScale = 1;
    54.         }
    55.  
    56.  
    57.     }
    58.  
    59.  
    60.     //Selects Random Number to show round
    61.     public void SelectAdRound()
    62.     {
    63.         requiredRoundsForAds = Random.Range(minRoundsAds, maxRoundsAds);
    64.  
    65.     }
    66.  
    67.     //Checks at the start of each new round if a Standard Ad Should be played.
    68.     public void ChkCurrentRound()
    69.     {
    70.         curRoundAds++;
    71.  
    72.         if(curRoundAds == requiredRoundsForAds)
    73.         {
    74.             Debug.Log("Standard Ad");
    75.             Advertisement.Show(myBasicAd);
    76.             curRoundAds = 0;
    77.             SelectAdRound();
    78.  
    79.         }
    80.     }
    81.  
    82.     //Resets the Current Round Cycle.
    83.     public void ResetCurRounds()
    84.     {
    85.         curRoundAds = 0;
    86.     }
    87.  
    88.     /*REWARD AD */
    89.  
    90.     public void DisplayRewardAd()
    91.     {
    92.  
    93.         Advertisement.Show(myRewardAd);
    94.         Debug.Log("Reward Ad");
    95.     }
    96.  
    97.  
    98.     // Implement IUnityAdsListener interface methods:
    99.     public void OnUnityAdsDidFinish(string myRewardAd, ShowResult showResult)
    100.     {
    101.         // Define conditional logic for each ad completion status:
    102.         if (showResult == ShowResult.Finished)
    103.         {
    104.            
    105.                 timer.AddTime();
    106.                 panelRewardsAds.SetActive(false);
    107.                 GetComponent<UnityAdsStandard>().ResetCurRounds();
    108.          
    109.         }
    110.         else if (showResult == ShowResult.Skipped)
    111.         {
    112.             // Do not reward the user for skipping the ad.
    113.         }
    114.         else if (showResult == ShowResult.Failed)
    115.         {
    116.             Debug.LogWarning("The ad did not finish due to an error.");
    117.         }
    118.     }
    119.  
    120.     public void OnUnityAdsReady(string placementId)
    121.     {
    122.         // If the ready Placement is rewarded, show the ad:
    123.         if (placementId == myRewardAd)
    124.         {
    125.             //Advertisement.Show(myRewardAd);
    126.         }
    127.     }
    128.  
    129.     public void OnUnityAdsDidError(string message)
    130.     {
    131.         // Log the error.
    132.     }
    133.  
    134.     public void OnUnityAdsDidStart(string placementId)
    135.     {
    136.         // Optional actions to take when the end-users triggers an ad.
    137.     }
    138.  
    139. }
    140.  
    Just to be clear the Standard ads are played when a particular round number is hit. The reward ads are played when the user presses a button at a particular time.

    Any help with this much appreciated as im tearing my hair out.

    Kind Regards,
    John
     
  2. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    @NavpointSoftware

    On line 36 of your script, you have AddListener commented out. This will prevent your callbacks from getting triggered.