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 sa957 · Sep 23, 2016 at 12:13 AM · timetriggerstimer-scriptreaction

on trigger enter, start timer, end when button is pressed & output reaction time.

I'm wondering if anyone has some insight on how to start a timer when the player enters a collider (is trigger). I want the player to react as quickly as possible by pressing a button in response to entering the trigger collider. I would also like the system to output a reaction time for each trigger collider. Is this possible?

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

1 Reply

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

Answer by hoogemast · Sep 23, 2016 at 07:55 AM

If i understand correctly what you would like to accomplish I would write something like this:

 class colliderWithTimer: MonoHehaviour
 private bool isTiming = false;
 private float timeTillKeyIsPressed = 0;
 
 void OnCollisionEnter(Collision collision) {
         isTiming = true;
 }
 
 void Update(){
         if (isTiming)
         {
                   timeTillKeyIsPressed += Time.DeltaTime;
         }
         if (Input.GetKeyDown(KeyCode.S)) // I used S, but ofc this can be something else
         {
                   isTiming = false;
         }
 
 }


now the timeTillKeyisPressed can be used to display the time.

Take note!! i do not know if it is the best practice to time in the update function with time.deltatime, but since you catch the keypressed in the update function as well i suspect this wouldn't give any performance issues. However when your framerate drops very low this can be a problem (but again the keypressed wont be caught either).

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 sa957 · Sep 26, 2016 at 04:49 PM 0
Share

Thank you so much!!! I will try this out and if it works out, I will find a way to compensat eyou :)) Thank you!

avatar image sa957 · Oct 03, 2016 at 01:04 AM 0
Share

Hey do you know how I can get it to show the reaction time (either in an onscreen window or in the editor/console?

avatar image hoogemast sa957 · Oct 06, 2016 at 09:21 AM 0
Share

yeah just add debug.log to show it in the console. Just like this:

if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.S)) { isTi$$anonymous$$g = false; Debug.Log(timeTill$$anonymous$$eyIsPressed) }

if you want to show it on screen you could try to use a ui element and change the text to with the timeTill$$anonymous$$eyIsPressed. You should of course cast the variable to a string.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Javascript beginner here: how do I implement time such as hours and days? 2 Answers

Why does my MatchTime Class not work when using Properties? 1 Answer

Static Variable Doesn't Change ? 0 Answers

reaction game: measure time of touch exactly? 1 Answer

How to make a date/time system with a fast forward feature? 2 Answers


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