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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

[CLOSED] Unity Services - Ads - Not loading on button click?

Discussion in 'Editor & General Support' started by Trickzbunny, Nov 3, 2016.

  1. Trickzbunny

    Trickzbunny

    Joined:
    Jun 26, 2015
    Posts:
    64
    [CLOSED]

    Issue:
    Think when I updated (downloaded new version of unity, it changed from Android to PC Standalone.. Well that was way too easy.. sometimes the easiest stuff gets overseen

    Hey there!

    I'm having some trouble with Unity Ads.
    After it not working out although I thought it should, I looked around and found a video, I have 1:1 the same line of Code as there and shown in the Unity Ads section, I dont see an issue but something is not working out..

    There are no errors when I play the scene, HOWEVER, if I try and make a build i get an error:
    "The name "Advertisement" does not exist in the current context" (11, 25)

    Here is an overview of my script, Ads settings and the button. What could be causing this?

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.Advertisements;
    4.  
    5. public class ShowAds : MonoBehaviour
    6. {
    7.     public void ShowAd()
    8.     {
    9.             Advertisement.Show();
    10.     }
    11. }
    12.  

    WatchAdsNotWorking.PNG AdsNotWorking2.PNG
     
    Last edited: Nov 14, 2016
  2. Trickzbunny

    Trickzbunny

    Joined:
    Jun 26, 2015
    Posts:
    64
  3. Trickzbunny

    Trickzbunny

    Joined:
    Jun 26, 2015
    Posts:
    64
    bump Please help :(
     
  4. kunalxigxag

    kunalxigxag

    Joined:
    Aug 7, 2014
    Posts:
    9
    Hi

    You need to initialize ads using code below with your game Id in Start() or Awake() or OnEnable() whichever you are using.

    Advertisement.Initialize("your_gameId");

    Then you can add the code below in your button method.

    if(Advertisement.IsReady("your_non_rewarded_zoneId"))
    {
    Advertisement.Show("your_non_rewarded_zoneId");
    }

    Best,
    Kunal
     
    Trickzbunny likes this.
  5. Trickzbunny

    Trickzbunny

    Joined:
    Jun 26, 2015
    Posts:
    64
    Hey Kunal,
    Thanks for the Reply and getting me a step closer
    Some small issues though, I set up my button and for some reason both ShowAd() and Random() are not showing me the Debug.Log which is confusing me a bit. Same as the Ad is still not showing up.

    and to the non_rewarded_zone_ID I added the "Placement ID" of what ad to play, I tried both video and rewardedVideo and both didnt work :/

    I've watched this video;

    and followed the steps and cant even get the simple version working at 5:25


    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.Advertisements;
    4.  
    5. public class ShowAds : MonoBehaviour
    6. {
    7.     void Start()
    8.     {
    9.         Advertisement.Initialize("my 7 digit Number is here");
    10.     }
    11.     public void ShowAd()
    12.     {
    13.         if (Advertisement.IsReady("video"))  // use video or rewardedVideo
    14.         {
    15.             Advertisement.Show ("video");    // use video or rewardedVideo
    16.             Debug.Log ("Add is shown.");        //Not showing in console
    17.         }
    18.     }
    19.     public void Random()
    20.     {
    21.         Debug.Log ("Random click working.");        //Not showing in console
    22.     }
    23. }
    24.  
    Added a Picture of the Button Settings, added sound to be sure the button works. The Random() is just a Debug.Log that isnt working and the ShowAd() also still isnt working


    I have Ads on, for both IOS and Android and Test mode aswell, I am only initializing the Android 7 digit number atm, is that fine?

    TheButton.PNG
     
    Last edited: Nov 11, 2016
  6. Trickzbunny

    Trickzbunny

    Joined:
    Jun 26, 2015
    Posts:
    64
  7. Trickzbunny

    Trickzbunny

    Joined:
    Jun 26, 2015
    Posts:
    64
  8. Trickzbunny

    Trickzbunny

    Joined:
    Jun 26, 2015
    Posts:
    64
  9. kunalxigxag

    kunalxigxag

    Joined:
    Aug 7, 2014
    Posts:
    9
    Have you tried just adding a single method to call in OnClick? Just the ShowAds.showAd one.
     
    Trickzbunny likes this.
  10. Trickzbunny

    Trickzbunny

    Joined:
    Jun 26, 2015
    Posts:
    64
    yes, followed the video to 5min where he does the simple 1 line script, even made a new project for it to test it out and that still didnt work :/
     
  11. Trickzbunny

    Trickzbunny

    Joined:
    Jun 26, 2015
    Posts:
    64
    Thanks a lot Kunalxigxag for checking out everything and helping me through it, really appreciate it!
    Keep up the good work :)