When you instantiate an AI clone, add them to a list, like: `public List drivers `. The list will contain all AI drivers. Once the race ends, iterate through the list to access each AI's race time. If you wish to store the times of each driver, you can create a dictionary `public Dictionary raceTimes; `I used a *float* but you would put whatever type you use to store your race time. Now, each AI driver is the key and their race time is the value. You can use this to create your scoreboard.
-
You'd access the carEngine script inside the loop like this:
foreach ( var ai in drivers )
{
// This is how you access the variable for the time it took a car to get from start to finish Line from each AI driver.
ai.RaceTimeVariable
}
Make sure you initialize the list before you add the AI cars to it...
↧