using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using UnityEngine.EventSystems;
using UnityEngine.Advertisements;
public class GameController : MonoBehaviour, IUnityAdsListener
{
void Awake()
{
Advertisement.AddListener(this);
}
public static void UnityAdsInitialise() <CALLED WHEN GAMES STARTS
{
// Debug.Log(“Initialised”);
string gameId = “-------”; //Play Store
bool testMode = true; //Set to False once live
Advertisement.Initialize(gameId, testMode);
}
public void LuckyDipPanelPressed()
{
if (luckyDipPlayOnce)
{
luckyDipPanel.SetActive(false);
luckyDipPanelShadow.SetActive(false);
return;
}
Debug.Log(“2” + luckyDipPanel); <<< THE VALUE HAS VALiD CONTENT
if (Advertisement.IsReady(“rewardedVideo”))
{
Advertisement.Show(“rewardedVideo”); >>>>GOES TO LISTENER
}
else
{
recieveText.text = “GIFT Unavailable”;
luckyDipPanel.transform.Find(“NowLetsDriveText”).gameObject.SetActive(true);
luckyDipPlayOnce = true;
}
}
// Implement IUnityAdsListener interface methods:
public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
{
if (placementId == “rewardedVideo”)
// Define conditional logic for each ad completion status:
if ((showResult == ShowResult.Finished) && !luckyDipPlayOnce)
{
//Debug.Log(“4”+luckyDipPanel); Would throw up ERROR - Gameobject Destroyed
// Reward the user for watching the ad to completion.
luckyDipPanel.transform.Find(“NowLetsDriveText”).gameObject.SetActive(true);
recieveText.text = “You have recieved the following GIFT”;
int randomGift = Random.Range(0, 3);
if (randomGift == 0)
//helmet
{
SoundEffectManager.PlaySound(“HelmetPickUp”);
joeyHelmet.SetActive(true);
helmetWorn = true;
helmetDamage = 0;
DisplayHelmetDamage();
miniHelmetDamageText.gameObject.SetActive(true);
miniHelmetDamageHeader.gameObject.SetActive(true);
helmetExists = true;
carController.miniHelmet.gameObject.SetActive(true);
luckyDipPanel.transform.Find(“coin”).gameObject.SetActive(false);
luckyDipPanel.transform.Find(“stopwatch”).gameObject.SetActive(false);
luckyDipPanel.transform.Find(“RewardText3”).gameObject.SetActive(false);
luckyDipPanel.transform.Find(“RewardText5”).gameObject.SetActive(false);
luckyDipPanel.transform.Find(“RewardText4”).transform.position += new Vector3(5, 0, 0);
luckyDipPanel.transform.Find(“joeyhelmet”).transform.position += new Vector3(5, 0, 0);
}
//Extra Time
if (randomGift == 1)
{
SoundEffectManager.PlaySound(“BonusStandard”);
IncreaseTime(60);
luckyDipPanel.transform.Find(“coin”).gameObject.SetActive(false);
luckyDipPanel.transform.Find(“RewardText5”).gameObject.SetActive(false);
luckyDipPanel.transform.Find(“RewardText4”).gameObject.SetActive(false);
luckyDipPanel.transform.Find(“joeyhelmet”).gameObject.SetActive(false);
}
//Extra Points
if (randomGift == 2)
{
SoundEffectManager.PlaySound(“CoinPickUp”);
int randomCash = Random.Range(4, 11);
score += randomCash * 5000;
newText = luckyDipPanel.transform.Find(“RewardText5”).GetComponent();
newText.text = “£” + (randomCash * 5).ToString() + “,000”;
UpdateScoreText();
luckyDipPanel.transform.Find(“coin”).transform.position -= new Vector3(5, 0, 0);
luckyDipPanel.transform.Find(“stopwatch”).gameObject.SetActive(false);
luckyDipPanel.transform.Find(“RewardText3”).gameObject.SetActive(false);
luckyDipPanel.transform.Find(“RewardText5”).transform.position -= new Vector3(5, 0, 0);
luckyDipPanel.transform.Find(“RewardText4”).gameObject.SetActive(false);
luckyDipPanel.transform.Find(“joeyhelmet”).gameObject.SetActive(false);
}
}
else if (showResult == ShowResult.Skipped)
{
// Do not reward the user for skipping the ad.
recieveText.text = “GIFT denied”;
Debug.Log(“The ad was skipped before reaching the end.”);
}
else if (showResult == ShowResult.Failed)
{
recieveText.text = “GIFT Unavailable”;
Debug.Log(“The ad failed to be shown.”);
}
luckyDipPlayOnce = true;
}
public void OnUnityAdsReady(string placementId)
{
Debug.Log(“Advert Ready”); <<<THIS NEVER DISPLAYS
}
public void OnUnityAdsDidError(string message)
{
// Log the error.
}
public void OnUnityAdsDidStart(string placementId)
{
// Optional actions to take when the end-users triggers an ad.
}