Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to ad picture ads??

Discussion in 'Unity Ads & User Acquisition' started by MrGky93, Dec 30, 2014.

  1. MrGky93

    MrGky93

    Joined:
    Feb 27, 2014
    Posts:
    281
    hi
    I use some codes like this

    if(Advertisement.isReady()){ Advertisement.Show(); }


    or this one


    using System; using UnityEngine; using UnityEngine.Advertisements; public class AdvertisementTest : MonoBehaviour { void Awake() { if (Advertisement.isSupported) { Advertisement.allowPrecache = true; Advertisement.Initialize (<YOUR GAME ID HERE>); } else { Debug.Log("Platform not supported"); } } void OnGUI() { if(GUI.Button(new Rect(10, 10, 150, 50), Advertisement.isReady() ? "Show Ad" : "Waiting...")) { // Show with default zone, pause engine and print result to debug log Advertisement.Show(null, new ShowOptions { pause = true, resultCallback = result => { Debug.Log(result.ToString()); } }); } } }





    but nothing will make picture ads ???!!
     
  2. unity-nikkolai

    unity-nikkolai

    Joined:
    Sep 18, 2014
    Posts:
    540
    Keep in mind, picture ads are still in beta. Which means there is limited fill for English speaking countries, and in most cases no fill for non-English speaking countries.

    You can still test picture ad functionality regardless of fill by enabling test mode:
    Code (CSharp):
    1. public string gameID;
    2. public bool disableTestMode;
    3.  
    4. void Awake ()
    5. {
    6.     bool enableTestMode = Debug.isDebugBuild && !disableTestMode;
    7.     Debug.Log(string.Format("Initializing Unity Ads for game ID {0} with test mode {1}...",
    8.                             gameID, enableTestMode ? "enabled" : "disabled"));
    9.     Advertisement.Initialize(gameID,enableTestMode);
    10. }
    Having gameID and disableTestMode as public variables makes it easy to set them from the inspector. During development, you always want to be initializing Unity Ads with test mode enabled. With the above code, test mode will be enabled if Development Build is enabled in Build Settings. However, you can force production ads to be shown instead of test ads by checking disableTestMode.

    When you're ready to publish your game, simply disable Development Build and test mode will be disabled. This way you don't accidentally ship your game with test mode enabled, which would only show test ads and not generate any revenue.

    To show picture ads, Unity Ads needs to be both initialized and ready to show ads:
    Code (CSharp):
    1. if (Advertisement.isInitialized &&
    2.     Advertisement.isReady("pictureZone"))
    3. {
    4.     Advertisement.Show("pictureZone");
    5. }
    Something like this will allow you to show an ad shortly after the scene loads:
    Code (CSharp):
    1. public string zoneID = "pictureZone";
    2. public float timeout = 15f;
    3.  
    4. private float _startTime = 0f;
    5. private float _yieldTime = 1f;
    6.  
    7. // A return type of IEnumerator allows for the use of yield statements.
    8. //  For more info, see: http://docs.unity3d.com/ScriptReference/YieldInstruction.html
    9. IEnumerator Start ()
    10. {
    11.     // Set zoneID to null if string is empty.
    12.     //  When zoneID value is null, the default zone is used.
    13.     if (string.IsNullOrEmpty(zoneID)) zoneID = null;
    14.  
    15.     // Check to see if Unity Ads is initialized.
    16.     //  If not, wait a second before trying again.
    17.     do yield return new WaitForSeconds(_yieldTime);
    18.     while (!Advertisement.isInitialized);
    19.  
    20.     Debug.Log("Unity Ads has finished initializing. Waiting for ads to be ready...");
    21.  
    22.     // Set a start time for the timeout.
    23.     _startTime = Time.timeSinceLevelLoad;
    24.  
    25.     // Check to see if Unity Ads are available and ready to be shown.
    26.     //  If not, wait a second before trying again.
    27.     while (!Advertisement.isReady(zoneID))
    28.     {
    29.         if (Time.timeSinceLevelLoad - _startTime > timeout)
    30.         {
    31.             Debug.LogWarning("The process for showing ads on load has timed out. " +
    32.                              "Ad not shown.");
    33.  
    34.             // Break out of both this loop and the Start method; Unity Ads will not
    35.             //  be shown on load since the wait time exceeded the time limit.
    36.             yield break;
    37.         }
    38.  
    39.         yield return new WaitForSeconds(_yieldTime);
    40.     }
    41.  
    42.     Debug.Log("Ads are available and ready. Showing ad now...");
    43.  
    44.     // Show ad after Unity Ads finishes initializing and ads are ready to show.
    45.     Advertisement.Show(zoneID);
    46. }
    Additional code examples and demo scene are available here.
     
    Last edited: Dec 30, 2014
    MrGky93 likes this.
  3. MrGky93

    MrGky93

    Joined:
    Feb 27, 2014
    Posts:
    281
    thx you :)
     
  4. MrGky93

    MrGky93

    Joined:
    Feb 27, 2014
    Posts:
    281
    hmm funny i use this one

    1. if (Advertisement.isInitialized &&
    2. Advertisement.isReady("pictureZone"))
    3. {
    4. Advertisement.Show("pictureZone");
    5. }


    And in unity3d this works good.
    But when i used it on my android phone this dont want to show me a picture ad why????

    And how to go out of the test mode??
    and i think the picture ad is by me buggy ??!!
     
    Last edited: Jan 1, 2015
  5. unity-nikkolai

    unity-nikkolai

    Joined:
    Sep 18, 2014
    Posts:
    540
    Keep in mind, picture ads are still in beta. Which means there is limited fill for English speaking countries, and in most cases no fill for non-English speaking countries.

    The example I provided earlier in this thread allows you to have test mode enabled while Development Build is enabled in Unity's Build Settings. You can override this behavior by selecting disableTestMode in the inspector for the script.

    To enable and disable test mode for Unity Ads, pass a boolean value when calling Initialize():
     
  6. subash95

    subash95

    Joined:
    Mar 10, 2015
    Posts:
    4
    ads show during 1st run but not after that why? and again run after clearing app cache.
     
  7. Harton

    Harton

    Joined:
    Dec 5, 2012
    Posts:
    20
    Same happens to me after the 1.2.1 update.
     
  8. bob777

    bob777

    Joined:
    Mar 4, 2015
    Posts:
    2
    How can I create Picture-ad placement in UnityAds Admin ?
    I have only the "Video" and "Rewarded video" types...

    Thank's
     
  9. Pix10

    Pix10

    Joined:
    Jul 21, 2012
    Posts:
    850
    unity-nikkolai likes this.