这是谷歌admob脚本,但Unity给我错误参数1:无法从“string”转换为“System.Action<GoogleMobileAds.Api.InitializationStatus>”。它在void Start()函数中为appID加下划线,并表示参数1:无法从“string”转换为“System.Action<GoogleMobileAds.Api.InitializationStatus>”请帮助我完成此操作。
`using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GoogleMobileAds.Api;
using GoogleMobileAds;
using System;
public class addmanager_script : MonoBehaviour
{
public BannerView bannerview;
public InterstitialAd regularad;
private string appID="ca-app-pub-5133215721502784~7588202759";
private string regularID="ca-app-pub-5133215721502784/3265814366";
// Use this for initialization
void Start ()
{
MobileAds.Initialize (appID);
//RequestAd ();
RequestBanner ();
}
// Update is called once per frame
void Update ()
{
}
public void OnClickShowBanner()
{
this.RequestBanner ();
}
public void OnClickShowAd()
{
this.RequestAd ();
}
private void RequestAd()
{
regularad = new InterstitialAd (regularID);
AdRequest request = new AdRequest.Builder ().Build ();
regularad.LoadAd (request);
}
private void RequestBanner()
{
#if UNITY_ANDROID
string bannerID = "ca-app-pub-5133215721502784/6909545908";
#elif UNITY_IPHONE
string adUnitId = bannerID;
#else
string bannerID ="ca-app-pub-5133215721502784/6909545908";
#endif
bannerview = new BannerView (bannerID, AdSize.Banner, AdPosition.Bottom);
AdRequest request = new AdRequest.Builder ().Build ();
bannerview.LoadAd (request);
bannerview.Show ();
//bannerview.OnAdLoaded += HandleOnAdLoaded;
}
void HandleOnAdLoaded(object a, EventArgs args)
{
print ("loaded");
bannerview.Show ();
}
public void Show()
{
if (regularad.IsLoaded ())
{
regularad.Show ();
}
}
}`
我不明白这个问题的解决方案是什么,因为我是新的编码。
1条答案
按热度按时间krcsximq1#
从docs。
所以问题是你不需要传递任何字符串参数给MobileAds.Initialize,而是需要传递一个delegate/action/callback,它通过参数接收一个
GoogleMobileAds.Api.InitializationStatus
。因此,您可以像上面的示例那样执行此操作,或者类似于: