Hi,
Me and some friends are in the process of making an android game, which we plan to get onto the Google Play store. Therefor we wanted to implement Unity Ads. We need both the simple (Interstitial ads) and the reward ad (videos). We followed the code samples for both and are fairly sure that this is correct. However when they are displayed they are both displayed as video ads, but is this only because we are in test mode, or did we do something wrong. This is tested on a OnePlus 2 and a OnePlus 3.
1: reward ad implementation (Admanager). The showad method is called in an other class.
public class AdManager : MonoBehaviour
{
[SerializeField]
string gameID = "1295866";
void Awake()
{
Advertisement.Initialize(gameID, true);
}
public void ShowAd(string zone = "")
{
#if UNITY_EDITOR
StartCoroutine(WaitForAd());
#endif
if (string.Equals(zone, ""))
zone = null;
ShowOptions options = new ShowOptions();
options.resultCallback = AdCallbackhandler;
if (Advertisement.IsReady(zone))
Advertisement.Show(zone, options);
}
void AdCallbackhandler(ShowResult result)
{
switch (result)
{
case ShowResult.Finished:
// Hardcoded reward, change later when we get more reward ads
GameManager.Instance.Player.GetComponent<CharController>().Revived = true;
GameManager.Instance.Player.GetComponent<CharController>().Halo.SetActive(true);
GameManager.Instance.Player.GetComponent<CharController>().Halo.GetComponent<SpriteRenderer>().sprite = Resources.Load("Invincible", typeof(Sprite)) as Sprite;
Debug.Log("Ad Finished. Rewarding player...");
break;
case ShowResult.Skipped:
GameManager.Instance.Player.GetComponent<CharController>().PlayerDeath();
Debug.Log("Ad skipped. Son, I am dissapointed in you");
break;
case ShowResult.Failed:
GameManager.Instance.Player.GetComponent<CharController>().PlayerDeath();
Debug.Log("I swear this has never happened to me before");
break;
}
Time.timeScale = 1;
}
IEnumerator WaitForAd()
{
float currentTimeScale = Time.timeScale;
Time.timeScale = 0f;
yield return null;
while (Advertisement.isShowing)
yield return null;
Time.timeScale = currentTimeScale;
}
2: simple ad implementation. The adtimer is to delay the showing of the ad, since this code is in the start method of a script on a object in another scene.
if (GameManager.Instance.AdTimer <= 0)
{
if (Advertisement.IsReady())
{
Advertisement.Show();
GameManager.Instance.AdTimer = 300;
}
}
Hope you can help.
Regards,
Jonas