Quantcast
Channel: Questions in topic: "ads"
Viewing all articles
Browse latest Browse all 1416

Unity Ads don't work

$
0
0
Like the title says I can't get ads to work. Mostly nothing happens and if something happens the game restarts using System.Collections; using System.Collections.Generic; using UnityEngine.Advertisements; using UnityEngine; public class MainAdScript : MonoBehaviour { private string GameId = "2949676"; public bool SkillActive = false; public float EndCounter; public float EndToShow; public float StartAdCounter; public GUIStyle TextGuiStyle; public void Start() { Advertisement.Initialize(GameId); } public void ShowRewardedAd() { if (Advertisement.IsReady("rewardedVideo")) { var options = new ShowOptions { resultCallback = HandleShowResult }; Advertisement.Show("rewardedVideo"); } } private void HandleShowResult(ShowResult result) { switch (result) { case ShowResult.Finished: Debug.Log("The ad was successfully shown."); MainScript.CurrentCoins += 10000; 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; } } void Update() { if (SkillActive == true) { PinScript.SkillActiveBonus = 4; } else { PinScript.SkillActiveBonus = 1; } StartAdCounter += 1 * Time.deltaTime; if (StartAdCounter < 200) { EndCounter = 0; EndToShow = 60; } if (EndToShow < 0) { StartAdCounter = 0; } } private void OnGUI() { if (StartAdCounter >= 200) { if (SpawnBall.BallActive == false) { EndCounter += 1 * Time.deltaTime; if (EndCounter > 1) { EndCounter = 0; EndToShow -= 1; } GUI.Box(new Rect(Screen.width / 30, Screen.height / 5, Screen.width / 4.9f, Screen.height / 3.5f), ""); GUI.Label(new Rect(Screen.width / 18, Screen.height / 4.1f, Screen.width / 2, Screen.height / 2), "Watch an ad for 4x", TextGuiStyle); GUI.Label(new Rect(Screen.width / 18, Screen.height / 3.6f, Screen.width / 2, Screen.height / 2), "coins for 3 minutes!", TextGuiStyle); GUI.Label(new Rect(Screen.width / 18, Screen.height / 2, Screen.width / 2, Screen.height / 2), "Offer expires in: " + EndToShow, TextGuiStyle); if (GUI.Button(new Rect(Screen.width / 28, Screen.height / 2.74f, Screen.width / 5, Screen.height / 8), "Sure")) { ShowRewardedAd(); StartAdCounter = -100; } } } } }

Viewing all articles
Browse latest Browse all 1416

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>