我想在我的游戏中加入 RewardAd。当您观看视频时,您会得到 +10 分,而不是您的高分。
你有 45 的高分,而你现在是 37,所以你看 +10 分的视频,你有 47 的高分,这很好。但是如果你再做一次,视频会给你+20分?!以及接下来的时间+30等等。
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);
}
}
}
}