本文主要是介绍Adding iAd in your App from Unity3d,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
In this chapter, let’s take a look in how to add iAd in your app from Unity3d. It is very simple to do. Let’s take a look.
First, create an empty game object in your scene and name it whatever makes you easy to remember, I am going to name it iAd [GameObject > Create Empty].
Now, create one C# script and name it iAd as well and then start editing by typing the followings -
For C# :
using UnityEngine;
using System.Collections;public class iAd : MonoBehaviour {public bool showOnTop = true;public bool dontDestroy = false;#if UNITY_IPHONEprivate ADBannerView banner;// Use this for initializationvoid Start () {if(dontDestroy){GameObject.DontDestroyOnLoad(gameObject);}banner = new ADBannerView(ADBannerView.Type.Banner, showOnTop? ADBannerView.Layout.Top : ADBannerView.Layout.Bottom);ADBannerView.onBannerWasLoaded += onBannerLoaded;}// onBannerLoaded is declared herevoid onBannerLoaded () {banner.visible = true;}
#endif
}
For Javascript :
#pragma strictvar showOnTop : boolean = true;var dontDestroy : boolean = false;#if UNITY_IPHONEprivate banner : ADBannerView;// Use this for initializationfunction Start () {if(dontDestroy){GameObject.DontDestroyOnLoad(gameObject);}banner = new ADBannerView(ADBannerView.Type.Banner, showOnTop? ADBannerView.Layout.Top : ADBannerView.Layout.Bottom);ADBannerView.onBannerWasLoaded += onBannerLoaded;}// Update is called once per framefunction onBannerLoaded () {banner.visible = true;}
#endif
Make sure you attached it with iAd Empty Game Object. Thats all you need to do.
You won’t be able to see iAd demo in unity3d editor so go ahead and Build and Run it. File > Build Settings > Build and Run, for the platform make sure, you have selected iOS, very important.
If just in case, Build and Run doesn’t work for you, don’t panic. Go to project file where you saved it and double click Xcode project file then build and run from there
. So now, you should see this.
This chapter meant to be short unity tutorial so If you have any problems understanding this chapter, just leave the comment below, I will try to help you guys as soon as possible.
If you like this tutorial and want me to make more in future, please hit like.
来源:Aarlangdi Tutorials for Developers
这篇关于Adding iAd in your App from Unity3d的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!