Hello!
I am creating a game with ads, and I’ve created rewardedVideo ads before in previous games, but I don’t know what’s going on now since I can’t get it to work. I haven’t made a game in a while, so it could just be me, or maybe something changed since the last time I’ve done it.
I appreciate all the help in advance!
Thank you!
Here’s my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Advertisements;
using UnityEngine.SceneManagement;
public class Advertisements : MonoBehaviour
{
string appleGameId = "[my game id for apple]";
string androidGameId = "[my game id for android]";
bool testMode = true;
bool releaseMode = false;
string skippableAd = "video";
string rewardedAd = "rewardedVideo";
public GameObject comError;
public GameObject endScreen, mainScreen, game, player;
public PlayerMovement PLAYER;
void Start()
{
Advertisement.Initialize(appleGameId, testMode);
//Advertisement.AddListener(this);
// TODO: REPLACE WITH CORRECT GAMEID AS WELL AS RELEASEMODE when RELEASING
}
public void ShowSkippableAd()
{
// Check if UnityAds ready before calling Show method:
if (Advertisement.IsReady())
{
Advertisement.Show(skippableAd);
// Replace mySurfacingId with the ID of the placements you wish to display as shown in your Unity Dashboard.
}
else
{
Debug.Log("Skippable ad not ready at the moment! Please try again later!");
}
}
public void ShowRewardedAd()
{
// Check if UnityAds ready before calling Show method:
if (Advertisement.IsReady())
{
Advertisement.Show(rewardedAd);
// Replace mySurfacingId with the ID of the placements you wish to display as shown in your Unity Dashboard.
print("Ad Shown!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
else
{
Debug.LogWarning("Rewarded ad not ready at the moment! Please try again later!");
comError.SetActive(true);
}
}
public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
{
// Define conditional logic for each ad completion status:
if (showResult == ShowResult.Finished)
{
// Reward the user for watching the ad to completion.
print("TESTWORKED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); // This line never gets executed.
onFinishedAd();
}
else if (showResult == ShowResult.Skipped)
{
// Do not reward the user for skipping the ad.
SceneManager.LoadScene(0);
}
else if (showResult == ShowResult.Failed)
{
Debug.LogWarning("The ad did not finish due to an error.");
comError.SetActive(true);
}
void onFinishedAd()
{
endScreen.SetActive(false);
mainScreen.SetActive(true);
game.SetActive(true);
player.GetComponent<Rigidbody>().isKinematic = true;
player.transform.position = new Vector3(0, 5, 0);
player.GetComponent<BoxCollider>().enabled = true;
PLAYER.sc.enabled = true;
PLAYER.countScore = true;
PLAYER.mesh.enabled = true;
PLAYER.hasFallen = false;
player.GetComponent<Rigidbody>().isKinematic = false;
// TODO: let user continue leaving current score
}
}
}