- Home /
WebGL doesn't work when using UnityEngine.Advertisements
Whenever I try to build to WebGL, I receive the following error:
Assets/Scripts/SettingsButtons.cs(98,17): error CS0246: The type or namespace name `ShowOptions' could not be found. Are you missing a using directive or an assembly reference?
Does this mean that it won't work because of the advertisements? If so, how can I have them automatically be disabled when I build to WebGL?
Here's the full script for context (It's a kind of swiss-army knife script so there's a bunch of useless stuff in there. I'll remove what I can)
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Analytics;
using UnityEngine.Advertisements;
using System;
using System.Collections;
using System.Collections.Generic;
public class SettingsButtons : MonoBehaviour {
public bool Value;
public Image Img;
public Sprite EnabledSprite;
public Sprite DisabledSprite;
//Ads Stuff
public string zoneId;
// Use this for initialization
void Start () {
GameObject.Find("MainMenu").GetComponent<Animator>().SetBool("Visible", true);
GameObject.Find("ExtraMenu").GetComponent<Animator>().SetBool("Visible", false);
}
// Update is called once per frame
void Update () {
}
public void ShowAd () {
if (string.IsNullOrEmpty (zoneId)) zoneId = null;
ShowOptions options = new ShowOptions();
options.resultCallback = HandleShowResult;
Advertisement.Show (zoneId, options);
}
public void ExpressAppreciation () {
GameObject.Find("Thanks").GetComponent<Animator>().SetTrigger("Show");
}
public void ExpressRegret () {
GameObject.Find("YouSuck").GetComponent<Animator>().SetTrigger("Show");
}
public void ExpressERROR () {
GameObject.Find("Error").GetComponent<Animator>().SetTrigger("Show");
}
private void HandleShowResult (ShowResult result)
{
switch (result)
{
case ShowResult.Finished:
ExpressAppreciation();
break;
case ShowResult.Skipped:
ExpressRegret();
break;
case ShowResult.Failed:
ExpressERROR();
break;
}
}
}
Thanks in advance if someone can help.
Nothing yet. I don't wanna have to remove all the related code every time I make a build. :\
Answer by roojerry · May 16, 2016 at 02:18 PM
Wrap your advertise code with preprocessor directives for WebGL. This will keep the code from being compiled for that platform, rather than having to manually remove it yourself.
Your answer
Follow this Question
Related Questions
Failed build WebGL in Unity5.0.1 2 Answers
Distribute terrain in zones 3 Answers
video-audio not playing in build (i tried webgl and android) 0 Answers
building WebGL app hangs 0 Answers
SetCursor WebGL doesn't work 1 Answer