Code : Tout sélectionner
Assets/SCRIPT/Route/DebutRoute.cs(126,83): error CS1525: Unexpected symbol `trajets'
Mais avec ou sans virgule, le code erreur est le même.
Code avec la virgule
Code : Tout sélectionner
using UnityEngine;
using System.Collections;
using System;
// donne le% de véhicules
[Serializable]
public struct Trajets {
public GameObject trajObject;
public float vitesse;
public float mEntrePoint;
public DepartVl[] departVl;
public float pCar;//
public float pUtilitaire;//
public float pSemi;//
public float pBus;//
public float pSemiLong;//
public float pMoto;//
}
[Serializable]
public struct DepartVl {
public int positionDepart;
public float vitesseDepart;
}
public enum InterieurVl {
None,
Oui,
Non
}
public class DebutRoute : MonoBehaviour {
// script qui detruit le vl à la fin du parcours et l'instancie au départ
// si true coché = début si false non coché = à fin
/*Donc tu choisie dans l'inspector le nombre de vl que tu veux au lancement de ta maquette pour chaque trajet et le programme vas te les instancié automatiquement par rapport à la fraction et au trajet.
exemple :
ligne Vl depart 4 , car j'ai 4 voies
element 0 : 4 si je veux 4 vl affichés dès le lancement de la maquette sur cette voie
element 1 : 1 si je veux 1 vl affichés dès le lancement de la maquette sur cette voie
element 2 : 3 si je veux 3 vl affichés dès le lancement de la maquette sur cette voie
element 3 : 10 si je veux 10 vl affichés dès le lancement de la maquette sur cette voie
Pour element0 , on a mis 0. Il y aura 0 véhicuke sur le trajet à 0.0, 0.25, 0.5 et 0.75
Pour element3 , on a mis 10. Il y aura 10 véhicuke sur le trajet à 0,0. 0.1, 0.2, 0.3, ....., 0.9
Il n'y a acucun vl à 1 car il serait à la fin du trajet et donc invisible !
*/
public Trajets[] trajets;
private int choixTrajet;
// pour multiplier le temps d'apparition des vl la nuit
public float multiplicateurNuit = 1.0f;
// temps apparition entre chaque voiture choisi au hasard
public float[] tempsApparition; // dans inspector donner le nombre de temsp puis les renseigner
//choisis un temps aléatoire
private int choixTemps;
private float temps;
public float pCar;
public float pUtilitaire;
public float pSemi;
public float pBus;
public float SpSemiLong;
public float pMoto;
private int choixPourcentage;
private bool finStart;
private Light jourNuit;
void Start () {
choixTemps = UnityEngine.Random.Range(0,tempsApparition.Length);
choixTrajet = UnityEngine.Random.Range(0,trajets.Length);
choixPourcentage = UnityEngine.Random.Range(1,101);
if (pCar + pUtilitaire + pSemi + pBus + SpSemiLong + pMoto > 100)
Debug.LogError("il y a plus de 100%");
if (pCar + pUtilitaire + pSemi + pBus + SpSemiLong + pMoto < 100)
Debug.LogError("il y a moin de 100%");
for (int i = 0; i < trajets.Length; i++) {
CreationVlDepart (i);
}
// 1 ° gamobject car seul dans la hierarchy.on va chercher sky Dome
// je prends son enfant Light
// dans Inspector on prend Light
jourNuit = GameObject.Find("Sky Dome").transform.FindChild("Light").GetComponent<Light>();
finStart = true;
}
// Update is called once per frame
void Update () {
if (finStart && Time.timeScale != 0) {
temps += Time.fixedDeltaTime;
// on multiplie le temps d'apparition si light < à 0.15
float tempsTempoApparition = 0.0f;
if ( jourNuit.intensity < 0.15f) {
tempsTempoApparition = tempsApparition[choixTemps] * multiplicateurNuit;
}
else {
tempsTempoApparition = tempsApparition[choixTemps];
}
//automatiquement
if (temps >= tempsTempoApparition) {
CreationVl(trajets[choixTrajet].trajObject, trajets[choixTrajet].mEntrePoint, trajets[choixTrajet].vitesse, 0);
choixTemps = UnityEngine.Random.Range(0,tempsApparition.Length);
choixTrajet = UnityEngine.Random.Range(0,trajets.Length);
choixPourcentage = UnityEngine.Random.Range(1,101);
temps = 0;
}
}
}
void CreationVlDepart (int countTrajet) {
if (trajets[countTrajet].departVl.Length != 0) {
for (int i = 0; i < trajets[countTrajet].departVl.Length; i++) {
CreationVl (trajets[countTrajet].trajObject trajets[countTrajet].mEntrePoint, trajets[countTrajet].departVl[i].vitesseDepart, trajets[countTrajet].departVl[i].positionDepart);
}
}
}
public void CreationVl (Trajets trajet, float metre, float vitesseFraction, int position) {
string nom = "";
int choixVl = 0;
InterieurVl interieur = InterieurVl.None;
//voitures
if (choixPourcentage < trajet.pCar) {
choixVl = UnityEngine.Random.Range(1,19); //19car il y a 18 voitures + 1
nom = "Voitures/Car_";
interieur = InterieurVl.Oui;
//utilitaires
} else if (choixPourcentage < trajet.pCar + trajet.pUtilitaire) {
choixVl = UnityEngine.Random.Range(1,14);//14 car il y a 13 utilitaires+ 1
nom = "Utilitaires/utilitaire_";
interieur = InterieurVl.Oui;
//semi
} else if (choixPourcentage < trajet.pCar + trajet.pUtilitaire + trajet.pSemi) {
choixVl = UnityEngine.Random.Range(1,9);//car 8 camions ne pas prendre les porte char et le double remoque
nom = "Poids_Lourds/semi_";
interieur = InterieurVl.Oui;
//bus
} else if (choixPourcentage < trajet.pCar + trajet.pUtilitaire + trajet.pSemi + trajet.pBus) {
choixVl = UnityEngine.Random.Range(1,4);//car 3 bus +1
nom = "BUS/bus_";
interieur = InterieurVl.Oui;
//semi long 2 remorque et porte char
} else if (choixPourcentage < trajet.pCar + trajet.pUtilitaire + trajet.pSemi+ trajet.pBus + trajet.pSemiLong) {
choixVl = UnityEngine.Random.Range(1,4);//car 2 porte chars et le double remoque
nom = "Super_Poids_Lourds_Longs/semiLong_";
interieur = InterieurVl.Oui;
//moto
} else if (choixPourcentage <= trajet.pCar + trajet.pUtilitaire + trajet.pSemi+ trajet.pBus + trajet.pSemiLong + trajet.pMoto) {
choixVl = UnityEngine.Random.Range(1,9);//9
nom = "Motos/moto_";
interieur = InterieurVl.Non;
}
GameObject instance = Instantiate(Resources.Load(""+nom+choixVl,typeof(GameObject))) as GameObject;
//modif du non
instance.name += trajet.name;
//change la postion de l'object dans le scéne
//donc transform = à l'obejct qui contient le script DebutRoute
instance.transform.SetParent(transform);
if (GetComponent<TrajetVl>() != null) {
//set le parcour sur l'object
instance.GetComponent<TrajetVl>().target_Path = trajet;
//modif la vitesse de l'object
instance.GetComponent<TrajetVl>().kmh = vitesseFraction;
instance.GetComponent<TrajetVl>().kmhActuel = vitesseFraction;
instance.GetComponent<TrajetVl>().minTab = position;
instance.GetComponent<TrajetVl>().mEntrePoint = metre;
instance.GetComponent<TrajetVl>().interieur = interieur;
instance.GetComponent<TrajetVl>().DemrageVl();
} else {
//set le parcour sur l'object
instance.GetComponentInChildren<TrajetVl>().target_Path = trajet;
//modif la vitesse de l'object
instance.GetComponentInChildren<TrajetVl>().kmh = vitesseFraction;
instance.GetComponentInChildren<TrajetVl>().kmhActuel = vitesseFraction;
instance.GetComponentInChildren<TrajetVl>().minTab = position;
instance.GetComponentInChildren<TrajetVl>().mEntrePoint = metre;
instance.GetComponentInChildren<TrajetVl>().interieur = interieur;
instance.GetComponentInChildren<TrajetVl>().DemrageVl();
}
}
}