0

I have recently implemented Unity Ads into my android game, but it does not appear to be working. I have code that checks if and ad is ready, and if it is, enables a button to show an ad. When i launch my game on my device, the button is never enabled. Here is my code:

 void Update () {
     if(!Advertisement.isInitialized && button == "Revive")
     {
         Advertisement.Initialize("MY_GAME_ID", true);
     }
     if(Advertisement.IsReady() && button == "Revive")
     {
         GetComponent<SpriteRenderer>().enabled = true;
         GetComponent<BoxCollider2D>().enabled = true;
     }
 }


 void OnMouseUp()
 {
        if(button == "Revive")
         {
             if(Advertisement.IsReady())
             {
                 Advertisement.Show(null, new ShowOptions {
                     resultCallback = result => {
                         Debug.Log(result.ToString());
                         player.GetComponent<PlayerMovement>().revive();
                         player.transform.position = insPlayer;
                         gameObject.SetActive(false);
                     }
                 });
             }
         }

 }

I tried the logcat but no errors occur. It works in the editor, but not on my device. Any ideas?

Any help is greatly appreciated, thanks.

Alex Boullé
  • 431
  • 5
  • 17
  • button is just a string i use to define what action to take on click @PawełMarecki – Alex Boullé Dec 23 '15 at 12:31
  • Ok. So, are you checkd if OnMouseUp working properly? Or if there is any log in console about ads? – Paweł Marecki Dec 23 '15 at 12:37
  • Yep, OnMouseUp definately works. It works in the editor and shows the placeholder for where the ad should be. No errors in the console or logcat. – Alex Boullé Dec 23 '15 at 12:39
  • Oh, I found something suspicous in the console. I says "gameId= 12345". I dont think the space should be there. In my script there isn't a space, but somehow there is on initialization. I typed my game id in manually and it now says "gameId=12345" without space. I will try building and see if it works now. – Alex Boullé Dec 23 '15 at 12:42

1 Answers1

0

Okay, it turns out there was a mysterious invisible space in my gameId that caused it not to initialize. It's working now.

Alex Boullé
  • 431
  • 5
  • 17