在 Unity3D 游戏中控制广告之间的时间

我使用下面的 obj.C 代码来处理要显示的广告之间的时间。但是现在我需要在 C# 中为 Unity3D 使用相同的代码。


-(void)showFullScreenads

{

    static NSTimeInterval gCBLastFail = -999;

    static bool isFirssst = true;


    if(!isFirssst)

    {

        NSTimeInterval intr = [NSDate timeIntervalSinceReferenceDate];


        float diff = intr - gCBLastFail;


        if(diff < 60.0f) // don't show ads if less than 60 sec

        {

            return;

        }

        else

        {

            gCBLastFail = [NSDate timeIntervalSinceReferenceDate];

        }

    }


    gCBLastFail = [NSDate timeIntervalSinceReferenceDate];

    isFirssst = false;


    [self showGoogleAdmobAds];

}

为 unity3d 寻找相同样式的代码来控制广告之间的时间。请帮我。


MM们
浏览 229回答 1
1回答

蓝山帝景

您不能static像在 C++ 和 Object-C 中那样在函数中使用。在函数外声明使用静态限定符的变量。您可以替换NSTimeInterval或timeIntervalSinceReferenceDate使用Time.time。如果showFullScreenads从Update每帧调用的函数中调用此函数,效果会更好。是等效的 C# 函数:static float gCBLastFail = -999;static bool isFirssst = true;void showFullScreenads(){&nbsp; &nbsp; if (!isFirssst)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; float intr = Time.time;&nbsp; &nbsp; &nbsp; &nbsp; float diff = intr - gCBLastFail;&nbsp; &nbsp; &nbsp; &nbsp; if (diff < 60.0f) // don't show ads if less than 60 sec&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Debug.Log("Add not displayed");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; else&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gCBLastFail = Time.time;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; gCBLastFail = Time.time;&nbsp; &nbsp; isFirssst = false;&nbsp; &nbsp; Debug.LogWarning("Add displayed");&nbsp; &nbsp; showGoogleAdmobAds();}void showGoogleAdmobAds(){&nbsp; &nbsp; //Your admob plugin code to show ad}
打开App,查看更多内容
随时随地看视频慕课网APP