为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

C#
MM们 2021-06-15 17:35:02
我使用下面的 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 寻找相同样式的代码来控制广告之间的时间。请帮我。
查看完整描述

1 回答

?
蓝山帝景

TA贡献1843条经验 获得超7个赞

您不能static像在 C++ 和 Object-C 中那样在函数中使用。在函数外声明使用静态限定符的变量。您可以替换NSTimeInterval或timeIntervalSinceReferenceDate使用Time.time。如果showFullScreenads从Update每帧调用的函数中调用此函数,效果会更好。


是等效的 C# 函数:


static float gCBLastFail = -999;

static bool isFirssst = true;


void showFullScreenads()

{

    if (!isFirssst)

    {

        float intr = Time.time;


        float diff = intr - gCBLastFail;


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

        {

            Debug.Log("Add not displayed");

            return;

        }

        else

        {

            gCBLastFail = Time.time;

        }

    }


    gCBLastFail = Time.time;

    isFirssst = false;


    Debug.LogWarning("Add displayed");

    showGoogleAdmobAds();

}


void showGoogleAdmobAds()

{

    //Your admob plugin code to show ad


}


查看完整回答
反对 回复 2021-06-20
  • 1 回答
  • 0 关注
  • 212 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信