Pour jouer sur la vitesse c'est un cube trigger , tag ModifVitesse et layer PanneauPieton, avec ce script
Code : Tout sélectionner
using UnityEngine;
using System.Collections;
public class Panneau : MonoBehaviour {
//choix vitesse du panneau
public float vitesse;
}
le personnage
www.grosfichiers.com/28Hq6zmSTGw
Le perso est fait avec
un empty Parent , tag PIETON et layer pietons, Rigidbody, capsule collider et 2 scripts : SelectVl et TrajetVl
TrajetVl est basé sur ItWeen
avec en enfants dans Hierarchy
un Detecteur (mesh collider)
2 cameras
Le corps du perso (avec des scripts)
- Z003.jpg (270.01 Kio) Consulté 4349 fois
SelectVL
Code : Tout sélectionner
using UnityEngine;
using System.Collections;
public class SelectVl : MonoBehaviour {
void OnMouseUp () {
GameObject.Find ("GestionCamera").GetComponent<GestionSelectionVl>().SelectVl (transform.gameObject);
}
}
et le principal de mon programme . C'est lui qui a kmh et kmhActuel
TarjetVL
Code : Tout sélectionner
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
// la fonction de trajet aérien est bloquée
/* Aidé by :
* Fabian Métayer
* 27/10/2015
*/
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 GameObject eclairage;
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");
}
IEnumerator WalkThePath () {
while(true){
time = (tabtList.Length * mEntrePoint)/(kmhActuel / 3.6f);
transform.position = iTween.PointOnPath (tabtList, fraction);
fraction += Time.deltaTime / time;
if (fraction > 1.0f)
fraction = 0.0f;
transform.LookAt(iTween.PointOnPath(tabtList, fraction + 0.1f));
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 (var other in toucheDetecteur) {
if (other.tag == "CoupeDetecteur") {
coupeDetecteur = other.GetComponent<CoupeDetecteur>().detecteur;
kmhActuel = 50.0f;// pour degager les croisements
}
if (other.tag == "CoupeDetecteurAutre") {
coupeDetecteur = other.GetComponent<CoupeDetecteur>().detecteur;
kmhActuel = 4.0f;
}
if (coupeDetecteur == false) {
if (other.tag == "ModifVitesse") {
kmh = other.GetComponent<Panneau>().vitesse;
} else if (other.tag == "EntreeInstersection") {
kmh = other.GetComponent<Priorite>().vitesse;
} 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;
}
}
}
ensuite sur le corps du perso , tag PIETON et layer pietons, avec le script PietonAnimationEscalier
Animation ( les 3 , la quatrième ,descente escalier, je dois la faire)
- Z004.jpg (237.48 Kio) Consulté 4349 fois
La création des perso se fait un partir de ce script
choix du perso aléatoire dans un groupe donné, et choix de sa texture aléatoire
Code : Tout sélectionner
using UnityEngine;
using System.Collections;
public class DebutRouteAutre1Groupe : MonoBehaviour {
public string chemin_Nom;
public int nombres;
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 = new float[0]; // dans inspector donner le nombre de temsp puis les renseigner
//choisis un temps aléatoire
private int choixTemps;
private float temps;
private bool finStart;
private Light jourNuit;
void Start () {
choixTemps = UnityEngine.Random.Range(0,tempsApparition.Length);
choixTrajet = UnityEngine.Random.Range(0,trajets.Length);
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].trajet, trajets[choixTrajet].mEntrePoint, trajets[choixTrajet].vitesse, 0);
choixTemps = UnityEngine.Random.Range(0,tempsApparition.Length);
choixTrajet = UnityEngine.Random.Range(0,trajets.Length);
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].trajet, trajets[countTrajet].mEntrePoint, trajets[countTrajet].departVl[i].vitesseDepart, trajets[countTrajet].departVl[i].positionDepart);
}
}
}
public void CreationVl (GameObject trajet, float metre, float vitesseFraction, int position) {
int choixVl = UnityEngine.Random.Range(1,nombres+1);
GameObject instance = Instantiate(Resources.Load(""+chemin_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>().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>().DemrageVl();
}
}
}
Merci beaucoup