Time for action – tracking scripts
We will be creating this script in the Space Fighter game:
- First, we will need a special class that will keep track of our performance statistics. Create a new script and name it
TrackerStat
. - To begin this script, we first need to change the class definition line. We do not want or need to extend the
MonoBehaviour
class. So, find the following line of code:public class TrackerStat : MonoBehaviour {
And, change it to the following:
public class TrackerStat {
- This script starts with four variables. The first will be used as an ID, allowing us to track multiple scripts at once by supplying different key values. The second will keep track of the average amount of time that the tracked bits of code are taking. The third is just the total number of times the tracked code has been called. The fourth is the longest time the code has taken to execute.
public string key = ""; public float averageTime = 0; public int totalCalls = 0; public float longestCall...