This supposed to show ad after 30secs but it shows ad even if my player touches this obj at 6th sec and I really don’t know why.
void OnCollisionEnter(Collision obj)
{
t = Time.time;
if (UnityEngine.Advertisements.Advertisement.IsReady() && t > 30)
{
Time.timeScale = 0f;
UnityEngine.Advertisements.Advertisement.Show();
}
,This should be working after 30secs but ad displays even if my player touches this object on 6th sec it still displays ad and I really don’t know why.
void OnCollisionEnter(Collision obj)
{
t = Time.time;
if (UnityEngine.Advertisements.Advertisement.IsReady() && t > 30)
{
Time.timeScale = 0f;
UnityEngine.Advertisements.Advertisement.Show();
}
Have you Debug.Log ( Time.time ); at the moment you show the ad ?
BTW, you should store somewhere the desired time to show ad. The way you’re doing it could show infinite ads just exiting and reentering the collision. Let the user a break between ads.
Try this
void OnCollisionEnter(Collision obj)
{
Debug.Log (Time.time);
if (UnityEngine.Advertisements.Advertisement.IsReady() && Time.time > t )
{
t = Time.time + 30f;
Time.timeScale = 0f;
UnityEngine.Advertisements.Advertisement.Show("rewardedVideo",new ShowOptions() { resultCallback = HandleAdResult });
}
And on Start () you should initialize t to Time.time + 30;
Glycin
3
Time.time keeps track of the time since the start of the game:
So you probably want to do:
t = Time.time + 30f;