Sign up Calendar Latest Topics
 
 
 


Reply
  Author   Comment  
James

Junior Member
Registered:
Posts: 29
Reply with quote  #1 

Hey guys

I have a problem (i had it with applovin ads too and i have no idea how to fix it)


so when the player lose i want to call a chartboost add so i did:

if(GameOver.active == true)

{

if(Random.Range(1,100) >70)

{

showadd = true;

}

if(showadd == true)

{

if(Random.Range(1,100) >70)

{

CBBinding.showInterstitial(null);

CBBinding.showInterstitial("Default");

stopshow();

}

}

 

}

(THIS IS ON FUNCTION UPDATE)

And now at the momment you lose and the game over is showing the chartboost spams because is calling an ad every frame
HOW DO I FIX IT?

Thanks for reading!

0
Roman

Avatar / Picture

Senior Member
Registered:
Posts: 304
Reply with quote  #2 
Create a function that you will call.(add showinterstitial in it) At the end of this function go to gameover scene. That way update function won't be repeated 2 times.

I hope that helps.

__________________
http://wasted-droid.com
0
James

Junior Member
Registered:
Posts: 29
Reply with quote  #3 
Quote:
Originally Posted by Roman
Create a function that you will call.(add showinterstitial in it) At the end of this function go to gameover scene. That way update function won't be repeated 2 times.

I hope that helps.



Thanks but i dont have a gameover sence the game over is on the same scene just when you lose the main camrea has some effect..
any other solution?
0
Roman

Avatar / Picture

Senior Member
Registered:
Posts: 304
Reply with quote  #4 
Call a function in some other script and destroy that one if you don't need it, or maybe you can make a bool variable that will call a function that displays your ad only if it happened once. There are a lot of ways...
__________________
http://wasted-droid.com
0
James

Junior Member
Registered:
Posts: 29
Reply with quote  #5 
Quote:
Originally Posted by Roman
Call a function in some other script and destroy that one if you don't need it, or maybe you can make a bool variable that will call a function that displays your ad only if it happened once. There are a lot of ways...


Thanks! it works great now
James
0
Salus Games

Member
Registered:
Posts: 85
Reply with quote  #6 
Glad you got it working but the simplest way I can think of and the way I do it it just to call the interstitial at the same point you set GameOver.active to true. Should only trigger once.



__________________
http://www.salusgames.com - Our passion is making great quality games across all genre's.
0
James

Junior Member
Registered:
Posts: 29
Reply with quote  #7 
Quote:
Originally Posted by Salus Games
Glad you got it working but the simplest way I can think of and the way I do it it just to call the interstitial at the same point you set GameOver.active to true. Should only trigger once.




Hey Salus 


can you please give me an example code for what you mean?


Thanks!
0
Salus Games

Member
Registered:
Posts: 85
Reply with quote  #8 
A quick example I could think of would be a bullet hitting a player. Each time it hits it will take off 1 health. If the players current health is 1 when a bullet hits it means that bullet will kill him so game over, show the ad

Bullet Script

OnTriggerEnter2D(Collider2D coll)
{
    if(coll.tag == "Player")
    {
        PlayerScript cachedPlayerScript = coll.GetComponent<PlayerScript>();
        
        if(cachedPlayerScript.health == 1)
        {
            CBBinding.ShowInterstial(null);
            GameOver.active = true;
        }
        cachedPlayerScript.health--;
    }        
}


Player Script

public int health = 10;


__________________
http://www.salusgames.com - Our passion is making great quality games across all genre's.
0
James

Junior Member
Registered:
Posts: 29
Reply with quote  #9 

Quote:
Originally Posted by Salus Games
A quick example I could think of would be a bullet hitting a player. Each time it hits it will take off 1 health. If the players current health is 1 when a bullet hits it means that bullet will kill him so game over, show the ad

Bullet Script
 OnTriggerEnter2D(Collider2D coll) { if(coll.tag == "Player") { PlayerScript cachedPlayerScript = coll.GetComponent(); if(cachedPlayerScript.health == 1) { CBBinding.ShowInterstial(null); GameOver.active = true; } cachedPlayerScript.health--; } } 


Player Script
 public int health = 10; 



Thats great
Thanks!

James

0
elektronische

Junior Member
Registered:
Posts: 4
Reply with quote  #10 
I'm doing the same, and test announcement Charboost works fine, the problem is that in the background Unity keeps running. Is there a function to stop the game while the ad is shown? And play on when the ad disappears?

PS: Thanks a lot for this great forum!
0
Salus Games

Member
Registered:
Posts: 85
Reply with quote  #11 
This is off the top of my head but i think there is a isImpressionVisable bool that chartboost sets to true when a ad is showing. So maybe something like 


if(CBBinding.isImpressionVisable)
{
     time.timeScale = 0f;
}

__________________
http://www.salusgames.com - Our passion is making great quality games across all genre's.
0
Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Easily create a Forum Website with Website Toolbox.