Unity Plugin not working

132 views
Skip to first unread message

Frederik Bisp

unread,
Aug 3, 2014, 11:31:33 AM8/3/14
to google-adm...@googlegroups.com
I'm using Unity 4.5, and have a hard time integrating admob into my game. 

The thing is, I can't access it. I can't declare it, call .Show(), .Hide() or anything else. I got this error-message: NullReferenceException: Object reference not set to an instance of an object.

It doesn't make any sense to me. It seems like the variable isn't global in the class. But I can't see why. It isn't a problem with any other variable in class.

It is a big problem, since I can't have the banner at all.

What can I do to fix it?

My code: 

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

public class GameManager : MonoBehaviour {
public BannerView PauseView;

void Start(){
// Create a 320x50 banner at the top of the screen.
BannerView PauseView = new BannerView( "Hidden for you guys", AdSize.Banner, AdPosition.Top);
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build(); 
// Load the banner with the request.
PauseView.LoadAd(request);
}
}


Eric Leichtenschlag

unread,
Aug 4, 2014, 5:41:42 PM8/4/14
to google-adm...@googlegroups.com
Instead of:

BannerView PauseView = new BannerView( "Hidden for you guys", AdSize.Banner, AdPosition.Top); 

use:

PauseView = new BannerView( "Hidden for you guys", AdSize.Banner, AdPosition.Top);

Right now you're creating a local PauseView instance that goes out of scope when you leave Start(), and are never actually setting the class field.

Thanks,
Eric
Reply all
Reply to author
Forward
0 new messages