• 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 · Oct 03, 2016 at 06:00 AM · scripting problemtimereaction

Outputting Reaction Time Data

Hi everyone,

Im creating an experiment with a driving simulator in Unity. I need to record player reaction time as soon as they enter a trigger. My problem is that I don't know how to get unity to provide me with a print out of the reaction time to each triggerevent. Here is the code ive been using so far:

using UnityEngine; using System.Collections;

public class ReactionTimer : MonoBehaviour {

 class colliderWithTimer: MonoBehaviour
 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;
     }

 }


 // Use this for initialization
 void Start () {
 
 }
 
 // Update is called once per frame
 void Update () {
 
 }

}

I was wondering if; a) this is correct for what I want to do and b) if there is a way so that the system will print out the reaction time to each event?

Thank you all very much!

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
0
Best Answer

Answer by Mindmapfreak · Oct 03, 2016 at 08:44 PM

If you just want to print out the time in the editor, use Debug.Log. If you want to see the reaction time in the compiled application you have to use the UI system. For Debug.Log something like this should work:

  void Update(){
      if (isTiming)
      {
          timeTillKeyisPressed += Time.DeltaTime;
      }
      if (Input.GetKeyDown(Keycode.S)) 
      {
          isTiming = false;
          Debug.Log("Reaction time: "+timeTillKeyisPressed+"ms"); //Or use UI here
          timeTillKeyisPressed = 0; //Reset timer
      }
  }

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 · Oct 04, 2016 at 01:40 PM 0
Share

Thank you very much! I tried this out and for some reason I can't figure out why I'm getting these 2 errors in the console:

Assets/Scripts/ReactionTimer.cs(8,15): error CS1031: Type expected

Assets/Scripts/ReactionTimer.cs(13,26): error CS1519: Unexpected symbol `=' in class, struct, or interface member declaration

Is there something wrong in my code? Thanks again for all your help.

avatar image Mindmapfreak sa957 · Oct 05, 2016 at 10:55 AM 0
Share

Can you show the part of the code that is causing the error (or the whole ReactionTimer.cs if that is not too big)?

avatar image sa957 Mindmapfreak · Oct 06, 2016 at 11:49 AM 0
Share

Yup, Here it is:

using UnityEngine; using System.Collections;

public class ReactionTimer : $$anonymous$$onoBehaviour {

 public class colliderTimer: $$anonymous$$onoBehaviour
 private bool isTi$$anonymous$$g = false;
 private float timeTill$$anonymous$$eyisPressed = 0;


 void OnCollisionEnter(Collision collision) {
     isTi$$anonymous$$g = true;
 }

 void Update(){
         if (isTi$$anonymous$$g) {
             timeTill$$anonymous$$eyisPressed += Time.DeltaTime;
         }
         if (Input.Get$$anonymous$$eyDown ($$anonymous$$eycode.S)) {
             isTi$$anonymous$$g = false;
             Debug.Log ("Reaction time: " + timeTill$$anonymous$$eyisPressed + "ms");
         }
     }

}

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Character controller without Deltatime 1 Answer

Increase speed over time 0 Answers

reaction game: measure time of touch exactly? 1 Answer

I want to make the gameobject rigidbody.iskinematic=true for 3s and immune to damage when it triggers the collider and then false again 0 Answers

Rewind time (or problems with arrays) 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