- Home /
UNity ads (in windows build) gives error (error CS0246: The type or namespace name `ShowResult' )
So I am intregrating unity ads into my projects. They sort of work with android...sometimes. However when I build the windows 86/64 build, it gives this error.
Assets/Plugins/AddCoins.cs(31,39): error CS0246: The type or namespace name `ShowResult' could not be found. Are you missing a using directive or an assembly reference?
I am assuming this is not understood by windows. How do I get rid of this error and build for windows?
Here is the AddCoins Script. I added some error checking to see what is happening. It's on this line (private void HandleShowResult(ShowResult result).
using UnityEngine;
using UnityEngine.Advertisements;
/////////////////////////////////////////////////////
public class AddCoins : MonoBehaviour
{
static public bool adReady = false;
static public int adState = 0;
/////////////////////////////////////////////////////
public void Update()
{
if (Advertisement.IsReady ("rewardedVideo"))
{
adReady = true;
}
else
{
adReady = false;
}
}
/////////////////////////////////////////////////////
public void ShowRewardedAd()
{
////////////////////////////////////////////////////
if (Advertisement.IsReady ("rewardedVideo"))
{
var options = new ShowOptions { resultCallback = HandleShowResult };
Advertisement.Show ("rewardedVideo", options);
}
}
/////////////////////////////////////////////////////
private void HandleShowResult(ShowResult result)
{
switch (result)
{
case ShowResult.Finished:
Debug.Log("The ad was successfully shown.");
adState = 1;
CoinsHas.coinsLeft = CoinsHas.coinsLeft + 1;
break;
case ShowResult.Skipped:
Debug.Log("The ad was skipped before reaching the end.");
adState = 2;
break;
case ShowResult.Failed:
Debug.LogError("The ad failed to be shown.");
adState = 3;
break;
}
//Save Coins
ES2.Save (CoinsHas.coinsLeft, "...");
}
/////////////////////////////////////////////////////
}
/////////////////////////////////////////////////////
experience same error . I my case I disable the ads in editor services (5.2+ required) and trying to show ads. ( That's why this error came :The type or namespace name `ShowResult' could not be found. Are you missing a using directive or an assembly reference) when I enable ads error gone. enable ads in editor.
Same here, ads works fine on Android & iOS, but I can't build Web and WebGL. How to make it "ignore" this checks on other platforms?
I have the same issue, is there are quick solution for this, besides having 2 different projects 1 with ads code one without? Afaik "Unity" comes from solving cross-platform issues for programmer, so what is the correct solution here?
private void HandleShowResult(ShowResult result)
defines a variable 'result' of type 'ShowResult' as an argument. Do you have a script or a defined class called ShowResult, accessible to that script?
Answer by Tabu · Oct 25, 2016 at 02:28 PM
I had this problem as well - solved it by going to the Ads under services ( Window -> Services ) and then under advanced tick in "Enable buildin Ads extensions"
This turned out to be the solution for me getting this error in editor, building to iOS.
The odd thing is I'd been working for hours without issue and apparently the checkbox unchecked itself. This seems to happen a lot when installing new versions, but this is the first time it happened to me in the middle of working.
Answer by aykut-yilmaz · Aug 18, 2016 at 11:43 AM
@wheretheidivides
You can try compiler directives. In a simple form, use something like the following:
#if UNITY_ANDROID
// Android specific code
#elif UNITY_IPHONE
// iPhone specific code
#else
// other platforms
#endif
There is some more information in below link:
https://docs.unity3d.com/353/Documentation/Manual/PlatformDependentCompilation.html
I have a similar case to yours, so I put both above functions into an #if. I also want to call the ShowRewardedAd function from somewhere else. But if the compiler doesn't compile it, then I will get a runtime error, so I made a different function named ShowUnityRewardedAd and I am calling that one. My project is not yet complete and I can not compile for IOS due to some other problem. Therefore below code is not fully tested and I may have some loose ends but basically this is how I did it:
using UnityEngine;
using System.Collections;
using UnityEngine.Advertisements;
public class UnityAdScript : MonoBehaviour {
public static bool unityAdWatched;
public void ShowUnityRewardedAd()
{
unityAdWatched = false;
#if UNITY_ANDROID || UNITY_IPHONE
ShowRewardedAd();
#endif
}
#if UNITY_ANDROID || UNITY_IPHONE
private void ShowRewardedAd()
{
if (Advertisement.IsReady("rewardedVideoZone"))
{
var options = new ShowOptions { resultCallback = HandleShowResult };
Advertisement.Show("rewardedVideoZone", options);
}
}
private void HandleShowResult(ShowResult result)
{
switch (result)
{
case ShowResult.Finished:
Debug.Log("The ad was successfully shown.");
//
// YOUR CODE TO REWARD THE GAMER
// Give coins etc.
unityAdWatched = true;
break;
case ShowResult.Skipped:
Debug.Log("The ad was skipped before reaching the end.");
break;
case ShowResult.Failed:
Debug.LogError("The ad failed to be shown.");
break;
}
}
#endif
}