public Queue <RoadPart> GenerateStartRoads() { if (conteiner != null) { return(roadParts); } float _startSpace = startSpace * 8; conteiner = new GameObject(); roadParts = new Queue <RoadPart>(); GameObject road = GameObject.FindObjectOfType <Road>().gameObject; conteiner.transform.SetParent(road.transform); conteiner.name = "RoadConteiner"; for (int i = 0; i < 5; i++) { GameObject roadPart = GameObject.Instantiate(roadPartPref, conteiner.transform); roadPart.transform.localPosition = new Vector3(0, 0, _startSpace + (i * 8 * partLength) + i * partIntervalLength * 8); RoadPart rp = roadPart.AddComponent <RoadPart>(); rp.SetRowCount(roadwaysCount); rp.SetLength(partLength); roadParts.Enqueue(rp); } return(roadParts); }
public void GenerateObstencle(RoadPart rp, int roadwaysCount, int length) { if (dencity > 0) { Obstencle[,] obstencles = new Obstencle[length, roadwaysCount]; for (int x = 0; x < length; x++) { int n = 0; for (int y = 0; y < roadwaysCount; y++) { if (UnityEngine.Random.Range(0, 3) < dencity) { int i = UnityEngine.Random.Range(0, roadwaysCount); if (obstencles[x, i] == null) { GameObject obst = GameObject.Instantiate(obstenclePrefs[UnityEngine.Random.Range(0, obstenclePrefs.Length)]); obst.transform.localPosition = new Vector3(-(((roadwaysCount * 3) / 2) - 1.5f) + 3 * i, 0, 0); obstencles[x, i] = obst.GetComponent <Obstencle>(); n++; } if (dencity == 1) { break; } if (n == roadwaysCount - 1) { break; } } } } rp.SetObstencle(obstencles); } }
public void AddNewRoad() { GameObject.Destroy(roadParts.Dequeue().gameObject); GameObject roadPart = GameObject.Instantiate(roadPartPref, conteiner.transform); roadPart.transform.localPosition = new Vector3(0, 0, roadParts.Peek().transform.position.x + (4 * 8 * partLength) + 4 * partIntervalLength * 8); RoadPart rp = roadPart.AddComponent <RoadPart>(); rp.SetRowCount(roadwaysCount); rp.SetLength(partLength); roadParts.Enqueue(rp); //TODO: пофиксить GameObject.FindObjectOfType <Road>().obstencleGenerator.GenerateObstencle(rp, roadwaysCount, partLength); }