【问题标题】:Controll time between ads in Unity3D Game在 Unity3D 游戏中控制广告之间的时间
【发布时间】:2018-05-18 02:17:26
【问题描述】:

我使用下面的 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 寻找相同的样式代码来控制广告之间的时间。请帮帮我。

【问题讨论】:

    标签: c# ios iphone xcode unity3d


    【解决方案1】:

    您不能像在 C++ 和 Object-C 中那样在函数中使用 static。在函数外部声明使用静态限定符的变量。您可以将NSTimeIntervaltimeIntervalSinceReferenceDate 替换为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
    
    }
    

    【讨论】:

    • 非常感谢您的快速回答。我会尽快检查。
    • 当然。如果有问题请告诉我
    • 我知道你是 Unity 开发专家,是否可以从统一代码中检查它的免费或付费应用程序?这是类似的问题。如果您知道 c# stackoverflow.com/questions/50403160/… 的代码,请回答
    • 我可以回答这个问题,但你必须付出一些努力,否则你会要求人们为你做移植工作。只需谷歌“如何在 Unity 中发出 http 请求”,然后 “如何在 Unity 中反序列化 json”。有了这两个,您可以将一些东西放在一起,如果它不起作用,请使用 Object-C 代码和尝试的 C# 移植代码创建一个新帖子并解释问题,我来的时候会看看它。该帖子已关闭,因为您没有努力实际移植代码。
    • 我已经花了 8 个多小时来做这件事……没有得到正确的电话来获取价格……谷歌搜索了很多次代码并运行了很多次……不知道如何检查它是否免费或付费应用程序...如果您知道请帮助我..如果编码需要很多小时,请忽略。
    猜你喜欢
    • 2015-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-16
    • 1970-01-01
    相关资源
    最近更新 更多