Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Advertisement is Error

Discussion in '5.5 Beta' started by oba_shunsuke, Sep 7, 2016.

  1. oba_shunsuke

    oba_shunsuke

    Joined:
    Aug 3, 2015
    Posts:
    3
    Hello.

    Do you Advertisement functions ?

    ```
    UnityEngine.Advertisements.Advertisement.Initialize(GAME_ID, true);
    ```

    ```
    NullReferenceException: Object reference not set to an instance of an object
    UnityEngine.Advertisements.Advertisement.Initialize (System.String gameId, Boolean testMode) (at /Users/builduser/buildslave/unity/build/Extensions/UnityAds/UnityAds/Advertisement.cs:211)
    ```
    NullReferenceException...

    No AssetStore. Builtin Advertisement.

    ----
    Unity5.5.0b1, b2
     
  2. rasmus-unity

    rasmus-unity

    Moderator

    Joined:
    Aug 15, 2014
    Posts:
    1,312
  3. oba_shunsuke

    oba_shunsuke

    Joined:
    Aug 3, 2015
    Posts:
    3
    Thank you!!

    There is no Error in Sample!
    but no function...

    Two Question.

    Q1. I build for ios platform under source included. Advertisement.IsReady () don't become Ready Status.

    ```
    using UnityEngine;
    using System.Collections;

    #if UNITY_ADS
    using UnityEngine.Advertisements; //onlycompileAdscodeonsupported platforms
    #endif

    public class UnityAd : MonoBehaviour
    {
    public event System.Action onCompleteReward;

    [SerializeField]
    private bool _isReady;

    public static readonly bool IS_TEST_MODE = true;

    private IEnumerator Start ()
    {
    #if UNITY_ADS
    yield return new WaitUntil (() => Advertisement.IsReady ());
    _isReady = true;
    #endif
    yield return null;
    }

    public void ShowDefaultAd ()
    {
    if (_isReady == false)
    {
    Debug.Log ("NoReady.");
    return;
    }
    #if UNITY_ADS
    if (Advertisement.IsReady() == false)
    {
    Debug.Log("Adsnotreadyfordefaultzone");
    return;
    }

    Advertisement.Show();
    #endif
    }

    public void ShowRewardedAd ()
    {
    if (_isReady == false)
    {
    Debug.Log ("NoReady.");
    return;
    }
    const string RewardedZoneId = "rewardedVideo";

    #if UNITY_ADS
    if (Advertisement.IsReady(RewardedZoneId) == false)
    {
    Debug.Log(string.Format("Adsnotreadyforzone'{0}'", RewardedZoneId));
    return;
    }

    var options = new ShowOptions { resultCallback = HandleShowResult };
    Advertisement.Show(RewardedZoneId, options);
    #endif
    }

    #if UNITY_ADS
    private void HandleShowResult(ShowResult result)
    {
    switch (result)
    {
    case ShowResult.Finished:
    Debug.Log("Theadwassuccessfullyshown.");
    //
    //YOURCODETOREWARDTHE GAMER
    //Givecoinsetc.
    if (onCompleteReward != null)
    {
    onCompleteReward();
    }
    break;

    case ShowResult.Skipped:
    Debug.Log("Theadwasskippedbeforereachingtheend.");
    break;

    case ShowResult.Failed:
    Debug.LogError("Theadfailedtobeshown.");
    break;
    }
    }
    #endif
    }
    ```

    Q2. UnityAd did not check operation in UnityEditor?
    Unity5.3.6 can confirm UnityAd operation check...
     
  4. rasmus-unity

    rasmus-unity

    Moderator

    Joined:
    Aug 15, 2014
    Posts:
    1,312
    Hi @oba_shunsuke,

    Can you please use the Insert... -> Code feature of forum to format your post, so the code becomes easier to read. I can take a look then. Right now e.g. some spaces seems to have been removed.

    Thanks,
    Rasmus
     
  5. oba_shunsuke

    oba_shunsuke

    Joined:
    Aug 3, 2015
    Posts:
    3
    @rasmus-unity
    Sorry I will be careful from next time when source code insert.

    thanks