Car IA and path from MAYA

Hello
I use a script to move my vehicles.
To do the route, I have to make this one stage by stage.
I created the path by adding manually marks.
These are tags in a way, when we begin the game, the vehicle follows the route.

In the script below, I have to give the “nomChemin”
Then vehicle follows the way: “void NextIndex”

How can I modify the script so that the vehicle follows the path of MAYA and begins in the IndexDeDepartVehicule (index for start of vehicule)?

Thank you

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class CarScript : MonoBehaviour {

public string nomChemin;
public float vitesseKmh;
float vitesse;
float sp;

List chemin;
float range = 0.5f,ratio;
Transform _transform,rayPoint;
int index;
bool stopCar,emergencyStop,noStopZone;
Rigidbody _rigidbody;
float acceleration;
int layerVehicule = 1 << 8;

void Start(){
_rigidbody = rigidbody;
_rigidbody.centerOfMass += new Vector3(0f, 0f, 1.0f);
vitesse = vitesseKmh/3.6f;
sp = vitesse;
acceleration = 10;
rayPoint = transform.Find (“RaycastPoint”);
_transform = transform;
ControlScript sc =GameObject.Find(“Controle”).GetComponent();
chemin = new List (sc.GetPath(nomChemin));
ratio = 0;
stopCar = emergencyStop=noStopZone = false;
layerVehicule= ~layerVehicule;
}

void Update()
{
RaycastHit hit;
float distance = 5.0f;

if(!stopCar){
if(vitesse<sp)vitesse+=Time.deltaTimeacceleration;
else if (vitesse > sp)vitesse -=Time.deltaTime
acceleration;
}else if(stopCar){
if(vitesse>0)
vitesse -= Time.deltaTimeacceleration;
else
vitesse=0;
}
if(Physics.Raycast(rayPoint.position,_transform.forward,out hit,distance)){
vitesse = (sp * (hit.distance/distance));
}
Vector3 dir = _transform.position - chemin[index].position;
if (dir.sqrMagnitude > range)
{
Move(chemin[index].position);
}
else NextIndex();
}
void Move(Vector3 target)
{
_transform.Translate(0,0,Time.deltaTime
vitesse);
if(ratio<1){
ratio += Time.deltaTime*0.1f;
var newRotation = Quaternion.LookRotation(target - _transform.position);
_transform.rotation = Quaternion.Lerp(_transform.rotation,newRotation,ratio);
}
}

/void NextIndex()
{
if (++index == chemin.Count) index = 0;
ratio = 0;
}
/

void NextIndex()
{
if (++index >= chemin.Count) {
index = 0;
transform.position = chemin[index].position;
}else{
if (++index == chemin.Count) index = 0;
ratio = 0;
}
}

public void StopCar(bool b){
if(!noStopZone)
stopCar = b;
}
public void SetSpeed(float f){
sp = f;
}
public float GetSpeed(){
return _rigidbody.velocity.magnitude;
}
public void EmergencyStop(){
if(emergencyStop){
stopCar = true;
acceleration = 20.0f;
StartCoroutine (SetAcceleration());
}
}
IEnumerator SetAcceleration(){
if(vitesse != 0)yield return null;
acceleration = 10.0f;
emergencyStop = false;
}
public void SetEmergencyStop(bool b){
emergencyStop = b;
}
public void SetNoStop(bool b){
noStopZone = b;
}
public void Reset(){
stopCar = false;
noStopZone=false;
emergencyStop= false;
}
}

/* cough cough */ Code tags please…

I would set the track up in Maya as an object with children. Number those in order. This way, in script all you have to do is get the children of that object and since they were numbered in order they will retain the order in Unity. Then each point is a waypoint and you simply use them like you are above.

Hi

I m noobs in script;
I do not know how to code.
It is a pupil engineer who made this code.
He cannot end it any more.

Can you finish it ?

Thank you

using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;

 public class CarScript : MonoBehaviour {

 public string nomChemin;
 public float vitesseKmh;
 float vitesse;
 float sp;

 List <Transform> chemin;
 float range = 0.5f,ratio;
 Transform _transform,rayPoint;
 int index;
 bool stopCar,emergencyStop,noStopZone;
 Rigidbody _rigidbody;
 float acceleration;
 int layerVehicule = 1 << 8;

 void Start(){
 _rigidbody = rigidbody;
 _rigidbody.centerOfMass += new Vector3(0f, 0f, 1.0f);
 vitesse = vitesseKmh/3.6f;
 sp = vitesse;
 acceleration = 10;
 rayPoint = transform.Find ("RaycastPoint");
 _transform = transform;
 ControlScript sc =GameObject.Find("Controle").GetComponent<ControlS cript>();
 chemin = new List<Transform> (sc.GetPath(nomChemin));
 ratio = 0;
 stopCar = emergencyStop=noStopZone = false;
 layerVehicule= ~layerVehicule;
 }

 void Update()
 {
 RaycastHit hit;
 float distance = 5.0f;

 if(!stopCar){
 if(vitesse<sp)vitesse+=Time.deltaTime*acceleration ; 
 else if (vitesse > sp)vitesse -=Time.deltaTime*acceleration;
 }else if(stopCar){
 if(vitesse>0)
 vitesse -= Time.deltaTime*acceleration;
 else 
 vitesse=0;
 }
 if(Physics.Raycast(rayPoint.position,_transform.fo rward,out hit,distance)){
 vitesse = (sp * (hit.distance/distance));
 }
 Vector3 dir = _transform.position - chemin[index].position;
 if (dir.sqrMagnitude > range)
 {
 Move(chemin[index].position);
 }
 else NextIndex();
 }
 void Move(Vector3 target)
 {
 _transform.Translate(0,0,Time.deltaTime*vitesse);
 if(ratio<1){
 ratio += Time.deltaTime*0.1f;
 var newRotation = Quaternion.LookRotation(target - _transform.position);
 _transform.rotation = Quaternion.Lerp(_transform.rotation,newRotation,ra tio);
 }
 }

 /*void NextIndex()
 {
 if (++index == chemin.Count) index = 0;
 ratio = 0;
 }*/

 void NextIndex()
 {
 if (++index >= chemin.Count) {
 index = 0;
 transform.position = chemin[index].position;
 }else{
 if (++index == chemin.Count) index = 0;
 ratio = 0;
 }
 }

 public void StopCar(bool b){
 if(!noStopZone)
 stopCar = b;
 }
 public void SetSpeed(float f){
 sp = f;
 }
 public float GetSpeed(){
 return _rigidbody.velocity.magnitude;
 }
 public void EmergencyStop(){
 if(emergencyStop){
 stopCar = true;
 acceleration = 20.0f;
 StartCoroutine (SetAcceleration());
 }
 }
 IEnumerator SetAcceleration(){
 if(vitesse != 0)yield return null;
 acceleration = 10.0f;
 emergencyStop = false;
 }
 public void SetEmergencyStop(bool b){
 emergencyStop = b;
 }
 public void SetNoStop(bool b){
 noStopZone = b;
 }
 public void Reset(){
 stopCar = false;
 noStopZone=false;
 emergencyStop= false;
 }
 }