G
G
graf452312019-01-09 21:45:50
Unity
graf45231, 2019-01-09 21:45:50

I can't figure out Unity Monetization 3.0, how to run ads on my smartphone?

Made a test project to learn how to monetize in Unity. Everything is fine in the editor, a test picture is shown and bonuses are accrued, but ads do not start on the phone, and in the emulator it crashes when you click on the ad button. When the button is pressed, the ShowAd () method is called and inside there is already a check whether the ad is ready, as far as I know in test mode it is always ready and therefore I don’t understand what the problem is. Ignore the changes in the text in the field, just trying to debug the code, I would be grateful if you could tell me how to debug the code on android.

using UnityEngine;
using UnityEngine.Monetization;
using UnityEngine.UI;

public class UnityAdsScript : MonoBehaviour
{
    public Player player;
    public string placementId = "rewardedVideo";
    public Text androidConsole;

#if UNITY_IOS
   private string gameId = "2997382";
#elif UNITY_ANDROID
    private string gameId = "2997383";
#endif

    void Start()
    {
        if (Monetization.isSupported)
        {
            Monetization.Initialize(gameId, true);
        }
    }

    void Update()
    {

    }

    public void ShowAd()
    {
        if (Monetization.IsReady(placementId)) {
            androidConsole.text = "Start1";
            ShowAdCallbacks options = new ShowAdCallbacks();
            androidConsole.text = "Start2";
            options.finishCallback = HandleShowResult;
            androidConsole.text = "Start3";
            ShowAdPlacementContent ad = Monetization.GetPlacementContent(placementId) as ShowAdPlacementContent;
            androidConsole.text = "Start4";
            ad.Show(options);
            androidConsole.text = "Start5";
        }
    }

    void HandleShowResult(ShowResult result)
    {
        if (result == ShowResult.Finished)
        {
            player.Reward();
            androidConsole.text = "Finish";
        }
        else if (result == ShowResult.Skipped)
        {
            androidConsole.text = "The player skipped the video - DO NOT REWARD!";
        }
        else if (result == ShowResult.Failed)
        {
            androidConsole.text = "Video failed to show";
        }
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MishkaVNorky, 2019-01-11
@MishkaVNorky

1. there is a stub on the computer, the library does not work like on the device
2. did you add "rewardedVideo" through the control panel? https://unityads.unity3d.com/help/monetization/pla...
everything looks correct in the code, you also need to take into account that the phone must have Internet access and advertising (for example, a video reward) is not shown immediately, but will first load and only later (including even if it is a test one)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question