Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
using UnityEngine;
using System.Collections;

public class Menu : MonoBehaviour {

private const string AD_UNIT_ID = "YOUR_AD_UNIT_ID";
private const string INTERSTITIAL_ID = "YOUR_AD_UNIT_ID";

private static Vector2 BUTTON_SIZE = new Vector2(100, 50);

private Rect buttonPositionShowAds;
private Rect buttonPositionHideAds;
private Rect buttonPositionShowInterstitial;


void Start() {


buttonPositionShowAds = new Rect(
(Screen.width - BUTTON_SIZE.x) / 2,
(Screen.height - BUTTON_SIZE.y) / 2,
BUTTON_SIZE.x, BUTTON_SIZE.y);

buttonPositionHideAds = new Rect(
buttonPositionShowAds.x, buttonPositionShowAds.y + BUTTON_SIZE.y * 3 / 2,
buttonPositionShowAds.width, buttonPositionShowAds.height);

buttonPositionShowInterstitial = new Rect(
buttonPositionHideAds.x, buttonPositionHideAds.y + BUTTON_SIZE.y * 3 / 2,
buttonPositionHideAds.width, buttonPositionHideAds.height);
}

void OnEnable() {

}

void OnDisable() {

}

void HandleAdLoaded() {
#if !UNITY_EDITOR
admob.ShowBanner();
#endif
}

void HandleInterstitialLoaded() {
#if !UNITY_EDITOR
admob.ShowInterstitial();
#endif
}

void OnGUI() {
if (GUI.Button(buttonPositionShowAds, "Show Ads")) {
#if !UNITY_EDITOR
admob.ShowBanner();
#endif
}

if (GUI.Button(buttonPositionHideAds, "Hide Ads")) {
#if !UNITY_EDITOR
admob.HideBanner();
#endif
}

if (GUI.Button(buttonPositionShowInterstitial, "Show Interstitial")) {
#if !UNITY_EDITOR
admob.RequestInterstitial();
#endif
}
}
}

What I have tried:

i tried to write admob global.
Posted
Updated 2-Oct-17 23:11pm

1 solution

You don't declare admob at all - all references to it in that code are uses of an instance, which you have not declared.
You need to declare it at the start of your class definition, just like you do
C#
private Rect buttonPositionShowAds;
And create an instance of the class for it to reference!
 
Share this answer
 
Comments
swamy456 3-Oct-17 11:24am    
thank you
OriginalGriff 3-Oct-17 11:27am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900