Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by panim0_unity · Feb 04, 2019 at 03:11 PM · collisiontimeadscompare

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();

     }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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;

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image panim0_unity · Feb 04, 2019 at 03:22 PM 0
Share
 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? 
avatar image panim0_unity · Feb 04, 2019 at 03:25 PM 0
Share

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

avatar image bpaynom panim0_unity · Feb 04, 2019 at 04:08 PM 0
Share

And you're saying that the ad shows when that debug prints 6 ?

avatar image panim0_unity bpaynom · Feb 04, 2019 at 06:22 PM 0
Share

yeah it was like that.

avatar image panim0_unity · Feb 04, 2019 at 06:21 PM 0
Share

Thank you, I understand now how that lines work :). I thought different about Time.time, gotta read carefully :) Solved!

avatar image
0

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;
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image panim0_unity · Feb 04, 2019 at 06:20 PM 0
Share

$$anonymous$$y bad, I didn't read carefully about Time.time. Problem solved thanks :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

154 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges