You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Unity AdsManager脚本CS1503错误求助:无法将InterstitialAd转为string

Fix for CS1503: Cannot convert 'InterstitialAd' to 'string'

Hey there, let’s sort out this error you’re running into—it’s a simple mix-up with variable names!

The Root Cause

In your RequestFullScreenAd() method, you accidentally tried to initialize a new InterstitialAd using the fullScreenAd variable (which is already an InterstitialAd object) instead of passing the ad ID string (fullScreenAdID) that the constructor requires. That’s why you’re getting this type mismatch error.

Corrected Code

Here’s the fixed version of your class, with the problematic line updated:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GoogleMobileAds.Api;

public class AdsManager : MonoBehaviour {
    public static AdsManager instance;
    private string appID = "ca-app-pub-3940256099942544~3347511713";
    private BannerView bannerView;
    private string bannerID = "ca-app-pub-3940256099942544/6300978111";
    private InterstitialAd fullScreenAd;
    private string fullScreenAdID = "ca-app-pub-3940256099942544/1033173712";

    private void Awake() {
        if (instance == null) {
            instance = this;
        } else {
            Destroy(this);
        }
    }

    private void Start() {
        RequestFullScreenAd();
    }

    public void RequestBanner() {
        bannerView = new BannerView(bannerID, AdSize.Banner, AdPosition.Bottom);
        AdRequest request = new AdRequest.Builder().Build();
        bannerView.LoadAd(request);
        bannerView.Show();
    }

    public void HideBanner() {
        bannerView.Hide();
    }

    public void RequestFullScreenAd() {
        // Fixed: use the string ad ID instead of the InterstitialAd object
        fullScreenAd = new InterstitialAd(fullScreenAdID);
        AdRequest request = new AdRequest.Builder().Build();
        fullScreenAd.LoadAd(request);
    }

    public void ShowFullScreenAd() {
        if (fullScreenAd.IsLoaded()) {
            fullScreenAd.Show();
        } else {
            Debug.Log("Full Screen Ad Not Loaded");
        }
    }
}

Quick Note

This is a common slip-up when working with ad SDKs—just remember to double-check that you’re passing the correct variable type (string IDs for constructors, object references for other operations) and you’ll avoid this kind of error in the future.

内容的提问来源于stack exchange,提问作者K.Oussama

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 09:12:02