- Home /
Calorie tracker
Hello, I am working on a running game and have ran into a speed bump on this issue. I am trying to code a script that will simply add 35 calories per unity miles (1 mile = 1609.34 meters) So if my guy has traveled 1609 meters any direction, increment the variable by 35. Also if its possible to show the calories counting up from 0 over time(on GUI) where it lines up with the 35 per mile that would be great. I am pretty new to unity and scripting so any help is appreciated. Thank you!
Generally learn about InvokeRepeating
. $$anonymous$$ake it so that every 1 second, it checks the distance. you can then update the variable "calories", and, you can update the .text
UI display.
Be absolutely sure you are using Unity's "new" UI by the way Unity.UI
Answer by Superscope · Jan 27, 2016 at 07:22 AM
Fixed it to work correctly, had to change the int to a float
var calories : float;
var currentCal : UnityEngine.UI.Text;
function AddCalorie()
{
calories+= 0.025f;
currentCal.text = "Calories Burned: " + calories.ToString("f2");
}
Your answer
Follow this Question
Related Questions
Detect GUI rotation degree 1 Answer
Unity Reload Bullets left 1 Answer
Add to number little by little so it ends at specific number. 1 Answer
What is the mathematical formula for GUI dragging ? 2 Answers
Displaying Mathematical Equations 2 Answers