using UnityEngine;
using System.Collections;
using UnityEngine.Advertisements;
public class AdStuff : MonoBehaviour {
void Awake() {
if (Advertisement.isSupported) {
Advertisement.allowPrecache = true;
Advertisement.Initialize ("22117",true);
} else {
Debug.Log("Platform not supported");
}
}
public void ButtonClick(){
PlayVideo ();
}
void PlayVideo(){
Advertisement.Show (@"defaultVideoAndPictureZone", new ShowOptions {
pause = false,
// Handle the various result callback states.
resultCallback = result => {
switch (result)
{
case ShowResult.Finished:
PlayerPrefs.SetInt ("Points", PlayerPrefs.GetInt ("Points") + 125);
break;
case ShowResult.Skipped:
///Your code if it skipped
break;
case ShowResult.Failed:
///Your code if it fails
break;
}
}
});
}
}
The following is my code. How come I have to click again to get the ad to load. For example the ad takes like 3 seconds to initialize in the editor for some reason, not quite sure why seeing as it’s on test mode. But if I clicked it earlier nothing happens, it doesn’t load after its ready you have to click the button again. I need it so when ButtonClick() is called it will load that ad, not so I have to click it a few times. Is this really obvious? What am I missing?