Hi all,
I’m a little lost with how to get an object’s transform.position, sequentially, from an array. I currently have have an array of checkpoints in my game. As of now, it’s pulling ALL the array’s data.
Array code:
for (int w = 0; w < wayPointLoc.Length; w++)
{
var currentWaypoint = wayPointObj[w];
var wayPointPos = wayPointLoc[w].position;
var wayPointTransform = transform.position;
distanceToWayPoint = Vector3.Distance(wayPointPos, wayPointTransform);
//Debug.Log(currentWaypoint + ">>> Checkpoints Passed: [[[" + checkPointCounter + "]]] Distance: [" + distanceToWayPoint + "]");
Debug.Log(currentWaypoint + ">>> Checkpoints Passed: [[[" + checkPointCounter + "]]] Distance: [" + wayPointTransform + "]");
}
What I’d like to happen is once the player passes a checkpoint, it’ll only check for the distance of the next checkpoint in the array.
Collider code:
void OnTriggerExit(Collider other)
{
if (checkPointCounter != wayPointObj.Length)
{
/*
*
* if checkPointCounter == wayPointObj[a].length
* didCompleteLap = true
* lapsCompleted++
*
* if lapsCompleted == totalLaps
* DONE
*
*/
/**********************/
if (other.gameObject.CompareTag("scoreStage"))
{
//increment every a collider passed.
checkPointCounter++;
currentWayPoint = checkPointCounter;
checkpointHit = true;
}
}
else
{
lapsCompleted++;
didCompleteLap = true;
//Debug.Log("Laps Completed: [" + lapsCompleted + "]");
checkPointCounter = 0;
if (lapsCompleted != totalLaps)
{
didCompleteLap = false;
}
else
{
didFinishRace = true; Time.timeScale = 0;
}
if (lapsCompleted <= (totalLaps - 1))
{
print("Final Lap");
}
}
}
What’s the best way to handle this?
Thanks in advance…