private void Start() { //Removes all useless stuff after creating the path Destroy(gameObject, waitTime); //Get the roadtemplate object form the hierarchy only during the start of this object roadTemplates = GameObject.FindGameObjectWithTag("Roads").GetComponent <RoadTemplates>(); //Call the CreateRoad methode with 0.2 seconds delay Invoke("CreateRoad", .15f); }
/* * Genère une voiture toutes les N secondes */ private void InstantiateVehicle() { GameObject Scripts = GameObject.Find("Scripts"); MapGenerator mapGenerator = Scripts.GetComponent <MapGenerator>(); grid = mapGenerator.grid; RoadTemplates road = GetComponentInParent <RoadTemplates>(); J = Mathf.Abs((int)road.transform.position.x) / mapGenerator.GetRoadSize; I = Mathf.Abs((int)road.transform.position.z) / mapGenerator.GetRoadSize; Vehicule tmpCar = cars[Random.Range(0, cars.Length)].GetComponent <Vehicule>(); tmpCar.PathNode = new List <Node>(); getNodesFromMap(tmpCar, I, J); var SpawnPoint = gameObject.transform.Find("SpawnPoint"); Instantiate(tmpCar, SpawnPoint.position, Quaternion.identity); }
private IEnumerator InstantiateFromNSecond(float seconds) { while (true) { yield return(new WaitForSeconds(seconds)); GameObject Scripts = GameObject.Find("Scripts"); MapGenerator mapGenerator = Scripts.GetComponent <MapGenerator>(); grid = mapGenerator.grid; RoadTemplates road = GetComponentInParent <RoadTemplates>(); J = Mathf.Abs((int)road.transform.position.x) / mapGenerator.GetRoadSize; I = Mathf.Abs((int)road.transform.position.z) / mapGenerator.GetRoadSize; Vehicule tmpCar = cars[Random.Range(0, cars.Length)].GetComponent <Vehicule>(); tmpCar.PathNode = new List <Node>(); getNodesFromMap(tmpCar, I, J); var SpawnPoint = gameObject.transform.Find("SpawnPoint"); Instantiate(tmpCar, SpawnPoint.position, Quaternion.identity); } }
void Start() { roadTemplates = GameObject.FindGameObjectWithTag("Roads").GetComponent <RoadTemplates>(); roadTemplates.roads.Add(this.gameObject); roadTemplates.waitTime = 1f; }