Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 _Remu_ · Jan 20, 2015 at 01:27 PM · javascriptrandomtimergeneration

Perform Function, If Not Clicked In 3 Seconds

I have game that presents the user with a random number (between 1 and 6). Upon tapping on the number the game generates a new number. If the new number is the same as the previous number, and the user tapps on it, the player looses the game. there is also a timer that causes the player to loose the game if they do not tapp the current number within 3 seconds.

I would like it to be that if a duplicate number appears, the player must not tapp it, for three seconds, and then a new number generates, and the proccess starts again.

What I am looking for is some sort of 'IfNotClickedIn3Seconds' function. Thanks.

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 _Remu_ · Feb 01, 2015 at 09:26 PM

I solved it, by running a single timer. I set a bool variable where if true, something will happen if the timer reaches 0.01 seconds. If the bool is false, the timer will still reach 0.0 seconds, and time out the player.

Comment
Add comment · 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
0

Answer by Denvery · Jan 20, 2015 at 01:50 PM

May be you search for something like this?

 float remainTime;
 bool count3Seconds;
 
 private void BeginCount3Seconds()
 {
    remainTime = 3;
    count3Seconds = true;
 }
 
 private void StopCount3Seconds()
 {
    count3Seconds = false;
 }
 
 private bool IfNotClickedIn3Seconds()
 {
    remainTime -= Time.deltaTime;
    if (remainTime < 0)
    {
       return true;
    }
    else
    {
       return false;
    }
 }
 
 private void Update()
 {
    if (count3Seconds)
    {
       if (IfNotClickedIn3Seconds)
       {
          PerformYouFunc();
          StopCount3Seconds();
       }
 
    }
 }

(somewhere (after number generation may be) you need call BeginCount3Seconds())

Comment
Add comment · Show 3 · 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 _Remu_ · Jan 20, 2015 at 03:57 PM 0
Share

Thanks, any chance you could translate it to javascript?

avatar image Denvery · Jan 20, 2015 at 03:58 PM 0
Share

Ok, I'll translate! Be back in 2 hrs.

avatar image Denvery · Jan 20, 2015 at 05:31 PM 0
Share

As I promised, translated code to JavaScript:

 var remainTime;
  var count3Seconds;
  
  function BeginCount3Seconds()
  {
     remainTime = 3;
     count3Seconds = true;
  }
  
  function StopCount3Seconds()
  {
     count3Seconds = false;
  }
  
  function IfNotClickedIn3Seconds()
  {
     remainTime -= Time.deltaTime;
     if (remainTime < 0)
     {
        return true;
     }
     else
     {
        return false;
     }
  }
  
  function Update()
  {
     if (count3Seconds)
     {
        if (IfNotClickedIn3Seconds)
        {
           PerformYouFunc();
           StopCount3Seconds();
        }
  
     }
  }



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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Code to randomly generate a mesh? 0 Answers

Random spawn timer 1 Answer

Generate random path in grid 1 Answer

Using arrays to randomly select an object 0 Answers

Random Room Generator 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