when activating the ad service unity crashes

when i play my game without ads in the editor mode it works fine but when i activate the ad service unity closes.

(i only want it for android)

this is my script
Code

using UnityEngine;
using UnityEngine.Advertisements;

public class ads : MonoBehaviour
{
    public test test;

    private void Start()
    {
        test = test.GetComponent<test>();
    }

    public void ShowRewardedAd()
    {
        if (Advertisement.IsReady("rewardedVideo"))
        {
            var options = new ShowOptions { resultCallback = HandleShowResult };
            Advertisement.Show("rewardedVideo", options);
        }
    }

    private void HandleShowResult(ShowResult result)
    {
        switch (result)
        {
            case ShowResult.Finished:
                Debug.Log("The ad was successfully shown.");
                test.watchedAd();
                break;
            case ShowResult.Skipped:
                Debug.Log("The ad was skipped before reaching the end.");
                break;
            case ShowResult.Failed:
                Debug.LogError("The ad failed to be shown.");
                break;
        }
    }
}

it gives me this error:

Assets/ads.cs(2,19): error CS0234: The type or namespace name `Advertisements' does not exist in the namespace `UnityEngine'. Are you missing an assembly reference?

and this one:

Assets/ads.cs(22,35): error CS0246: The type or namespace name `ShowResult' could not be found. Are you missing an assembly reference?

how can i fix this?!
thanks alot,
Kelvin

This may be better posted in the ads sub forum, but just from some experience, sometimes the built in ads service (under the service tab) is wonky. I had to turn that off and import the one from the unity store. Plus, currently the unity store is further updated (2.1 vs 2.0.something I think).

If you want to use the service tab one, perhaps turning it off and on again will fix this as well.

k i found that somehow my script was making unity crash. i found a better(newer) version of the ads script
but thanks for your help

this is my new code:

using UnityEngine;
#if UNITY_ADS
using UnityEngine.Advertisements; // only compile Ads code on supported platforms
#endif

public class UnityAdsExample : MonoBehaviour
{
    public test test;

    private void Awake()
    {
        test = test.GetComponent<test>();
    }

    public void ShowDefaultAd()
    {
#if UNITY_ADS
        if (!Advertisement.IsReady())
        {
            Debug.Log("Ads not ready for default placement");
            return;
        }

        Advertisement.Show();
#endif
    }

    public void ShowRewardedAd()
    {
        const string RewardedPlacementId = "rewardedVideo";

#if UNITY_ADS
        if (!Advertisement.IsReady(RewardedPlacementId))
        {
            Debug.Log(string.Format("Ads not ready for placement '{0}'", RewardedPlacementId));
            return;
        }

        var options = new ShowOptions { resultCallback = HandleShowResult };
        Advertisement.Show(RewardedPlacementId, options);
#endif
    }

#if UNITY_ADS
    private void HandleShowResult(ShowResult result)
    {
        switch (result)
        {
            case ShowResult.Finished:
                Debug.Log("The ad was successfully shown.");
                test.watchedAd();
                break;
            case ShowResult.Skipped:
                Debug.Log("The ad was skipped before reaching the end.");
                break;
            case ShowResult.Failed:
                Debug.LogError("The ad failed to be shown.");
                break;
        }
    }

#endif
}