Unity Ads to display after a number of plays
in order to display ads after a number of plays what C# code should I write for unity ads? I would like for an ad to be displayed after every 7 plays. Thank you :)
int playAfter;
if (playerdied or something){
playAfter +=1;
if(playAfter == 7){
//play ad
playAfter = 0;
}
}
but if you load the scene each time player die or however you cont number of plays every thing will start over . if so you have to attach the script to game object that wont be destroyed . let me so then i will tell you how .
this is where I tried the code but I get error the way I tried...I'm really poor to develop even the simplest thing seems too difficult.. What exactly should I do here?
void GameWin()
{
//Display the GameWin Screen.
pnlWin.SetActive (true);
//Hide the Playing screen.
PnlPlaying.SetActive(false);
}
Answer by Ali-hatem · Apr 10, 2016 at 05:40 PM
1- make an empty Game Object & attach this script to it :
public class Data : MonoBehaviour{
public static Data dat;
public int counter = 0;
void Awake ()
{
if (dat == null)
{
DontDestroyOnLoad(gameObject);
dat = this;
}
else if (dat != this)
{
Destroy(gameObject);
}
}
}
now from your script that include GameWin function :
void Start(){
pnlWin.gameObject.SetActive (false);
PnlPlaying.gameObject.SetActive(false);
}
void GameWin()
{
Data.dat.counter += 1;
if(Data.dat.counter == 7){
// play ad
Data.dat.counter = 0 ;
}
else if(detect if win by your way){
pnlWin.gameObject.SetActive (true);
}
else if(detect if lose by your way){
PnlPlaying.gameObject.SetActive(true);
}
}
Your answer
Follow this Question
Related Questions
Scripting errors in Unity Ads Import 1 Answer
Unity Ads rewarded video no result, Android 1 Answer
Unity Ads only showing Test Ads 0 Answers
ad audio callback help pleeeeeeease!!! 0 Answers
Unity Ads Callback Problem,Unity ads callback problem 5 Answers