Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The type 'Advertisement' exists in both 'UnityEngine.Advertisements.Editor'

I am building a game with ads in Unity 2019.2.21f1, using Unity Ads. I have the following short script for displaying ads:

using System.Collections;
using UnityEngine;
using UnityEngine.Advertisements;

public class AdBannerScriptUnity : MonoBehaviour
{
    public string gameId = "myGameId";
    public string placementId = "AdBanner";
    public bool testMode = true;

    void Start()
    {
        Advertisement.Initialize(gameId, testMode);
        StartCoroutine(ShowBannerWhenReady());
    }

    IEnumerator ShowBannerWhenReady()
    {
        while (!Advertisement.IsReady(placementId))
        {
            yield return new WaitForSeconds(0.5f);
        }
        Advertisement.Banner.SetPosition(BannerPosition.BOTTOM_CENTER);
        Advertisement.Banner.Show(placementId);
    }
}

I have Ads enabled in Unity Services (Cloud Icon button on top right of Unity Editor UI) and have imported the Unity Monetization Asset from the asset store.

When building this game, I get the following error:

Assets/Scripts/AdBannerScriptUnity.cs(13,9): error CS0433: The type 'Advertisement' exists in both 'UnityEngine.Advertisements.Editor, Version=3.4.2.0, Culture=neutral, PublicKeyToken=null' and 'UnityEngine.Advertisements, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'

I have read somewhere that since Unity 5.2, the Unity Monetization Asset is no longer necessary to display ads with Unity, so I tried removing it, but then I get

Assets/Scripts/AdBannerScriptUnity.cs(23,23): error CS0117: 'Advertisement' does not contain a definition for 'Banner'

So clearly, the Asset is necessary, but it seems I somehow, according to the first error posted above, have two versions installed? How do I make sure I only have one version installed?

like image 330
ChrisC Avatar asked Dec 23 '22 18:12

ChrisC


1 Answers

I'm using Unity 2019.3 6f1 and experincing the same problem. Somewhere I read that if you use Monetization asset from the store and enable Ads from Unity Services they create the issue. But I couldn't remove the asset. When I disable Ads from serviceses no more ads are displayed(quiet naturally :) ) So looking for updates on that post.

Edit: Mate, I have solved my problem finally. Indeed it is the Monetization asset from the asset store what is causing conflict. You should use Ads from the services tab and import Monetization asset from Package manager (not from asset store) and delete all contents of Monetization from asset store. I'm attaching the image of files you should delete from your project folders. Unity Monetization Asset Store Files

like image 94
Patroclos Avatar answered Dec 30 '22 12:12

Patroclos