Я сделал простую 2d-игру с небольшим количеством объектов, и она отлично работает на моем Xperia ST. Но когда я интегрировал admobs, чтобы показывать как баннер, так и межстраничные объявления в игре по экрану, геймплей отстает и замедляется.Простая игра Unity становится медленной после интеграции admob
Мой код AdMob и как они используются, приводится ниже
Игрок сценария
using UnityEngine;
using System.Collections;
public class PlayerMotion : MonoBehaviour {
public GameObject gameOverTag,spawner,camera,adObject;
SpawnScript spawnScript;
GoogleMobileAdsDemoScript adScript;
// Use this for initialization
void Awake() {
adObject=GameObject.Find("Ads");// ads is a game object which was kept from main menu screen
}
void Start() {
spawnScript= spawner.GetComponent<SpawnScript>();
//adScript=camera.GetComponent<GoogleMobileAdsDemoScript>();//GoogleMobileAdsDemoScript is the ad script
adScript=adObject.GetComponent<GoogleMobileAdsDemoScript>();
adScript.hideBanner();
adScript.requestInterstitial();
}
// Update is called once per frame
void Update() {
//some more code
}
}
public void Movement()
{
//some code
}
void OnCollisionEnter2D(Collision2D other){
//some code
}
void OnGUI(){
if (gameOver) {
if((adScript.timesInterstitalRequested)%5==0)
adScript.ShowInterstitial();
else
adScript.showBanner();
//some more code
}
}
}
Вот GoogleMobileAdsDemoScript код
using System;
using UnityEngine;
using GoogleMobileAds;
using GoogleMobileAds.Api;
// Example script showing how to invoke the Google Mobile Ads Unity plugin.
public class GoogleMobileAdsDemoScript : MonoBehaviour
{
private BannerView bannerView;
private InterstitialAd interstitial;
public int timesBannerRequested=0,timesInterstitalRequested=0;
void Awake() {
DontDestroyOnLoad (this);
}
void Start()
{
}
public void requestBanner(){
//Requesting BannerView
timesBannerRequested = timesBannerRequested + 1;
#if UNITY_EDITOR
string adUnitId = "ca-app-pub-asdas";
#elif UNITY_ANDROID
string adUnitId = "ca-app-pub-asd";
#elif UNITY_IPHONE
string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE";
#else
string adUnitId = "unexpected_platform";
#endif
bannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Bottom);
AdRequest requestBanner = new AdRequest.Builder().Build();
bannerView.LoadAd(requestBanner);
//bannerView.Hide();
}
public void requestInterstitial(){
timesInterstitalRequested = timesInterstitalRequested + 1;
//Requesting Interstitial
#if UNITY_EDITOR
string adUnitIdInterstitial = "ca-app-pub-dfada";
#elif UNITY_ANDROID
string adUnitIdInterstitial = "ca-app-pub-asdas";
#elif UNITY_IPHONE
string adUnitIdInterstitial = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";
#else
string adUnitIdInterstitial = "unexpected_platform";
#endif
interstitial = new InterstitialAd(adUnitIdInterstitial);
AdRequest requestInterstitial = new AdRequest.Builder().Build();
interstitial.LoadAd(requestInterstitial);
}
public void showBanner()
{
bannerView.Show();
}
public void destroyBanner()
{
bannerView.Destroy();
}
public void hideBanner()
{
bannerView.Hide();
}
public void ShowInterstitial()
{
if (interstitial.IsLoaded())
{
interstitial.Show();
}
else
{
print("Interstitial is not ready yet.");
}
}
}
Из опыта я нахожу, что хорошо отформатированный код получает наилучшую помощь здесь, на SO. – FunctionR
@FunctionR Я не понял, что именно вы имели в виду –