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

In editor appear an image when I call UnityAds, but on android device..nothing happens :((

Discussion in 'Unity Ads & User Acquisition' started by Victor-M, Jul 8, 2015.

  1. Victor-M

    Victor-M

    Joined:
    Jul 4, 2015
    Posts:
    5
    Hi,

    I recently publish a beta version of my game to test google services and ads before to publish my final app. It's my first game.

    The google services it's ok. *-*
    But I have some problems with Unity Ads. ://

    On Editor:
    Appear an image with one message. (Here would be your ad Unit (things seems to be working!))
    "Yaha! It's working" I thought.
    On Android device:
    ...nothing...
    "No..No no..nOOOOu" I thought crying kkkk

    My code:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.Advertisements;
    4.  
    5. public class <AdScript> : MonoBehaviour {
    6.  
    7.     [SerializeField] string gameID = "GameID";
    8.  
    9.     void Awake () {
    10.         Advertisement.Initialize (gameID, true);
    11.     }
    12.  
    13.     public void ShowAd(string zone = ""){
    14.         #if UNITY_EDITOR
    15.             StartCoroutine (WaitForAd ());
    16.         #endif
    17.  
    18.         if(string.Equals (zone, ""))
    19.             zone = null;
    20.  
    21.         ShowOptions options = new ShowOptions ();
    22.         options.resultCallback = AdCallbackhandler;
    23.  
    24.         if (Advertisement.IsReady(zone))
    25.             Advertisement.Show (zone, options);
    26.     }
    27.  
    28.     void AdCallbackhandler(ShowResult showResult){
    29.         switch (showResult) {
    30.             case ShowResult.Finished:
    31.             Debug.Log ("Ad finished...Take your reward!");
    32.             break;
    33.             case ShowResult.Skipped:
    34.             Debug.Log ("Oh no...:/");
    35.             break;
    36.             case ShowResult.Failed:
    37.             Debug.Log ("Sorry. Don't happen again.");
    38.             break;
    39.         }
    40.     }
    41.  
    42.     IEnumerator WaitForAd(){
    43.         float currentTimeScale = Time.timeScale;
    44.         Time.timeScale = 0f;
    45.         yield return null;
    46.  
    47.         while(Advertisement.isShowing)
    48.             yield return null;
    49.  
    50.         Time.timeScale = currentTimeScale;
    51.     }
    52. }
    Help me?
     
  2. Rasmus Selsmark

    Rasmus Selsmark

    Joined:
    Mar 13, 2013
    Posts:
    120
    Hi, sorry for late reply.

    You shouldn't have to set Time.timeScale = 0, as game is automatically paused by Unity Ads when showing video ad. Please see https://unityads.unity3d.com/help/D...shers/Integration-Guide-for-Unity-Asset-Store for instruction on how to integrate Ads into your Unity game. Generally I think you should remove the coroutine call, as Unity Ads will pause the game itself.

    Hope this helps.

    /Rasmus