How can you determine the position in the race by checkpoints? There are checkpoints on the track, I want to determine the position of cars by the number of checkpoints passed, such an assessment is not entirely accurate, but for me it is quite suitable.
At this stage, I have a script where I populate a list with all the cars on the scene, each car has a variable number of checkpoints passed. Please tell me how to do it, preferably with code example
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
public class RaceManager : MonoBehaviour
{
public Text racePostotionsText;
public List<GameObject> carObjects = new List<GameObject>();
private void Start()
{
Physics.IgnoreLayerCollision(3, 7);
GameObject[] objects = GameObject.FindObjectsOfType<GameObject>();
foreach (var obj in objects)
{
if (obj.GetComponent<CarEngine>())
{
carObjects.Add(obj);
}
if (obj.GetComponent<CarController>())
{
carObjects.Add(obj);
}
}
}
private void Update()
{
}
}