Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Unity 2022.2 is now available as the latest Tech release.
    Dismiss Notice
  3. We are making some changes to the DOTS forums.
    Dismiss Notice
  4. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

mute ad volume

Discussion in 'Unity Ads & User Acquisition' started by No-jo, Jun 18, 2015.

Thread Status:
Not open for further replies.
  1. No-jo

    No-jo

    Joined:
    Aug 30, 2014
    Posts:
    8
    Hi,

    Been struggling to find a solution to this.

    I have a mute music button in my game. The status is saved in PlayerPrefs for the next time the user loads the app. I can't seem to get Unity Ads to mute at all.

    I have unity Ads load in separate scenes - once after my game intro and once after game over.

    I have a global boolean - "music" - which is set to either true or false according to the playerPrefs setting on my intro scene. It is working fine except in the ads.

    I have tried in numerous places:

    Code (CSharp):
    1. if (!GlobalVar.music)
    2.             AudioListener.volume = 0;
    Isn't there an Advertisement.volume type method?

    Here is my unity ads script for my intro adverts. Can't truely remember where I originally lifted it from to be honest:

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Advertisements;
    3. using System.Collections;
    4.  
    5. public class UnityAds : MonoBehaviour
    6. {
    7.     void Start ()
    8.     {
    9.  
    10.         Advertisement.Initialize ("XXXXX", false);
    11.        
    12.         StartCoroutine (ShowAdWhenReady ());
    13.     }
    14.    
    15.     IEnumerator ShowAdWhenReady()
    16.     {
    17.         while (!Advertisement.isReady ())
    18.             yield return null;
    19.        
    20.  
    21.         DoShowAd(null);
    22.  
    23.     }
    24.  
    25.     // Use this method to show an ad from an external class.
    26.     public static void ShowAd (string zone = null)
    27.     {
    28.         if (Advertisement.isInitialized)
    29.         {
    30.            
    31.  
    32.             if (Advertisement.isReady(zone)) DoShowAd(zone);
    33.             else Debug.LogWarning("Unable to show advertisement. Placement zone is not ready.");
    34.         }
    35.         else Debug.LogError("Failed to show advertisement. Unity Ads is not initialized.");
    36.     }
    37.    
    38.     private static void DoShowAd (string zone = null, int version = 0)
    39.     {
    40.         if (!GlobalVar.music)
    41.             AudioListener.volume = 0;
    42.         // Functionality wise, the following two DoShowAd methods do exactly the same thing.
    43.         //  The CondensedVersion is simply a clever way of writing the ExpandedVersion.
    44.         //  They are provided here as examples of two different styles of coding.
    45.         switch (version)
    46.         {
    47.         case 0:
    48.             DoShowAd_CondensedVersion(zone);
    49.             break;
    50.         case 1:
    51.             DoShowAd_ExpandedVersion(zone);
    52.             break;
    53.         }
    54.     }
    55.    
    56.     private static void DoShowAd_CondensedVersion (string zone, bool pauseGameDuringAd = true)
    57.     {
    58.  
    59.         if (!GlobalVar.music)
    60.             AudioListener.volume = 0;
    61.  
    62.         Advertisement.Show(zone, new ShowOptions {
    63.  
    64.  
    65.             // With the pause option set to true, the timeScale and AudioListener
    66.             //  volume for your game is set to 0 while the ad is shown.
    67.             pause = pauseGameDuringAd,
    68.             // The resultCallback is triggered when the ad is closed.
    69.             resultCallback = result => {
    70.                 HandleShowResult(result);
    71.             }
    72.         });
    73.  
    74.       if (!GlobalVar.music)
    75.             AudioListener.volume = 0;
    76.     }
    77.    
    78.     private static void DoShowAd_ExpandedVersion (string zone, bool pauseGameDuringAd = true)
    79.     {
    80.         if (!GlobalVar.music)
    81.             AudioListener.volume = 0;
    82.  
    83.         ShowOptions options = new ShowOptions();
    84.  
    85.         // With the pause option set to true, the timeScale and AudioListener
    86.         //  volume for your game is set to 0 while the ad is shown.
    87.         options.pause = pauseGameDuringAd;
    88.         // The resultCallback is triggered when the ad is closed.
    89.         options.resultCallback = HandleShowResult;
    90.  
    91.  
    92.         Advertisement.Show(zone,options);
    93.  
    94.       if (!GlobalVar.music)
    95.             AudioListener.volume = 0;
    96.     }
    97.    
    98.     private static void HandleShowResult (ShowResult result)
    99.     {
    100.         switch (result)
    101.         {
    102.         case ShowResult.Finished:
    103.             Debug.Log("The ad was successfully shown.");
    104.             break;
    105.         case ShowResult.Skipped:
    106.             Debug.Log("The ad was skipped before reaching the end.");
    107.             break;
    108.         case ShowResult.Failed:
    109.             Debug.LogError("The ad failed to be shown.");
    110.             break;
    111.         }
    112.        
    113.         Application.LoadLevel ("Menu");
    114.         AudioListener.volume = 1;
    115.        
    116.        
    117.     }
    118. }
    Many Thanks
     
  2. No-jo

    No-jo

    Joined:
    Aug 30, 2014
    Posts:
    8
    anyone?
     
  3. renezuidhof

    renezuidhof

    Joined:
    Oct 25, 2013
    Posts:
    3
    Did you find an answer? I am having the exact same problem
     
  4. No-jo

    No-jo

    Joined:
    Aug 30, 2014
    Posts:
    8
    In the end I contacted UnityAds directly. This was their response (short answer - No):

    Hope this helps.
     
  5. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,760
    This is dumb. I want to mute ads when my game is mute, but not when my game is not mute... how could this not be an option.
     
  6. stack86

    stack86

    Joined:
    Jul 22, 2016
    Posts:
    11
    This is F***ing ridiculous. My testers have complained about unmuted Ads when they've muted my game.. and my only possible solution is to permanently mute all Ads for all users!?
     
Thread Status:
Not open for further replies.