I want a RewardAd in my game. When you watch video you get +10 score to your current score not your high-score.
You have a 45 high-score and you are now at 37, so you watch video for +10 score and you have 47 high-score it's fine. But if you do it again, the video gives you +20 score?! And the following time +30 and so on.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GoogleMobileAds.Api;
using System.Threading;
public class RewardAd : MonoBehaviour {
public int highscore;
public int score;
public static GameObject drawscore_obj;
public RewardBasedVideoAd rewardBasedVideo = null;
public string adUnitId;
void Start()
{
rewardBasedVideo = null;
GetComponent<SpriteRenderer> ().enabled = false;
//highscore = PlayerPrefs.GetInt ("highscore");
adUnitId = "ca-app-pub-2879768424205988/1590886374";
rewardBasedVideo = RewardBasedVideoAd.Instance;
AdRequest request = new AdRequest.Builder().Build();
rewardBasedVideo.LoadAd(request, adUnitId);
rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded;
}
void Update()
{
if (GameOverScript.GameOver)
{
GetComponent<SpriteRenderer> ().enabled = true;
}
}
void OnMouseDown()
{
showAdd(rewardBasedVideo);
}
private void showAdd(RewardBasedVideoAd rewardBasedVideo)
{
if (rewardBasedVideo.IsLoaded())
{
if (GameOverScript.GameOver)
{
rewardBasedVideo.Show ();
}
}
}
public void HandleRewardBasedVideoRewarded(object sender, Reward args)
{
highscore = PlayerPrefs.GetInt ("highscore");
if ((Controll.points + 10) > highscore)
{
Controll.points += 10;
if(Controll.points > highscore)
{
PlayerPrefs.SetInt ("highscore", highscore);
}
}
}
}