J'ai du mal à avoir les idées claires .Je comprends mieux pourquoi tu galères.
Pour le script d'où vient mon pb ?
J'ai du mal à avoir les idées claires .Je comprends mieux pourquoi tu galères.
Code : Tout sélectionner
// Définir une variable qui gardera en mémoire l'état en cours
bool etatLumiereCourant = false; //Ici, admettons que les lumières sont éteintes par défaut
...
void Update ()
{
// CalculerNouvelEtatLumiere () va définir si les lumières doivent être éteintes ou allumées.
// etatLumiereActuel va récupérer le résultat de ce calcul
bool etatLumiereActuel = CalculerNouvelEtatLumiere ();
// On compare l'état en cours et l'état actuel nouvellement calculé
// S'ils sont identiques alors pas besoin de modifier quoique ce soit
// Sinon on fait le changement
if (etatLumiereActuel != etatLumiereCourant )
{
// On redéfinit l'état en cours
etatLumiereCourant = etatLumiereActuel;
// On affecte l'éclairage
ChangerProprieteLumiere ();
}
}
Code : Tout sélectionner
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
// la fonction de trajet aérien est bloquée
/* Create by :
* Fabian Métayer
* 27/10/2015
*
* Modifle 15-1-2019 pour véhicules et perso escalier
*
*/
public class TrajetVl : MonoBehaviour {
public GameObject target_Path;
public float kmh; // vitesse voulue
public float kmhActuel; // vitesse reelle
public float mEntrePoint = 5.0f;
private float time;
public float fraction;
public Transform[] tabtList = new Transform[11];
public int minTab = 0;
public Transform detecteur;
public LayerMask layerPanneau;
public Collider[] toucheDetecteur;
public bool coupeDetecteur;
private Light jourNuit; //private
private GameObject eclairage; //private
private GameObject eclairageFreins;
public GameObject clignotantsDroits;
public GameObject clignotantsGauche;
private IEnumerator coroutineClignotants;
public InterieurVl interieur;
// pour allumer eteindre les feux dans un tunnel Définir une variable qui gardera en mémoire l'état en cours
bool etatLumiereCourant = false; //Ici, admettons que les lumières sont éteintes par défaut
public void DemrageVl () {
tabtList = new Transform[11];
TabDynamique ();
if (transform.FindChild("Detecteur"))
detecteur = transform.FindChild("Detecteur").transform;
jourNuit = GameObject.Find("Sky Dome").transform.FindChild("Light").GetComponent<Light>();
//cherche dans ces enfants un object avec le nom Eclairage
//si existe alors on ajoute l'object portant le nom "Eclairage" dans la variable eclairage
if (this.transform.FindChild ("Eclairage")) {
eclairage = this.transform.FindChild ("Eclairage").gameObject;
}
if (this.transform.FindChild ("Eclairage_Freins")) {
eclairageFreins = this.transform.FindChild ("Eclairage_Freins").gameObject;
eclairageFreins.SetActive (false);
}
if (this.transform.FindChild ("Eclairage_Clignotants_droits")) {
clignotantsDroits = this.transform.FindChild ("Eclairage_Clignotants_droits").gameObject;
clignotantsDroits.SetActive (false);
}
if (this.transform.FindChild ("Eclairage_Clignotants_gauche")) {
clignotantsGauche = this.transform.FindChild ("Eclairage_Clignotants_gauche").gameObject;
clignotantsGauche.SetActive (false);
}
StartCoroutine("WalkThePath");
}
// pour allumer eteindre les feux dans un tunnel Définir une variable qui gardera en mémoire l'état en cours
void Update ()
{
// CalculerNouvelEtatLumiere () va définir si les lumières doivent être éteintes ou allumées.
// etatLumiereActuel va récupérer le résultat de ce calcul
bool etatLumiereActuel = CalculerNouvelEtatLumiere ();
// On compare l'état en cours et l'état actuel nouvellement calculé
// S'ils sont identiques alors pas besoin de modifier quoique ce soit
// Sinon on fait le changement
if (etatLumiereActuel != etatLumiereCourant )
{
// On redéfinit l'état en cours
etatLumiereCourant = etatLumiereActuel;
// On affecte l'éclairage
ChangerProprieteLumiere ();
}
}
public void CalculerNouvelEtatLumiere(){
//??????
}
public void ChangerProprieteLumiere(){
if (eclairage.activeInHierarchy == false && jourNuit.intensity > 0.15f) { // si jour les feux s'allument
eclairage.SetActive (true);
}
if (eclairage.activeInHierarchy == false && jourNuit.intensity < 0.15f) { // si nuit les feux restent allumés
eclairage.SetActive (true);
}
/* ligne 291
void GestionLumiere () {
if (eclairage != null) {
if (jourNuit.intensity < 0.15f) {
if (eclairage.activeInHierarchy == false)
eclairage.SetActive (true);
}
else {
if (eclairage.activeInHierarchy == true)
eclairage.SetActive (false);
}
}
} */
public void TabDynamique () {
fraction = 0.1f;
int count = 0;
for (int i = 0; i < 11; i++) {
if (minTab+i < target_Path.transform.childCount) {
tabtList[i] = target_Path.transform.GetChild(minTab+i);
count++;
}
}
if (minTab+8 < target_Path.transform.childCount)
minTab += 8;
else
minTab += count;
}
public void StopCoroutine () {
StopCoroutine("WalkThePath");
}
/*
// version du createur DOTWEENN
void LateUpdate () {
//nombre de point * distance entre point / km/h / 3.6
time = (tabt.Length * mEntrePoint)/(kmh / 3.6f);
if (start) {
transform.position = iTween.PointOnPath(tabt, fraction);
fraction += Time.deltaTime / time;
if (fraction > 1.0f)
fraction = 0.0f;
transform.LookAt(iTween.PointOnPath(tabt, fraction + 0.001f));
}
}*/
IEnumerator WalkThePath () {
while(true){
time = ((tabtList.Length * mEntrePoint)/(kmhActuel / 3.6f)*0.88f);// original (tabtList.Length * mEntrePoint)/(kmhActuel / 3.6f)
/*
scene 2x2
362 x 5m = 1 810m
130 kmh/h fait 36.1111 mn/s donc 1 810m à 130km/h fait 50 sec / 55 sec réelles donc x0.91 pour avoir 50 sec
110 kmh/h fait 30.5555 mn/s donc 1 810m à 110km/h fait 59 sec / 64 sec réelles donc x0.91 pour avoir 59 sec
scene bi-di
305 x 5m = 1 525m
90 kmh/h fait 25 mn/s donc 1 525m à 90km/h fait 61 sec / 66 sec réelles donc x0.91 pour avoir 60 sec
50 kmh/h fait 13.888 mn/s donc 1 525m à 50km/h fait 110 sec/ 117 sec réelles donc x0.91 pour avoir 107 sec
*/
transform.position = iTween.PointOnPath (tabtList, fraction);
fraction += Time.deltaTime / time;
if (fraction > 1.0f)
fraction = 0.0f;
/* modif pour vehicule ou personnage*/
if (gameObject.tag == "VEHICULE")
{
transform.LookAt(iTween.PointOnPath(tabtList, fraction + 0.08f)); //0.05F plus c'est petit est plus de tremblote pour s'orienter sur le point à 0.005m
}
else
{
Vector3 direction =iTween.PointOnPath(tabtList, fraction + 0.08f); //0.05F
direction.y = this.transform.position.y;
transform.LookAt(direction);
}
if (gameObject.tag == "VELO")
{
transform.LookAt(iTween.PointOnPath(tabtList, fraction + 0.08f)); //0.05F plus c'est petit est plus de tremblote pour s'orienter sur le point à 0.005m
}
else
{
Vector3 direction =iTween.PointOnPath(tabtList, fraction + 0.08f); //0.05F
direction.y = this.transform.position.y;
transform.LookAt(direction);
}
if (kmhActuel < kmh){
kmhActuel += 0.7f;// acceleration jusqu'à la vitesse kmh 0.7f
} else if (kmhActuel > kmh && kmh != 0) {
kmhActuel -= 0.9f;// decceleration douce 0.9
} else if (kmh == 0) {
kmhActuel = 0;// on stoppe brutalement le VL
}
if (fraction >= 0.9f) //0.9f
TabDynamique();
GestionDetecteur ();
GestionLumiere ();
GestionFreins ();
yield return null;
}
}
void GestionDetecteur () {
if (detecteur != null) {
if (gameObject.tag == "VEHICULE")
toucheDetecteur = Physics.OverlapSphere(detecteur.position, 0.75f, layerPanneau);
else
toucheDetecteur = Physics.OverlapSphere(detecteur.position, 0.5f, layerPanneau);
if (toucheDetecteur.Length != 0) {
foreach (Collider other in toucheDetecteur) {
if (other.tag == "CoupeDetecteur") {
coupeDetecteur = other.GetComponent<CoupeDetecteur>().detecteur;
kmhActuel = 30.0f;// pour degager les croisements à 30 km/h
// tant que la sphere du détecteur est dans l'objet sa vitesse est de 30 km/h
// apres le VL reprend sa vitesse normale
}
if (other.tag == "CoupeDetecteurAutre") {
coupeDetecteur = other.GetComponent<CoupeDetecteur>().detecteur;
kmhActuel = 4.0f;
}
/////// Pour que vehicule se mette à la vitesse du velo s'il est devant
if (other.tag == "VELO") {
coupeDetecteur = other.GetComponent<TrajetVl>().detecteur;
kmhActuel = other.GetComponent<TrajetVl>().kmh; //
}
//////////////////////////
if (coupeDetecteur == false) {
if (other.tag == "ModifVitesse") {
kmh = other.GetComponent<Panneau>().vitesse;
} else if (other.tag == "EntreeInstersection") {
kmh = GetPrioriteVitesse(other);
} else if (other.tag == "VEHICULE") {
if (kmh > other.GetComponent<TrajetVl>().kmh)
kmh = other.GetComponent<TrajetVl>().kmh;
} else if (other.tag == "ClignotantsOn") {
kmh = other.GetComponent<GestionClignotants>().vitesse;
if (other.GetComponent<GestionClignotants>().trajet == target_Path) {
ClignotantsOff ();
if (other.GetComponent<GestionClignotants>().enumClignotants == EnumClignotants.Droites) {
coroutineClignotants = ClignotantsDroits();
StartCoroutine (coroutineClignotants);
} else {
coroutineClignotants = ClignotantsGauche();
StartCoroutine (coroutineClignotants);
}
}
} else if (other.tag == "ClignotantsOff") {
kmh = other.GetComponent<GestionClignotants>().vitesse;
ClignotantsOff ();
}
}
}
}
if (kmhActuel == 0 && toucheDetecteur.Length == 0)
kmhActuel = 30.0f;
}
}
void GestionLumiere () {
if (eclairage != null) {
if (jourNuit.intensity < 0.15f) {
if (eclairage.activeInHierarchy == false)
eclairage.SetActive (true);
}
else {
if (eclairage.activeInHierarchy == true)
eclairage.SetActive (false);
}
}
}
void GestionFreins () {
if (eclairageFreins != null){
if (kmhActuel > kmh+3 || kmhActuel == 0) {
if (eclairageFreins.activeInHierarchy == false)
eclairageFreins.SetActive (true);
} else {
if (eclairageFreins.activeInHierarchy == true)
eclairageFreins.SetActive (false);
}
}
}
IEnumerator ClignotantsDroits () {
if (clignotantsDroits != null) {
while (true) {
clignotantsDroits.SetActive (true);
yield return new WaitForSeconds (0.3f);
clignotantsDroits.SetActive (false);
yield return new WaitForSeconds (0.3f);
}
}
}
IEnumerator ClignotantsGauche () {
if (clignotantsGauche != null) {
while (true) {
clignotantsGauche.SetActive (true);
yield return new WaitForSeconds (0.3f);
clignotantsGauche.SetActive (false);
yield return new WaitForSeconds (0.3f);
}
}
}
void ClignotantsOff () {
if (coroutineClignotants != null) {
StopCoroutine (coroutineClignotants);
if (clignotantsDroits != null)
clignotantsDroits.SetActive (false);
if (clignotantsGauche != null)
clignotantsGauche.SetActive (false);
coroutineClignotants = null;
}
}
float GetPrioriteVitesse(Collider other){
Priorite priorite = other.GetComponent<Priorite> ();
if (priorite != null) {
return priorite.vitesse;
} else {
PrioriteOllioules prioriteOllioules = other.GetComponent<PrioriteOllioules> ();
return prioriteOllioules.vitesse;
}
}
}
Code : Tout sélectionner
public void CalculerNouvelEtatLumiere(){
//??????
}
Code : Tout sélectionner
using UnityEngine;
using System.Collections;
public class AfficheFeuxVehiculeVelo : MonoBehaviour {
// Faire une forme 3D du tunnel complet dans Maya3D
private GameObject LesFeuxDuVehiculeDansTunnel ;
public void RechercheLumieresDansTunnel () {
//cherche dans ces enfants un object avec le nom "LumieresDansTunnel"
//si existe alors on ajoute l'object portant le nom "LumieresDansTunnel" dans la variable LesFeuxDuVehiculeDansTunnel
if (this.transform.FindChild ("LumieresDansTunnel")) {
LesFeuxDuVehiculeDansTunnel = this.transform.FindChild ("LumieresDansTunnel").gameObject;
}
}
void OnTriggerEnter(Collider other) // le vehicule entre les feux copiés s'allument ( indépendant de gestionLumière de trajetvl)
{
if (other.tag == "VEHICULE" || other.tag == "VELO")
{
LesFeuxDuVehiculeDansTunnel.SetActive (true);
}
}
void OnTriggerStay(Collider other)// le vehicule reste dans la forme 3D de Maya avec les feux copiés toujours allumés ( indépendant de gestionLumière de trajetvl)
{
if (other.tag == "VEHICULE" || other.tag == "VELO")
{
LesFeuxDuVehiculeDansTunnel.SetActive (true);
}
}
void OnTriggerExit(Collider other) // le vehicule sort de la forme 3D de Maya , les feux copiés s'éteignent ( indépendant de gestionLumière de trajetvl)
{
if (other.tag == "VEHICULE" || other.tag == "VELO")
{
LesFeuxDuVehiculeDansTunnel.SetActive (false);
}
}
}
Code : Tout sélectionner
IEnumerator WalkThePath ()
{
while(true)
{
...
GestionLumiere ();
...
yield return null;
}
}
Code : Tout sélectionner
private bool dansUnTunnel = false;
void OnTriggerEnter(Collider other) // NE PAS COPIER LES FEUX, GARDER LES MEMES! ILS NE SONT PAS DIFFERENTS!
{
if (other.tag == "VEHICULE" || other.tag == "VELO")
{
dansUnTunnel = true;
}
}
void OnTriggerExit(Collider other) //SORTIE DU TUNNEL (UN SEUL COLLIDER ENTIER)
{
if (other.tag == "VEHICULE" || other.tag == "VELO")
{
dansUnTunnel = false;
}
}
void GestionLumiere () {
if (eclairage != null)
{
// SI TU ES DANS UN TUNNEL TU ALLUMES LES FEUX QUEL QUE SOIT LE JOUR/NUIT
if (dansUnTunnel) {
eclairage.SetActive (true);
}
// SINON C'EST LE JOUR/NUIT QUI S'EN OCCUPE
else {
if (jourNuit.intensity < 0.15f) {
if (eclairage.activeInHierarchy == false)
eclairage.SetActive (true);
}
else {
if (eclairage.activeInHierarchy == true)
eclairage.SetActive (false);
}
}
}
}
Code : Tout sélectionner
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
public class TunnelAllumageDesFeux : MonoBehaviour {
private bool dansUnTunnel = false;
private GameObject eclairage;
private Light jourNuit;
public void DemarageVl () {
jourNuit = GameObject.Find("Sky Dome").transform.FindChild("Light").GetComponent<Light>();
//cherche dans ces enfants un object avec le nom Eclairage
//si existe alors on ajoute l'object portant le nom "Eclairage" dans la variable eclairage
if (this.transform.FindChild ("Eclairage")) {
eclairage = this.transform.FindChild ("Eclairage").gameObject;
}
}
void OnTriggerEnter(Collider other) // NE PAS COPIER LES FEUX, GARDER LES MEMES! ILS NE SONT PAS DIFFERENTS!
{
if (other.tag == "VEHICULE" || other.tag == "VELO")
{
dansUnTunnel = true;
}
}
void OnTriggerExit(Collider other) //SORTIE DU TUNNEL (UN SEUL COLLIDER ENTIER)
{
if (other.tag == "VEHICULE" || other.tag == "VELO")
{
dansUnTunnel = false;
}
}
void GestionLumiere () {
if (eclairage != null)
{
// SI TU ES DANS UN TUNNEL TU ALLUMES LES FEUX QUEL QUE SOIT LE JOUR/NUIT
if (dansUnTunnel) {
eclairage.SetActive (true);
}
// SINON C'EST LE JOUR/NUIT QUI S'EN OCCUPE
else {
if (jourNuit.intensity < 0.15f) {
if (eclairage.activeInHierarchy == false)
eclairage.SetActive (true);
}
else {
if (eclairage.activeInHierarchy == true)
eclairage.SetActive (false);
}
}
}
}
}
Code : Tout sélectionner
void OnTriggerEnter (Collider other)
{
// Si le collider est tagué TUNNEL et que ce script est attaché a un objet tagué VEHICULE ou VELO
if (other.tag == "TUNNEL" && (gameObject.tag == "VEHICULE" || gameObject.tag == "VELO"))
Code : Tout sélectionner
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
/*
script à mettre sur tous les vehicules et les vélos
Pour allumer/éteindre dans un tunnel , tous les feux des véhicules ou des velos faire un objet 3D de la forme du tunnel
et le tagguer en TUNNEL
*/
public class TunnelAllumageDesFeux : MonoBehaviour {
private bool dansUnTunnel = false;
private GameObject eclairage;
private Light jourNuit;
public void DemarageVl () {
jourNuit = GameObject.Find("Sky Dome").transform.FindChild("Light").GetComponent<Light>();
//cherche dans ces enfants un object avec le nom Eclairage
//si existe alors on ajoute l'object portant le nom "Eclairage" dans la variable eclairage
if (this.transform.FindChild ("Eclairage")) {
eclairage = this.transform.FindChild ("Eclairage").gameObject;
}
}
void OnTriggerEnter(Collider other) //ENTREE DU TUNNEL
//le collider MAYA 3D en forme de tunnel doit etre tagué TUNNEL et que ce script est attaché a un objet tagué VEHICULE ou VELO
{
if (other.tag == "TUNNEL" && (gameObject.tag == "VEHICULE" || gameObject.tag == "VELO"))
{
dansUnTunnel = true;
}
}
void OnTriggerExit(Collider other) //SORTIE DU TUNNEL (UN SEUL COLLIDER ENTIER MAYA 3D en forme de tunnel)
{
if (other.tag == "TUNNEL" && (gameObject.tag == "VEHICULE" || gameObject.tag == "VELO"))
{
dansUnTunnel = false;
}
}
void AllumageExtinctionDesFeux() {
if (eclairage != null)
{
// SI TU ES DANS UN TUNNEL TU ALLUMES LES FEUX QUEL QUE SOIT LE JOUR/NUIT
if (dansUnTunnel) {
eclairage.SetActive (true);
}
// SINON C'EST LE JOUR/NUIT QUI S'EN OCCUPE
else {
if (jourNuit.intensity < 0.15f) {
if (eclairage.activeInHierarchy == false)
eclairage.SetActive (true);
}
else {
if (eclairage.activeInHierarchy == true)
eclairage.SetActive (false);
}
}
}
}
}
Code : Tout sélectionner
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
// la fonction de trajet aérien est bloquée
/* Create by :
* Fabian Métayer
* 27/10/2015
*
* Modifle 15-1-2019 pour véhicules et perso escalier
*
*/
public class TrajetVl : MonoBehaviour {
public GameObject target_Path;
public float kmh; // vitesse voulue
public float kmhActuel; // vitesse reelle
public float mEntrePoint = 5.0f;
private float time;
public float fraction;
public Transform[] tabtList = new Transform[11];
public int minTab = 0;
public Transform detecteur;
public LayerMask layerPanneau;
public Collider[] toucheDetecteur;
public bool coupeDetecteur;
private Light jourNuit; //private
private GameObject eclairage; //private
private bool dansUnTunnel = false; // pour allumage des feux dans un tunnel, le tunnel est tagué en TUNNEL et a la forme 3D du tunnel réel
private GameObject eclairageFreins;
public GameObject clignotantsDroits;
public GameObject clignotantsGauche;
private IEnumerator coroutineClignotants;
public InterieurVl interieur;
public void DemrageVl () {
tabtList = new Transform[11];
TabDynamique ();
if (transform.FindChild("Detecteur"))
detecteur = transform.FindChild("Detecteur").transform;
jourNuit = GameObject.Find("Sky Dome").transform.FindChild("Light").GetComponent<Light>();
//cherche dans ces enfants un object avec le nom Eclairage
//si existe alors on ajoute l'object portant le nom "Eclairage" dans la variable eclairage
if (this.transform.FindChild ("Eclairage")) {
eclairage = this.transform.FindChild ("Eclairage").gameObject;
}
if (this.transform.FindChild ("Eclairage_Freins")) {
eclairageFreins = this.transform.FindChild ("Eclairage_Freins").gameObject;
eclairageFreins.SetActive (false);
}
if (this.transform.FindChild ("Eclairage_Clignotants_droits")) {
clignotantsDroits = this.transform.FindChild ("Eclairage_Clignotants_droits").gameObject;
clignotantsDroits.SetActive (false);
}
if (this.transform.FindChild ("Eclairage_Clignotants_gauche")) {
clignotantsGauche = this.transform.FindChild ("Eclairage_Clignotants_gauche").gameObject;
clignotantsGauche.SetActive (false);
}
StartCoroutine("WalkThePath");
}
public void TabDynamique () {
fraction = 0.1f;
int count = 0;
for (int i = 0; i < 11; i++) {
if (minTab+i < target_Path.transform.childCount) {
tabtList[i] = target_Path.transform.GetChild(minTab+i);
count++;
}
}
if (minTab+8 < target_Path.transform.childCount)
minTab += 8;
else
minTab += count;
}
public void StopCoroutine () {
StopCoroutine("WalkThePath");
}
/*
// version du createur DOTWEENN
void LateUpdate () {
//nombre de point * distance entre point / km/h / 3.6
time = (tabt.Length * mEntrePoint)/(kmh / 3.6f);
if (start) {
transform.position = iTween.PointOnPath(tabt, fraction);
fraction += Time.deltaTime / time;
if (fraction > 1.0f)
fraction = 0.0f;
transform.LookAt(iTween.PointOnPath(tabt, fraction + 0.001f));
}
}*/
IEnumerator WalkThePath () {
while(true){
time = ((tabtList.Length * mEntrePoint)/(kmhActuel / 3.6f)*0.88f);// original (tabtList.Length * mEntrePoint)/(kmhActuel / 3.6f)
/*
scene 2x2
362 x 5m = 1 810m
130 kmh/h fait 36.1111 mn/s donc 1 810m à 130km/h fait 50 sec / 55 sec réelles donc x0.91 pour avoir 50 sec
110 kmh/h fait 30.5555 mn/s donc 1 810m à 110km/h fait 59 sec / 64 sec réelles donc x0.91 pour avoir 59 sec
scene bi-di
305 x 5m = 1 525m
90 kmh/h fait 25 mn/s donc 1 525m à 90km/h fait 61 sec / 66 sec réelles donc x0.91 pour avoir 60 sec
50 kmh/h fait 13.888 mn/s donc 1 525m à 50km/h fait 110 sec/ 117 sec réelles donc x0.91 pour avoir 107 sec
*/
transform.position = iTween.PointOnPath (tabtList, fraction);
fraction += Time.deltaTime / time;
if (fraction > 1.0f)
fraction = 0.0f;
/* modif pour vehicule ou personnage*/
if (gameObject.tag == "VEHICULE")
{
transform.LookAt(iTween.PointOnPath(tabtList, fraction + 0.08f)); //0.05F plus c'est petit est plus de tremblote pour s'orienter sur le point à 0.005m
}
/*else
{
Vector3 direction =iTween.PointOnPath(tabtList, fraction + 0.08f); //0.05F
direction.y = this.transform.position.y;
transform.LookAt(direction);
}*/
if (gameObject.tag == "VELO")
{
transform.LookAt(iTween.PointOnPath(tabtList, fraction + 0.08f)); //0.05F plus c'est petit est plus de tremblote pour s'orienter sur le point à 0.005m
}
/*else
{
Vector3 direction =iTween.PointOnPath(tabtList, fraction + 0.08f); //0.05F
direction.y = this.transform.position.y;
transform.LookAt(direction);
}*/
if (gameObject.tag == "PIETON")
{
Vector3 direction =iTween.PointOnPath(tabtList, fraction + 0.08f); //0.05F pour que le pieton reste vertical
direction.y = this.transform.position.y;
transform.LookAt(direction);
}
/*else
{
Vector3 direction =iTween.PointOnPath(tabtList, fraction + 0.08f); //0.05F
direction.y = this.transform.position.y;
transform.LookAt(direction);
}*/
if (kmhActuel < kmh){
kmhActuel += 0.7f;// acceleration jusqu'à la vitesse kmh 0.7f
} else if (kmhActuel > kmh && kmh != 0) {
kmhActuel -= 0.9f;// decceleration douce 0.9
} else if (kmh == 0) {
kmhActuel = 0;// on stoppe brutalement le VL
}
if (fraction >= 0.9f) //0.9f
TabDynamique();
GestionDetecteur ();
GestionLumiere ();
GestionFreins ();
yield return null;
}
}
void GestionDetecteur () {
if (detecteur != null) {
if (gameObject.tag == "VEHICULE")
toucheDetecteur = Physics.OverlapSphere(detecteur.position, 0.75f, layerPanneau);
else
toucheDetecteur = Physics.OverlapSphere(detecteur.position, 0.5f, layerPanneau);
if (toucheDetecteur.Length != 0) {
foreach (Collider other in toucheDetecteur) {
if (other.tag == "CoupeDetecteur") {
coupeDetecteur = other.GetComponent<CoupeDetecteur>().detecteur;
kmhActuel = 30.0f;// pour degager les croisements à 30 km/h
// tant que la sphere du détecteur est dans l'objet sa vitesse est de 30 km/h
// apres le VL reprend sa vitesse normale
}
if (other.tag == "CoupeDetecteurAutre") {
coupeDetecteur = other.GetComponent<CoupeDetecteur>().detecteur;
kmhActuel = 4.0f;
}
/////// Pour que vehicule se mette à la vitesse du velo s'il est devant
if (other.tag == "VELO") {
coupeDetecteur = other.GetComponent<TrajetVl>().detecteur;
kmhActuel = other.GetComponent<TrajetVl>().kmh; //
}
//////////////////////////
if (coupeDetecteur == false) {
if (other.tag == "ModifVitesse") {
kmh = other.GetComponent<Panneau>().vitesse;
} else if (other.tag == "EntreeInstersection") {
kmh = GetPrioriteVitesse(other);
} else if (other.tag == "VEHICULE") {
if (kmh > other.GetComponent<TrajetVl>().kmh)
kmh = other.GetComponent<TrajetVl>().kmh;
} else if (other.tag == "ClignotantsOn") {
kmh = other.GetComponent<GestionClignotants>().vitesse;
if (other.GetComponent<GestionClignotants>().trajet == target_Path) {
ClignotantsOff ();
if (other.GetComponent<GestionClignotants>().enumClignotants == EnumClignotants.Droites) {
coroutineClignotants = ClignotantsDroits();
StartCoroutine (coroutineClignotants);
} else {
coroutineClignotants = ClignotantsGauche();
StartCoroutine (coroutineClignotants);
}
}
} else if (other.tag == "ClignotantsOff") {
kmh = other.GetComponent<GestionClignotants>().vitesse;
ClignotantsOff ();
}
}
}
}
if (kmhActuel == 0 && toucheDetecteur.Length == 0)
kmhActuel = 30.0f;
}
}
//------------------------------------------------------------------------------------
// allumage et extinction des feux dans un tunnel
void OnTriggerEnter(Collider other) //ENTREE DU TUNNEL
//le collider MAYA 3D en forme de tunnel doit etre tagué TUNNEL et que ce script est attaché a un objet tagué VEHICULE ou VELO
{
if (other.tag == "TUNNEL" && (gameObject.tag == "VEHICULE" || gameObject.tag == "VELO"))
{
dansUnTunnel = true;
}
}
void OnTriggerExit(Collider other) //SORTIE DU TUNNEL (UN SEUL COLLIDER ENTIER MAYA 3D en forme de tunnel)
{
if (other.tag == "TUNNEL" && (gameObject.tag == "VEHICULE" || gameObject.tag == "VELO"))
{
dansUnTunnel = false;
}
}
// ------------------------------
void GestionLumiere () {
if (eclairage != null)
{
// SI TU ES DANS UN TUNNEL TU ALLUMES LES FEUX QUEL QUE SOIT LE JOUR/NUIT
if (dansUnTunnel) {
eclairage.SetActive (true);
}
// SINON C'EST LE JOUR/NUIT QUI S'EN OCCUPE
else {
if (jourNuit.intensity < 0.15f) {
if (eclairage.activeInHierarchy == false)
eclairage.SetActive (true);
}
else {
if (eclairage.activeInHierarchy == true)
eclairage.SetActive (false);
}
}
}
}
void GestionFreins () {
if (eclairageFreins != null){
if (kmhActuel > kmh+3 || kmhActuel == 0) {
if (eclairageFreins.activeInHierarchy == false)
eclairageFreins.SetActive (true);
} else {
if (eclairageFreins.activeInHierarchy == true)
eclairageFreins.SetActive (false);
}
}
}
IEnumerator ClignotantsDroits () {
if (clignotantsDroits != null) {
while (true) {
clignotantsDroits.SetActive (true);
yield return new WaitForSeconds (0.3f);
clignotantsDroits.SetActive (false);
yield return new WaitForSeconds (0.3f);
}
}
}
IEnumerator ClignotantsGauche () {
if (clignotantsGauche != null) {
while (true) {
clignotantsGauche.SetActive (true);
yield return new WaitForSeconds (0.3f);
clignotantsGauche.SetActive (false);
yield return new WaitForSeconds (0.3f);
}
}
}
void ClignotantsOff () {
if (coroutineClignotants != null) {
StopCoroutine (coroutineClignotants);
if (clignotantsDroits != null)
clignotantsDroits.SetActive (false);
if (clignotantsGauche != null)
clignotantsGauche.SetActive (false);
coroutineClignotants = null;
}
}
float GetPrioriteVitesse(Collider other){
Priorite priorite = other.GetComponent<Priorite> ();
if (priorite != null) {
return priorite.vitesse;
} else {
PrioriteOllioules prioriteOllioules = other.GetComponent<PrioriteOllioules> ();
return prioriteOllioules.vitesse;
}
}
}