我是团结的新手;我只想在代码源上测试某些东西,所以我聘请了一名自由职业者来实施广告。广告在玩家输掉3次之后显示,并且在暂停菜单中,我想在每次玩家输掉时进行显示,请您告诉我如何做到这一点,并要具体,因为我是这一切的新手
这是我的广告控件
非常感谢您的帮助
最佳成绩
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class UIManager : MonoBehaviour
{
public GameObject maskPanel, pausePanel, retrievePanel, gameOverPanel, levelClearPanel;
public Text timerText, coinValueText;
public float timeMax;
private float currentTimer;
public GameObject[] heart;
public int coinToRetrieve;
public Sprite[] starSpr;
public Image starImg;
public Text coinResultValue;
void Awake ()
{
GameManager._UIManager = this;
}
// Use this for initialization
void Start ()
{
currentTimer = timeMax;
coinValueText.text = GameManager._gotCoin.ToString ();
AudioManager.Instance.mainMusic.mute = false;
}
// Update is called once per frame
void Update ()
{
if (Mathf.CeilToInt (currentTimer) > 0) {
currentTimer -= Time.deltaTime;
timerText.text = Mathf.CeilToInt (currentTimer).ToString ();
}
if (Mathf.CeilToInt (currentTimer) == 0) {
if (!GameManager.isGameOver) {
AudioManager.Instance.PlayOutOfTime ();
GameManager.isGameOver = true;
StartCoroutine (GameOver ());
}
}
coinValueText.text = GameManager._gotCoin.ToString ();
}
public void Pause ()
{
AdsControl.Instance.showAds ();
Time.timeScale = 0.0f;
maskPanel.SetActive (true);
pausePanel.SetActive (true);
}
public void Resume ()
{
Time.timeScale = 1.0f;
maskPanel.SetActive (false);
pausePanel.SetActive (false);
}
public void Replay ()
{
Time.timeScale = 1.0f;
Application.LoadLevel ("Game");
}
public void Back ()
{
Time.timeScale = 1.0f;
Application.LoadLevel ("Home");
}
public IEnumerator GameOver ()
{
yield return new WaitForSeconds (1.0f);
AdsControl.Instance.showAds ();
//int _coin = PlayerPrefs.GetInt ("Coin");
if (GameManager._gotCoin >= coinToRetrieve) {
ShowRetrieve ();
} else {
ShowGameOver ();
}
}
void ShowRetrieve ()
{
Time.timeScale = 0.0f;
maskPanel.SetActive (true);
retrievePanel.SetActive (true);
}
public void ShowGameOver ()
{
Time.timeScale = 0.0f;
maskPanel.SetActive (true);
retrievePanel.SetActive (false);
gameOverPanel.SetActive (true);
PlayerPrefs.SetInt ("Coin", GameManager._gotCoin);
}
public void LevelClear ()
{
StartCoroutine (LevelClearIE ());
}
IEnumerator LevelClearIE ()
{
yield return new WaitForSeconds (1.0f);
Time.timeScale = 0.0f;
maskPanel.SetActive (true);
levelClearPanel.SetActive (true);
int star = 0;
if (currentTimer >= 0.75f * timeMax) {
star = 3;
starImg.sprite = starSpr [2];
} else if (currentTimer >= 0.5f * timeMax && currentTimer < 0.75f * timeMax) {
star = 2;
starImg.sprite = starSpr [1];
} else {
star = 1;
starImg.sprite = starSpr [0];
}
PlayerPrefs.SetInt ("Star" + PlayerPrefs.GetInt ("CurrentLevel").ToString (), star);
int currentLevel = PlayerPrefs.GetInt ("CurrentLevel");
int levelActive = PlayerPrefs.GetInt ("Level");
if (currentLevel == levelActive) {
currentLevel++;
PlayerPrefs.SetInt ("Level", currentLevel);
PlayerPrefs.SetInt ("CurrentLevel", currentLevel);
}
PlayerPrefs.SetInt ("Coin", GameManager._gotCoin);
coinResultValue.text = GameManager._gotCoin.ToString ();
}
public void Retrieve ()
{
AudioManager.Instance.mainMusic.mute = false;
GameManager._heart++;
SetHeart (GameManager._heart);
GameManager._gotCoin -= coinToRetrieve;
Time.timeScale = 1.0f;
maskPanel.SetActive (false);
retrievePanel.SetActive (false);
LevelManager.Instance.SpawnPlayer ();
}
public void QuitToHome ()
{
Time.timeScale = 1.0f;
Application.LoadLevel ("Home");
}
public void NextLevel()
{
Application.LoadLevel ("Game");
}
public void SetHeart (int _heart)
{
if (_heart == 3) {
heart [2].SetActive (true);
heart [1].SetActive (true);
heart [0].SetActive (true);
} else if (_heart == 2) {
heart [2].SetActive (false);
heart [1].SetActive (true);
heart [0].SetActive (true);
} else if (_heart == 1) {
heart [2].SetActive (false);
heart [1].SetActive (false);
heart [0].SetActive (true);
} else {
heart [2].SetActive (false);
heart [1].SetActive (false);
heart [0].SetActive (false);
}
}
}
答案 0 :(得分:0)
玩家松开三颗心之后,看起来像是在显示广告。在上述脚本中,GameManager脚本当前正在设置玩家收到的心数。您可以通过更改...来确认这一点。
SetHeart (GameManager._heart);
...在以上脚本中为:
SetHeart (1);
我假设GameManager脚本将心数设置为3。这只是一个临时解决方案,用于测试您的广告在一次游戏丢失后是否会展示。
您可以更新问题以包含GameManager脚本吗?您应该可以通过在项目的脚本顶部附近找到public class GameManager
来查找脚本来找到脚本。
答案 1 :(得分:-1)
您可以创建函数ShowAds()
如果玩家输了,则显示广告。
public class PlayerScript : MonoBehaviour
{
//The update frame
private void Update()
{
//If player has lost
if(heart.count.Equals(0))
{
ShowAd();
}
}
//A funtion which shows ad
private void ShowAd()
{
//Whichever ad provider you use; use the funtion
}
}