|
I am trying to display through GUI text the amount of calories burned riding a bicycle relative to the amount of time spent riding the bike. The code I have works except for the fact that it resets back to zero every 60 seconds. I can't for the life of me figure out what's wrong. Here's the code that I am using below. //Format the time nicely guiText.text = FormatTime (); guiText.material.color=Color.white; } //Format time like this //12(minutes):34(seconds).5(fraction) function FormatTime () { var intTime = Time.time; var seconds = intTime % 60; switch (vehicle) { case "car" : calories = seconds * .03317; break; case "bike": calories = seconds * .1325; break; case "walk": calories = seconds * .058; break; default: //don't do anything! break; } calories = Mathf.Floor(calories * 100) / 100; //print (calories);
return caloriesText; } Any help would be appreciated!
(comments are locked)
|
|
You're telling it to reset to 0 every 60 seconds when you use the modulus operator: "var seconds = intTime % 60;". However, most of that actually isn't necessary; you're better off just using string formatting:
(comments are locked)
|
