Skip to content

Instantly share code, notes, and snippets.

@AngryAnt
Created July 25, 2011 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AngryAnt/1104017 to your computer and use it in GitHub Desktop.
Save AngryAnt/1104017 to your computer and use it in GitHub Desktop.
An example of tracking distance traveled and translating to game points. Untested.
using UnityEngine;
using System.Collections;
public class DistancePoints : MonoBehaviour
{
public float pointsPerUnit = 1.0f;
private Vector3 lastPosition;
private float measuredDistance;
void Start ()
{
lastPosition = transform.position;
measuredDistance = 0.0f;
}
void Update ()
{
measuredDistance += (transform.position - lastPosition).magnitude;
lastPosition = transform.position;
}
public float Points
{
get
{
return measuredDistance * pointsPerUnit;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment