So I am trying to use Unity Ads with javascript, but each time I try to click on the button it come up with:
"NullReferenceException: Object reference not set to an instance of an object
AdButton.OnMouseDown () (at Assets/AdButton.js:22)
UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32) "
Here is the code that I am using, any help would be greatly appreciated!
#pragma strict
var ad : UnityEngine.Advertisements.Advertisement;
function HandleShowResult (result: UnityEngine.Advertisements.ShowResult) {
switch (result) {
case UnityEngine.Advertisements.ShowResult.Finished :
Debug.Log("The ad was successfully shown.");
break;
case UnityEngine.Advertisements.ShowResult.Skipped :
Debug.Log("The ad was skipped");
break;
case UnityEngine.Advertisements.ShowResult.Failed :
Debug.LogError("The ad failed to be shown.");
break;
}
}
function OnMouseDown () {
if (ad.IsReady("rewardedVideo")) {
var options : UnityEngine.Advertisements.ShowOptions;
options.resultCallback = HandleShowResult;
ad.Show("rewardedVideo", options);
}
}
↧