Calculate distance travalled.

I want to calculate the total distance traveled by an object in the whole axis (x, y, z).
(I’m not talking about calculating the distance between 2 object)

This depends on your specific project also but if you are talking about tracking distance travelled in the 3D space by an object you can add up it’s distance every frame.

Vector3 oldPos;
float totalDistance = 0;

void Start(){
    oldPos = transform.position;
}

void Update(){
    Vector3 distanceVector = transform.position - oldPos;
    float distanceThisFrame = distanceVector.magnitude;
    totalDistance += distanceThisFrame;
    oldPos = transform.position;
}

Hi, I think the best way to do this is by using

distance = radius * theta(rotaion in radian) ;

Or

In case your object is a car you can track total number revolution of the tyre to calculate distance being travlled it will give you very accurate result.
Here is how.

1 Rev = 2 * (pi = 3.14) * (radius of the tyre) . => distance travelled in one revolution.

Hi @FurkanOcalan

this is an easy one. Just calculate the distance between where it was and where it is on each update.

public float totalDistance = 0;
public bool record = true;

private Vector3 previousLoc;

void FixedUpdate() {
	if (record)
		RecordDistance ();
}

void RecordDistance () {
	totalDistance += Vector3.Distance(transform.position, previousLoc);
	previousLoc = transform.position;
}

void ToggleRecord() => record = !record;

This works on the physics update. Meaning even if you do circulate motion it will still record the total distance traveled.