Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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
0
Question by MonqoStudios · Dec 04, 2018 at 07:08 PM · error

Game restarts when it is supposed to show ads.

Hello,

In my game the player can watch an ad to activate a skill with grants the player more coins. But when the button is pressed and the ad is supposed to start, the game restarts.

My game isn't published in the playstore, could this also cause this error?

Script:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine.Advertisements;
 using UnityEngine;
 
 public class MainAdScript : MonoBehaviour {
 
 
     public bool SkillActive = false;
     public float EndCounter;
     public float EndToShow;
     public float StartAdCounter;
     public GUIStyle TextGuiStyle;
 
 
 
 
     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;
         }
 
     }
 
     public void ShowAd() {
 
         if (Advertisement.IsReady())
         {
             Advertisement.Show("rewardedVideo", new ShowOptions() { resultCallback = HandleAdResult });
         }
 
     }
 
     private void HandleAdResult(ShowResult result) {
 
         switch (result) {
             case ShowResult.Finished:
                 Debug.Log("Add Bonus");
                 break;
             case ShowResult.Skipped:
                 Debug.Log("Skipped");
                 break;
             case ShowResult.Failed:
                 SkillActive = true;
                 break;
         }
 
     }
 
     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")) {
                     ShowAd();
                     StartAdCounter = -100;
                 }
 
 
             }
         }
 
     }
 
 }

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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.

Follow this Question

Answers Answers and Comments

124 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 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 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

Missing Component Error 1 Answer

I need help with an error 1 Answer

Every script says "can not load script" and that there is no monobehavior in the file 2 Answers

Error in the script 0 Answers

Limit rotation for a statue puzzle 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges