Hey everyone !
I’ve just integrated Everplay GameAds into my Unity Android game, however when I change scene and go back to the first scene, and click “show ad”, the callback of a completed ad isn’t fired, so the user has saw the ad, but they don’t get rewarded for doing so, as they should.
I’ll provide the modified UnityAdsTest.cs, it’s the basic code coming with the plugin, which I modified to my game.
I think this is a delegate related issue, that’s why I’m posting this here. I’ve also emailed Everplay, if I’ll get an answer I’ll post it.
I want you guys to focus on “UnityAdsVideoCompleted” delegate, that’s the one that should be fired if someone finishes an ad.
But I’ll provide the full script, I appreciate any help !
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class UnityAdsTest : MonoBehaviour
{
private bool _campaignsAvailable = false;
void Awake()
{
UnityAds.setCampaignsAvailableDelegate(UnityAdsCampaignsAvailable);
UnityAds.setHideDelegate(UnityAdsHide);
UnityAds.setShowDelegate(UnityAdsShow);
UnityAds.setCampaignsFetchFailedDelegate(UnityAdsCampaignsFetchFailed);
UnityAds.setVideoCompletedDelegate(UnityAdsVideoCompleted);
UnityAds.setVideoStartedDelegate(UnityAdsVideoStarted);
DontDestroyOnLoad(this.gameObject);
}
void Update()
{
GameObject.Find("CoinText").guiText.text = GoldCoinPowerUpScript.goldCoins.ToString();
PlayerPrefs.SetInt ("GoldCoins", GoldCoinPowerUpScript.goldCoins);
}
/*void Update()
{
GameObject.Find("CoinLabel").GetComponent
}*/
public void UnityAdsCampaignsAvailable()
{
Debug.Log ("ADS: CAMPAIGNS READY!");
_campaignsAvailable = true;
}
public void UnityAdsCampaignsFetchFailed()
{
Debug.Log ("ADS: CAMPAIGNS FETCH FAILED!");
}
public void UnityAdsShow()
{
Debug.Log ("ADS: SHOW");
}
public void UnityAdsHide()
{
Debug.Log ("ADS: HIDE");
}
public void UnityAdsVideoCompleted(string rewardItemKey, bool skipped)
{
Debug.Log ("ADS: VIDEO COMPLETE : " + rewardItemKey + " - " + skipped);
GoldCoinPowerUpScript.goldCoins += 100;
//PlayerPrefs.SetInt ("GoldCoins", GoldCoinPowerUpScript.goldCoins);
Application.Quit (); //Only for testing
//GameObject.Find("CoinText").guiText.text = GoldCoinPowerUpScript.goldCoins.ToString();
//GameObject.Find ("AdHandler").GetComponent<AdHandlerScript>().AddGold();
//Application.Quit();
}
public void UnityAdsVideoStarted()
{
Debug.Log ("ADS: VIDEO STARTED!");
}
public void UpdateGold(int goldCoins)
{
}
/*void OnGUI ()
{
if (GUI.Button (new Rect (10, 10, 150, 50), _campaignsAvailable ? "Open Zone 1" : "Waiting...")) {
if (_campaignsAvailable) {
UnityAdsExternal.Log("Open Zone 1 -button clicked");
UnityAds.show("16-default");
}
}
if (GUI.Button (new Rect (10, 70, 150, 50), _campaignsAvailable ? "Open Zone 2" : "Waiting...")) {
if(_campaignsAvailable) {
UnityAdsExternal.Log ("Open Zone 2 -button clicked");
UnityAds.show("16-default", "ship", new Dictionary<string, string>{
{"openAnimated", "true"},
{"noOfferScreen", "true"},
{"sid", "testiSid"},
{"muteVideoSounds", "true"},
{"useDeviceOrientationForVideo", "true"}
});
}
}
}*/
}
Thanks !