Adding iAd in your App from Unity3d

Adding iAd in your App from Unity3d

Advertisemen

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_IPHONE
    private ADBannerView banner;
    // Use this for initialization
    void Start () 

      {
        if(dontDestroy)

           {
             GameObject.DontDestroyOnLoad(gameObject);
           }
        
        banner = new ADBannerView(ADBannerView.Type.Banner

              showOnTopADBannerView.Layout.Top : ADBannerView.Layout.Bottom);

        
ADBannerView.onBannerWasLoaded += onBannerLoaded;
      }
    
    // onBannerLoaded is declared here
    void onBannerLoaded () 

      {
        banner.visible = true;
      }
#endif
}

For Javascript :

#pragma strict
"color: #f7f7f1;">    var showOnTop boolean true;
    var dontDestroy : boolean = false;

#if UNITY_IPHONE
    private banner : ADBannerView;
    // Use this for initialization
    function Start () 
     {
        if(dontDestroy)

          {
            GameObject.DontDestroyOnLoad(gameObject);
          }
        
        banner = new ADBannerView(ADBannerView.Type.Banner

              showOnTopADBannerView.Layout.Top ADBannerView.Layout.Bottom);

        ADBannerView.onBannerWasLoaded += onBannerLoaded;
     }
    
    // Update is called once per frame
    function 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.


Advertisemen

Disclaimer: Gambar, artikel ataupun video yang ada di web ini terkadang berasal dari berbagai sumber media lain. Hak Cipta sepenuhnya dipegang oleh sumber tersebut. Jika ada masalah terkait hal ini, Anda dapat menghubungi kami disini.

Tidak ada komentar:

Posting Komentar

© Copyright 2017 Tutorial Unity 3D