Void Update. Only once.
Hi, I need to show an Insterticial Ad when the player is dead ussing this Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class aaa : MonoBehaviour {
public GameObject GameOverSplash;
void Update()
{
if(GameOverSplash.active)
{
EasyGoogleMobileAds.GetInterstitialManager().ShowInterstitial();
}
}
}
An it works but the Script show a Ad every second. But when I use Void Start, It does not work.
I need to show the Ad only once.
Thanks for the help.
Have a good day.
Answer by Hellium · Jan 25, 2018 at 05:08 PM
Simply disable after you have called the function:
void Update()
{
if(GameOverSplash.active)
{
EasyGoogleMobileAds.GetInterstitialManager().ShowInterstitial();
enabled = false ;
}
}
Or, use coroutines:
IEnumerator Start()
{
yield return null ; // Wait one frame
EasyGoogleMobileAds.GetInterstitialManager().ShowInterstitial();
}
Yeah man, It works with the first, but the script shows the Add two times.
Are you sure you haven't attached the script twice? ($$anonymous$$aybe on two different objects)
Answer by pekaram · Feb 18, 2018 at 12:50 PM
Instead of using an aaa.Update(), you can use GameOverSplash.OnEnable() method. https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnEnable.html
Answer by taib · Aug 09, 2020 at 03:41 AM
the simple way, like i always do, i make prefab and put some ads script inside that prefab and instantiate that prefab after enemy or player die.. and destroy it around 0.1f..
Your answer
Follow this Question
Related Questions
How do GameObjects detect void Update and how to make my custom one. 0 Answers
How can i enable and disable a void function on the update function? 1 Answer
Delay in update and only one Input.GetButton 1 Answer
What is the difference between Update() , LateUpdate() , FixedUpdate(), and when i should use them 3 Answers