• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
6
Question by SupremeEnchanter · Nov 23, 2015 at 04:26 AM · unity 5erroradsshowcs0246

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, "...");
     }
     /////////////////////////////////////////////////////
 }
 /////////////////////////////////////////////////////
 
Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image waqaswaqas · Dec 27, 2015 at 11:47 AM 0
Share

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.

avatar image niceplay_games · Mar 21, 2016 at 09:55 AM 0
Share

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?

avatar image _watcher_ · Jun 21, 2016 at 02:23 PM 0
Share

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?

avatar image meat5000 ♦ · Aug 18, 2016 at 11:49 AM 0
Share
 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?

2 Replies

· Add your reply
  • Sort: 
avatar image
4

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"

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Shaolin-Dave · Oct 30, 2016 at 05:10 AM 0
Share

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.

avatar image Devilzzz · Jan 30, 2017 at 11:31 AM 0
Share

Nice... this worked for me as well!

avatar image
0

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
 }
 


Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

52 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Error building Player because scripts had compiler errors 2 Answers

[Google Cardboard SDK] Error Importing Package CS0246 0 Answers

ADMob ads no show 3 Answers

Shader worked in Unity 4.5, now Unity 5 kills it. 1 Answer

Assets/Scripts/Board.cs(2914,17): error CS0103: The name `Advertisement' does not exist in the current context 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges