本文介绍了Unity3D中的AppLovin广告:未触发onAppLovinEventReceived的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Unity3D iOS游戏中使用了Applovin全屏广告.

I used Applovin fullscreen ads in Unity3D iOS game.

广告运行良好.但是事件监听器没有被触发.我希望跟踪失败事件调用.

Ads are working good. But event listener not fired. I wish to track fail event call.

public static void StartApplovin ()
    {
        AppLovin.SetSdkKey("My_SDK_Key");
        AppLovin.InitializeSdk();

        AppLovin.SetUnityAdListener("ApplovinListener");
    }

这是ApplovinListener.cs类

Here is ApplovinListener.cs class

public class ApplovinListener : MonoBehaviour {

    void onAppLovinEventReceived(string ev)
    {
        Debug.Log ("\n\nonAppLovinEventReceived\n\n");

        if(ev.Contains("DISPLAYEDINTER")) {
            // An ad was shown.  Pause the game.
        }
        else if(ev.Contains("HIDDENINTER")) {
            // Ad ad was closed.  Resume the game.
            // If you're using PreloadInterstitial/HasPreloadedInterstitial, make a preload call here.
            AppLovin.PreloadInterstitial();
        }
        else if(ev.Contains("LOADEDINTER")) {
            // An interstitial ad was successfully loaded.
        }
        else if(string.Equals(ev, "LOADINTERFAILED")) {
            // An interstitial ad failed to load.
            GameCenter2.ShowAdmobAds ();
            Debug.Log ("\n\n Applovin FAILED\n\n");

        }
    }

 }

当我运行时,Xcode会在下面显示控制台日志.

When I run, Xcode gives below console log.

SendMessage: object ApplovinListener not found!

如何调用onAppLovinEventReceived?

How to get onAppLovinEventReceived called ?

更新:我已通过创建gameObject解决了此问题

UPDATE: I have fixed this problem by creating gameObject

在Unity Manu中,按GameObject->创建空白

In Unity Manu, Press GameObject->Create Empty

将其命名为"ApplovinListener"

Name it "ApplovinListener"

现在将名为ApplovinListener的脚本附加到游戏对象.就是这样.

Now attach script named ApplovinListener to game object. That’s it.

推荐答案

您的ApplovinListener脚本必须附加到传递到AppLovin.SetUnityAdListener函数的GameObject的名称上,以便onAppLovinEventReceived函数成为叫.

Your ApplovinListener script must be attached to the name of the GameObject that is passed into the AppLovin.SetUnityAdListener function in order for the onAppLovinEventReceived function to be called.

您有这个:

AppLovin.SetUnityAdListener("ApplovinListener");

确保有一个实际上名为"ApplovinListener"的GameObject.现在,确保将ApplovinListener脚本附加到该脚本.完成此操作后,应调用onAppLovinEventReceived函数.

Make sure that there is a GameObject actually named "ApplovinListener". Now, make sure that the ApplovinListener script is attached to it. The onAppLovinEventReceived function should be called after you do this.

为方便起见,建议您改为:

To make this easier for you, I recommend you do this instead:

AppLovin.SetUnityAdListener(yourGameObject.name);

然后将ApplovinListener脚本附加到您上面引用的GameObject.

then attach the ApplovinListener script to that GameObject you referenced above.

这篇关于Unity3D中的AppLovin广告:未触发onAppLovinEventReceived的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-29 11:36