How can I record the time that has passed between mouse clicks?
I am working on an app that when you click on a sprite, a timer starts (not visible) and records the time it took to click on the sprite which appeared just after the click. This repeats for 10 times, then a new scene is loaded and displays the all the times in seconds. I have the sprite appearing/disappearing component working, I just need the timer and recording function to work. Preferred language is C#. Any help is appreciated, thanks.
Answer by Hellium · Jan 20, 2017 at 08:54 AM
I haven't tested the code and it's just the part about saving the time between two mouse clicks, not retrieving data in other scene :
     private System.Collections.Generic.List<float> timers;
     private float lastClickTime = -1;
     private void Start()
     {
         timers = new System.Collections.Generic.List<float>();
     }
     private void Update()
     {
         if( Input.GetMouseButtonDown(0))
         {
             timers.Add( lastClickTime > 0 ? Time.time - lastClickTime : Time.time );
             if( timers.Count == 10 )
             {
                 // Save the timers into a file / PlayerPrefs
                 UnityEngine.SceneManagement.SceneManager.LoadScene( 1 );
             }
         }
     }
Hey, thanks a lot for the answer. I am wondering where to go next with the script, and what I can do to make it work. I forgot to mention I have little coding knowledge and I am keen to learn more. Thanks again.
Your answer
 
 
             Follow this Question
Related Questions
How to shake the virtual camera when time scale is 0? 0 Answers
20 minute countdown timer 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                