Created
July 25, 2011 12:23
-
-
Save AngryAnt/1104017 to your computer and use it in GitHub Desktop.
An example of tracking distance traveled and translating to game points. Untested.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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