Have to click a few times to get an ad loaded

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?

One thing that you are missing is the IsReady check.

if( Advertisement.isReady()){            
// Show with default zone, pause engine and print result to debug log            
Advertisement.Show(null, new ShowOptions {pause = true, resultCallback = result => {
Debug.Log(result.ToString()); }});        
}

Also, make sure to use code blocks to make code easier to read.

Thank-you but that doesn’t change that it isn’t loading at first and you must click it a few times. Would the best solution be to enable a boolean with the button to check if the ad has loaded through the update function then launch the ad once it is ready? I assumed there would be a better way but I guess not, thanks a ton for the help!

In the documentation, they have the button only enable once isReady returns true.

https://unityads.unity3d.com/help/Documentation%20for%20Publishers/Integration-Guide-for-Unity-Asset-Store