Hi! Im creating a racing game in unity and for car positions(e.g Pos:2/8) and lap systems one of my friends gave this piece of code to me…but it counts from 0 to 8…
u know… when you are in the last position it writes Pos:0/8 instead of 8/8 and when you pass all of the cars it writes 8/8 instead of 1/8 and the code is here:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public class CheckpointManager : MonoBehaviour {
public List<GameObject> EnemyCars = new List<GameObject>();
public TextMesh PosText;
void Start()
{
GameObject pLayer = GameObject.FindWithTag("Player");
EnemyCars.Add(pLayer);
}
void Update()
{
GameObject _Player;
int _PlayerPos = 0;
for(int i=0; i<EnemyCars.Count; i++)
{
if(EnemyCars*.name == "Player")*
-
{*
Player = EnemyCars*;
_PlayerPos = EnemyCars.IndexOf(EnemyCars);*
* }
}
EnemyCars.Sort(SortByPassedCheckpoints);_
PosText.text = "Pos: " + PlayerPos.ToString() + “/” + EnemyCars.Count.ToString();*
* }*_
* int SortByPassedCheckpoints(GameObject C1, GameObject C2)*
* {*
* return C1.GetComponent().PassedCheckpoints.CompareTo(C2.GetComponent().PassedCheckpoints);*
* }*
}
Please help what should i do…thanx