/// <summary> /// Tries to display a video ad. This could fail if an ad is not available or ready, /// the player requesting the ad is hosting the game - in which case showing an ad would /// pause the game for all clients - an ad was already shown or the percentage based /// chance has calculated to not show an ad for this attempt. All these checks can be /// skipped by setting the argument passed in to true, effectively forcing an ad to show. /// </summary> public static bool ShowAd(bool force = false) { if (force || !GameManager.isMaster() && !adShown && GetInstance().shouldShowAd()) { if (Advertisement.IsReady()) { //this attempt should show an ad: initialize ad and pass the result to //the HandleResult method. Stop recording gameplay video while showing an ad Advertisement.Show("", new ShowOptions { resultCallback = GetInstance().HandleResult }); UnityEveryplayManager.PauseRecord(); return(true); } } //at this point we were not able to show an ad yet. //if this ad attempt has not been forced, increase attempt counter //so the next attempt has a higher probability of showing an ad if (!force) { counter++; } return(false); }