How can I check the elapsed between two intervals? I want to do the following: "start time counter when Input.GetButtonDown("Fire1") , stop counter when collision is detected` And then Debug.Log the elapsed time?

  • 4
    \$\begingroup\$ Please don't edit a question to change it into a completely different question. The original was about measuring elapsed time, and the accepted answer reflects that. Changing it to be about altitude is just confusing. If you have something else you want to know, ask a new question rather than editing an old one. \$\endgroup\$
    – DMGregory
    Nov 6, 2015 at 20:34
  • 3
    \$\begingroup\$ This is the second time you've done this, and the second and last time you will receive a warning about it. Don't edit questions to drastically change their subject matter, especially once they are established questions with answers. \$\endgroup\$
    – user1430
    Nov 6, 2015 at 23:47

1 Answer 1


Store Time when the Fire1 button goes down, and then check the difference between that stored value and Time.time when the collision is detected:

private float fire_start_time;

void Update() {
    if(Input.GetButtonDown("Fire1")) {
        fire_start_time = Time.time;

void OnTriggerEnter(Collider other) {
    Debug.Log("elapsed time: " + (Time.time - fire_start_time));

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .