I have two scripts one whith the name “coin manager” and the others for the ads and i want to make after the player wach the ad tou increase the amound of coins.
Here Is My Two Scripts:
Ads-----------------------------------------------
using UnityEngine;
using UnityEngine.Advertisements;
using System.Collections;
public class ADS : MonoBehaviour
{
void Awake()
{
if (Advertisement.isSupported)
{
if(Application.platform == RuntimePlatform.Android)
{
Advertisement.Initialize(“1201734”, false);
}
}
}
public void ShowAd()
{
if (Advertisement.IsReady())
{
Advertisement.Show(“rewardedVideo”, new ShowOptions() {resultCallback = HandleAdResult});
}
}
private void HandleAdResult(ShowResult result)
{
switch (result)
{
case ShowResult.Finished:
Debug.Log(“Player Gain +50 Coins”); //Here the Reward!!!
break;
case ShowResult.Skipped:
Debug.Log(“Player Skipped The AD”);
break;
case ShowResult.Failed:
Debug.Log(“Player Failed To Launch The AD Unit”);
break;
}
}
}
Coin Manager------------------------
using UnityEngine;
using System;
using System.Collections;
public class CoinManager : MonoBehaviour
{
public static CoinManager Instance;
public int Coins { get; private set; }
public static event Action CoinsUpdated = delegate {};
[SerializeField]
int INITIAL_COINS = 100;
const string COINS = “COINS”; // key name to store high score in PlayerPrefs
void Awake()
{
if (Instance)
{
DestroyImmediate(gameObject);
}
else
{
Instance = this;
DontDestroyOnLoad(gameObject);
}
}
void Start()
{
Reset();
}
public void Reset()
{
// Initialize coins
Coins = PlayerPrefs.GetInt(COINS, INITIAL_COINS);
}
public void AddCoins(int amount)
{
Coins += amount;
// Store new coin value
PlayerPrefs.SetInt(COINS, Coins);
// Fire event
CoinsUpdated(Coins);
}
public void RemoveCoins(int amount)
{
Coins -= amount;
// Store new coin value
PlayerPrefs.SetInt(COINS, Coins);
// Fire event
CoinsUpdated(Coins);
}
}
2867550–210042–CoinManager.cs (1.16 KB)
2867550–210043–ADS.cs (1.01 KB)