- Home /
 
how to find time of a button pressed
Hello I have force and need to set it with the time of button pressing and holding and after releasing the button , time change to a number and get in my force value but don't know how to do it? how can I find and access the time of button pressing? (Please answer with java) thanks
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by ShadowAngel · Feb 17, 2013 at 09:04 AM
 var button_press_time : float = 0.0; // button_press_time variable to store our time
 
 function OnGUI()
 {
     if (GUI.Button(Rect(0,0,200,200),"Time")) //Check when button is pressed
     {
         button_press_time = Time.time; //Set button_press_time  to current time
         Debug.Log(button_press_time); // Print button_press_time to console
     }
 }
 
               Same goes for standard Input methotds.
Answer by tomekkie2 · Feb 17, 2013 at 08:57 AM
Just use Time.time
 var timePressed:float;
         
 function OnGUI() {
    if (GUI.Button(new Rect(55, 170, 120, 20), "Press")) timePressed = Time.time;
 }
 
              Your answer