Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Rewarded Ads stopped working

Discussion in 'Unity Ads & User Acquisition' started by Ofir125, Dec 3, 2022.

  1. Ofir125

    Ofir125

    Joined:
    Oct 1, 2021
    Posts:
    2
    I worked with rewarded ads before and everything worked then one day I open my Unity project and it stopped working, the ad works but the reward doesn't, I tried multiple methods and checked on the internet for answers but unfortunately nothing worked I will attach the code I would if you can take a look. It doesn't say that I have errors it just doesn't work.
    If anyone has the answer please let me know
     

    Attached Files:

  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,643
    Please use code-tags when posting code. Also, you should use the dedicated Ads forum.

    I'll move your post.
     
  3. Ofir125

    Ofir125

    Joined:
    Oct 1, 2021
    Posts:
    2
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Advertisements;
    3. using UnityEngine.SceneManagement;
    4.  
    5. public class AdsManager : MonoBehaviour
    6. {
    7.     public interface IUnityAdsListener { };
    8.  
    9.     public static int b;
    10.     public int a;
    11.     public int i;
    12.     public int earn;
    13.     public int once;
    14.  
    15.     // Start is called before the first frame update
    16.     void Start()
    17.     {
    18.         a = 0;
    19.         Advertisement.Initialize("ID");
    20.         Advertisement.AddListener((UnityEngine.Advertisements.IUnityAdsListener)this);
    21.     }
    22.     void Update()
    23.     {
    24.         a = 0;
    25.       i = PlayerPrefs.GetInt("ad");
    26.        if (i==4)
    27.         {
    28.             PlayAd();
    29.  
    30.             PlayerPrefs.SetInt("ad", 0);
    31.         }
    32.     }
    33.  
    34.     // Update is called once per frame
    35.     public void PlayAd()
    36.     {
    37.         if (Advertisement.IsReady("Interstitial_Android"))
    38.         {
    39.             Advertisement.Show();
    40.             Debug.Log("ad");
    41.         }
    42.  
    43.  
    44.  
    45.  
    46.  
    47. I attached the code.
    48.  
    49.     }
    50.     public void PlayRewardedAd()
    51.     {
    52.      
    53.         if (Advertisement.IsReady("Rewarded_Android"))
    54.         {
    55.             Advertisement.Show("Rewarded_Android");
    56.             Debug.Log("played");
    57.             once = 1;
    58.         }
    59.         else
    60.         {
    61.             Debug.Log("is not ready");
    62.         }
    63.      
    64.     }
    65.  
    66.     public void OnUnityAdsReady(string placementId)
    67.     {
    68.         Debug.Log("ready");
    69.     }
    70.  
    71.     public void OnUnityAdsDidError(string message)
    72.     {
    73.         Debug.Log("error");
    74.         Advertisement.RemoveListener((UnityEngine.Advertisements.IUnityAdsListener)this);
    75.     }
    76.  
    77.     public void OnUnityAdsDidStart(string placementId)
    78.     {
    79.      
    80.         Debug.Log("started");
    81.     }
    82.  
    83.  
    84.     void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
    85.     {
    86.      
    87.             if (showResult == ShowResult.Finished)
    88.             {
    89.  
    90.                 Debug.LogWarning("works");
    91.                 SceneManager.LoadScene("Main");
    92.             }
    93.             else if (showResult == ShowResult.Skipped)
    94.             {
    95.                 Debug.LogWarning("The ad did not finish due to an error.");
    96.  
    97.             }
    98.             else if (showResult == ShowResult.Failed)
    99.             {
    100.                 Debug.LogWarning("The ad did not finish due to an error.");
    101.             }
    102.             else
    103.             {
    104.                 Debug.LogError("Error");
    105.             }
    106.     }
    107. }
    108.