Search code examples
c#unity-game-engineadsunityads

UNITY3D - Cannot perform action after watching ad?


The following script is supposed to reward the player when the ad has been watched:

public void ShowAd()
{
    if (Advertisement.IsReady())
    {
        var showOptions = new ShowOptions();
        showOptions.resultCallback += ResultCallback;
        Advertisement.Show();
    }
}

private void ResultCallback (ShowResult result) {
    if(result == ShowResult.Finished) {
        coins += 50;
    }
    else {
        Debug.Log ("No award given. Result was :: "+result);
    }
}

ShowAd() is called when a button is pressed.

The problem: I can't get the script to award the player.


Solution

  • Problem: Advertisement.Show() does not have a callback handler.

    You need to use the other overload Advertisement.Show(string zoneId, Advertisements.ShowOptions options)

    So you need to create a zone if you don't have one. Then replace your Show with

    Advertisement.Show(zoneId, showOptions);