找不到类型或名称空间名称“ GameManager”

时间:2020-08-06 17:54:55

标签: c# unity3d admob

我一直在尝试为第一款游戏编写一些代码,这样,如果用户没有观看(来自admob的)完整的奖励视频广告,并且他更早关闭了该视频,那么他不会要求实际奖励是额外的生活。
我想做的第一件事是将GameObject(关联了“ ads脚本”)从Menu Scene移到Game Scene,因为我想从游戏场景访问功能更容易。 > 看完一些教程之后,以下是“奖励视频广告”的代码:

public class ads : MonoBehaviour
{
private RewardedAd rewardedAd;
private void RequestReward()
    {
        string adUnitId = "ca-app-pub-3940256099942544/5224354917";
        this.rewardedAd = new RewardedAd(adUnitId);

        this.rewardedAd.OnAdLoaded += this.HandleOnRewardedAdLoaded;
        this.rewardedAd.OnUserEarnedReward += this.HandleOnRewarded;
        this.rewardedAd.OnAdClosed += this.HandleOnRewardedAdClosed;

        AdRequest request = new AdRequest.Builder().Build();
        this.rewardedAd.LoadAd(request);
    }
public void ShowRewardVideo()
    {
        if (this.rewardedAd.IsLoaded())
        {
            this.rewardedAd.Show();
        }
        else
        {
            Debug.Log("Reward video is not ready yet");
        }
    }
public void HandleOnRewardedAdLoaded(object sender, EventArgs args)
    {
        ShowRewardVideo();
    }
public void HandleOnRewarded(object sender, EventArgs args)
    {
      // SO, If I understand properly, if I want players not to receive the extra life<br>
      before the reward video is finished, I have to write here the code for receiving the extra life 
      instead of writing it in the GameManager script. (script that is down below)

    }
public void HandleOnRewardedAdClosed(object sender, EventArgs args)
    {
        this.rewardedAd.OnAdLoaded -= this.HandleOnRewardedAdLoaded;
        this.rewardedAd.OnUserEarnedReward -= this.HandleOnRewarded;
        this.rewardedAd.OnAdClosed -= this.HandleOnRewardedAdClosed;
    }

在这里,我具有GameScript的2个功能,这些功能可以让我展示广告: 第一个,当按下游戏中的按钮“观看额外的生命”时被调用

public void ShowReward()
{
        birdParent.SetActive(false);
        ads.instance.ShowRewardVideo();
        gameOverCanvas.SetActive(false);
        score.SetActive(false);
      ->rewardPanel.SetActive(true);
        Time.timeScale = 0;
}

单击该按钮后,视频开始播放,如您在功能中所看到的,带有奖励的面板被激活(无论您观看了完整视频还是关闭了完整视频)。然后,在完成视频播放后,您会回到游戏中,在面板上显示诸如“感谢您观看视频,这是您的额外生命。请按OK”。当按下“确定”按钮时,将调用此功能

public void ContinueAfterReward()
{
    score.SetActive(true);
    rewardPanel.SetActive(false);
    Time.timeScale = 1;
    Start();
    GameHasStarted();
    bird.Start();
    bird.Update();
    score.SetActive(true);
}

问题在于这两个函数位于“ GameManager”脚本(位于GameManager对象中)中,但我希望它们以某种方式集成到“ ads”脚本(位于标准GameObject对象中)中的脚本中),这样我就可以在该句柄工具中插入或调用函数,以防止用户希望获得奖励而跳过视频。我试图在广告脚本中声明一个“ public GameManager gameManager”(因此之后我应该能够调用广告脚本中的函数),但是它根本不起作用,我从标题中得到了错误。
< br /> 我不知道您是否了解我想做的事,但是如果您有任何想法请写答复,因为我在这件事上苦苦挣扎了几个小时,只是想不通..或者您是否知道其他方法.. :)

编辑: enter image description here

因此,基本上,在GameObject中,我有脚本“ ads”,在其中,我想从GameManager对象的“ GameManager”脚本中调用某些函数。即使我在GM脚本中声明了公共静态GameManager实例,也无法在ads脚本中调用GameManager.instance.ShowReward()或public GameManager GameManager。我该怎么办?

enter image description here

enter image description here

有趣的是,正如您在上一张照片中所看到的,我有一个与鸟脚本相关联的鸟游戏对象,并且在其中可以调用gamemanager脚本..并不是因为大写字母,我尝试了gameManager和GameManager

enter image description here

1 个答案:

答案 0 :(得分:1)

在这种情况下,所有迹象都表明Unity试图迫使adsGameManager之前进行编译。

进入Unity编辑器,将adsGoogleMobileAds目录中移到另一个Assets目录中,因为GoogleMobileAds可能被专门配置为首先编译/早。

在不太可能的情况下无法正常工作,请将adsGameManager放在同一目录中。