Skip to content

Advertising

VirtueSky edited this page Sep 4, 2024 · 13 revisions

Advertising for unity

(Tested with applovin > v5.11.3 and google admob > v8.5.2)

Use

Setting

Open tab Advertising in Magic Panel

Unity_r1v2Ygg9sY

  • Create AdClient and AdVariable
  • Choose AdNetwork Max or Admob
  • You can click install sdk if your project doesn't have it yet.
  • Add Scripting Define Symbols to use

Set id for AdUnitVariable

AdVariable

(For Admob, you can get the test Id by going to Context Menu and selecting Get Id Test)

idtest

Attach Advertising to the object in the scene to load the ads

Adsvertising

Script show ads (demo)

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using VirtueSky.Ads;

public class AdsManager : MonoBehaviour
{
    public TextMeshProUGUI textNoti;
    public AdUnitVariable banner;
    public AdUnitVariable inter;
    public AdUnitVariable reward;

    public void ShowBanner()
    {
        Debug.Log(banner.IsReady());
        banner.Show();
    }

    public void ShowInter()
    {
        if (inter.IsReady())
        {
            LogMessage("inter is ready");
            inter.Show().OnCompleted(() => { LogMessage("inter is completed"); });
        }
        else
        {
            LogMessage("Inter is not ready");
        }
    }

    public void ShowReward()
    {
        if (reward.IsReady())
        {
            LogMessage("reward is ready");
            reward.Show().OnCompleted(() => { LogMessage("Reward is completed"); }).OnSkipped(() => { LogMessage("reward is skipped"); });
        }
        else
        {
            LogMessage("reward is not ready");
        }
    }

    void LogMessage(string message)
    {
        textNoti.text = message;
        Debug.Log(message);
    }
}
Clone this wiki locally