Kulwinder Singh Rahal
Kulwinder Singh Rahal

Reputation: 519

Unity ads not initilizing automatically?

I am using unity reward based Ads in my android/iOS game. but when I check it Advertisement.IsReady (rewardVideoID);

always return false.

Also if check in Awake unity ads initialization is false

void Awake ()
{
    Debug.Log ("Unity ads ini state : " + Advertisement.isInitialized); //it is false everytime
} 

But I have enabled ads in Unity Editor so here I want to know why unity ads are not auto initializing. I used unity ads in my previous project it is initializing automatically.

Upvotes: 2

Views: 8789

Answers (2)

murgupluoglu
murgupluoglu

Reputation: 7205

Select either Android or iOS as active build target. Unity Ads doesn't support standalone. Its in File -> Build Settings -> Platform

Upvotes: 0

Programmer
Programmer

Reputation: 125445

You must call Advertisement.Initialize before checking Advertisement.isInitialized or Advertisement.IsReady.

Not just that. When you call Advertisement.Initialize, there is no guarantee that it will initialize immediately. This is why you must perform this check in a coroutine function so that you can continuously check it until it has initialized.

An example from Unity's Ads Doc:

IEnumerator Start()
{
!UNITY_ADS // If the Ads service is not enabled...
    if (Advertisement.isSupported)
    { // If runtime platform is supported...
        Advertisement.Initialize(gameId, enableTestMode); // ...initialize.
    }
if

    // Wait until Unity Ads is initialized,
    //  and the default ad placement is ready.
    while (!Advertisement.isInitialized || !Advertisement.IsReady())
    {
        yield return new WaitForSeconds(0.5f);
    }

    // Show the default ad placement.
    Advertisement.Show();
}

Upvotes: 0

Related Questions