Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

461
Views
Unidad - Anuncio llamado varias veces

Tengo este problema al usar el anuncio de Unity. Específicamente después de ver el video y hacer clic en el botón X para cerrar el video, debería darle el premio al jugador (pasar al siguiente nivel). El problema es que la función OnUnityAdsDidFinish llama a if (showResult == ShowResult.Finished) varias veces. ¿Qué estoy haciendo mal? ¿Cómo llamo a la función FindObjectOfType () .LoadNextLevel () una vez? ? Gracias de antemano

 public class UnityAdsInterstitial : MonoBehaviour, IUnityAdsListener { private string gameID = "******"; //nome scelto nella DashBoard di Unity private string interstitialID = "interstitial"; private string myPlacementId = "rewardedVideo"; public int randomHighValue = 30; private bool TestMode = true; private bool adsClosed = false; public Button _button; private void Awake() { _button = GetComponent<Button>(); } void Start() { Debug.Log("Ads start"); _button = GameObject.Find("StartAds").GetComponent<Button>(); _button.interactable = Advertisement.IsReady(myPlacementId); if (_button) _button.onClick.AddListener(ShowRewardedVideo); Advertisement.Initialize(gameID, TestMode); Advertisement.AddListener(this); if (adsClosed) { adsClosed = false; } } public void ShowInterstitial() { if (Advertisement.IsReady(interstitialID) ) { Advertisement.Show(interstitialID); } } public void ShowRewardedVideo() { if (Advertisement.IsReady(myPlacementId)) { Debug.Log("Rewarded video is Ready"); Advertisement.Show(myPlacementId); } else { Debug.Log("Rewarded video is not ready at the moment! Please try again later!"); } } public void HideBanner() { Advertisement.Banner.Hide(); } public void OnUnityAdsReady(string placementdID) { if (placementdID == interstitialID) { Debug.Log("InterstitialIsReady"); } if (placementdID == myPlacementId) { Debug.Log("RewardedIsReady"); _button.interactable = true; } } public void OnUnityAdsDidFinish(string placementdID, ShowResult showResult) { if (showResult == ShowResult.Finished) { // Reward the user for watching the ad to completion. if (!adsClosed) { adsClosed = true; FindObjectOfType<LevelLoader>().LoadNextLevel(); } } else if (showResult == ShowResult.Skipped) { // Do not reward the user for skipping the ad. } else if (showResult == ShowResult.Failed) { Debug.LogWarning("The ad did not finish due to an error."); } } public void OnUnityAdsDidError(string message) { Debug.Log("OnUnityAdsDidError"); } public void OnUnityAdsDidStart(string message) { Debug.Log("OnUnityAdsDidStart"); }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Comenzaría mi investigación verificando la identificación de la ubicación (en caso de que haya más ubicaciones)

  1. Comprobación de que la devolución de llamada es para el ID de ubicación adecuado
 if (showResult == ShowResult.Finished && placementId == myPlacementId) { // Reward the user for watching the ad to completion. if (!adsClosed) { adsClosed = true; FindObjectOfType<LevelLoader>().LoadNextLevel(); } }

La segunda sería que solo tengo una instancia activa de UnityAdsInterstitial . Puede verificar esto en el modo de depuración por la referencia del objeto. Si más de una instancia comienza en otro lugar de su código, entonces debe limitarse a una.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!