how to check how much distance the player covered.
Hello, I am making a 2d bike racing game like hill climb racing 2d. I want to make my game score according how much distance the player covered. But i don't know how to do that. Is someone else tell me how to do it.
Answer by UnityCoach · Oct 23, 2018 at 01:09 PM
You can something in the like :
public class DistanceMeter : MonoBehaviour
{
Vector3 _previousPosition;
float _distance;
void Start ()
{
_previousPosition = transform.position;
}
void Update ()
{
_distance += Vector3.Distance (_previousPosition, transform.position);
_previousPosition = transform.position;
}
}
@UnityCoach Hello sir, Here are some problem. I'm making 2D bike game. When bike going to positive horizontal direction it's fine. But when bike going to negative horizontal direction traveled distance is also increase. I just want to calculate the travel distance only on positive horizontal direction.
Your answer
Follow this Question
Related Questions
displaying high score 1 Answer
High Score Saving and Displaying on another scene 0 Answers
Fishing rod, connecting rod and bobber? 0 Answers
,Attack and chase range issue 2 Answers
Scoring Points with UI Text 0 Answers