现在,游戏中每次玩家死后都会播放广告。我希望广告在玩家第三次死后出现。请指导我,因为我是一个初学者,没有真正的知识编码。还请指定是否需要将脚本附加到特定的游戏对象。
我已经把广告代码放在下面了。谢谢。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
public GameObject gameOverCanvas;
public GameObject Interstitial;
public int DeathCount = 0;
private void Start()
{
Time.timeScale = 1;
}
public void GameOver()
{
gameOverCanvas.SetActive(true);
Time.timeScale = 0;
DeathCount++;
}
private bool DeathCountCheck()
{
if (DeathCount == 3)
{
// Reset the variable, otherwise it will increase indefinitely and the condition will not be met in the future
Interstitial.GetComponent<InterstitialAds>().ShowInterstitial();
DeathCount = 0;
return true;
}
return false;
}
public void Replay()
{
SceneManager.LoadScene(0);
}发布于 2022-01-13 11:20:50
如果每次玩家死后,"deathCount“都会增加,那么当广告显示给你看的时候,只需检查这个变量并适当地重置它。
// Function that checks if there were 3 deaths
private bool DeathCountCheck()
{
if (deathCount == 3)
{
// Reset the variable, otherwise it will increase indefinitely and the condition will not be met in the future
deathCount = 0;
return true;
}
return false;
}然后在"ShowInterstitialAd“中添加另一个条件
public void ShowInterstitial()
{
if (Advertisement.IsReady(interstitialID) && DeathCountCheck())
{
Advertisement.Show(interstitialID);
}
}https://stackoverflow.com/questions/70695506
复制相似问题