Unity Ads - Advertisement does not contain a definition for isSupported

So I have been working on implementing ads into my game, but when I imported the Unity Ads package and used the supplied sample code for a test, I get all kinds of Errors that are saying that the advertisement class does not contain definitions for… anything but I can actually look at the advertisement class and see the variables defined right there.

The script is exactly as provided by the UnityAds page.

using System;
using UnityEngine;
using UnityEngine.Advertisements;

public class Advertisement : MonoBehaviour {
	void Awake() {
		if (Advertisement.isSupported) {
			Advertisement.allowPrecache = true;
			Advertisement.Initialize (*censored*);
		} else {
			Debug.Log("Platform not supported");
		}
	}
	
	void OnGUI() {
		if(GUI.Button(new Rect(10, 10, 150, 50), Advertisement.isReady() ? "Show Ad" : "Waiting...")) {
			// Show with default zone, pause engine and print result to debug log
			Advertisement.Show(null, new ShowOptions {
				pause = true,
				resultCallback = result => {
					Debug.Log(result.ToString());
				}
			});
		}
	}
}

Your class is called Advertisement. This creates a name conflict. When your code tries to find Advertisement.isSupported or similar it looks in your class. Since your class doesn’t have those you get the error. There two solutions.

  1. Change the name of your behavior to something else. This is the preferred solution.
  2. Use the fully qualified name of UnityAds classes anywhere you use them, i.e. UnityEngine.Advertisements.Advertisement.isSupported