- Home /
Comparing time. Missing something?
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();
}
Answer by bpaynom · Feb 04, 2019 at 03:17 PM
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;
void OnCollisionEnter(Collision obj)
{
t = Time.time;
Debug.Log (Time.time);
if (UnityEngine.Advertisements.Advertisement.IsReady() && t > 30)
{
Time.timeScale = 0f;
UnityEngine.Advertisements.Advertisement.Show("rewardedVideo",new ShowOptions() { resultCallback = HandleAdResult });
}
like this one?
Yes that's the next thing I'm going to do. This is actually going to ask user (rewarded video), but first i wanted to see this functioning well and than I'm going to edit this code for a button
And you're saying that the ad shows when that debug prints 6 ?
Thank you, I understand now how that lines work :). I thought different about Time.time, gotta read carefully :) Solved!
Answer by Glycin · Feb 04, 2019 at 04:15 PM
Time.time keeps track of the time since the start of the game:
https://docs.unity3d.com/ScriptReference/Time-time.html
So you probably want to do:
t = Time.time + 30f;
$$anonymous$$y bad, I didn't read carefully about Time.time. Problem solved thanks :)
Your answer
Follow this Question
Related Questions
80 tags for one game? 3 Answers
Delay Advertisements when switching between scenes? 0 Answers
How can I add time to a timer on an object collision? 1 Answer
How to change fall delay of a gameobject by time? 2 Answers
Destroy Object Over Time 1 Answer