using UnityEngine; using System.Collections; using System.Collections.Generic; public class GameManager : MonoBehaviour { // 生成障碍物点列表 public List bornPosList_Obstacle = new List(); //生成道具点列表 public List bornPosList_Tool = new List(); // 道路列表 public List roadList = new List(); // 抵达点列表 public List arrivePosList = new List(); // 障碍物列表 public List objObstacleList = new List(); //道具列表 public List objToolList = new List(); // 目前的障碍物 Dictionary> objDict = new Dictionary>(); //目前的道具 Dictionary> objDict1 = new Dictionary>(); public int roadDistance; public bool isEnd = false; // Use this for initialization [System.Obsolete] void Start () { foreach(Transform road in roadList) { List objList = new List(); objDict.Add(road.name, objList); } initRoad(0); initRoad(1); } // Update is called once per frame void Update () { } // 切出新的道路 [System.Obsolete] public void changeRoad(Transform arrivePos) { int index = arrivePosList.IndexOf(arrivePos); if(index >= 0) { int lastIndex = index - 1; if (lastIndex < 0) lastIndex = roadList.Count - 1; // 移动道路 roadList[index].position = roadList[lastIndex].position + new Vector3(roadDistance, 0, 0); initRoad(index); } else { Debug.LogError("arrivePos index is error"); return; } } [System.Obsolete] void initRoad(int index) { string roadName = roadList[index].name; // 清空已有障碍物 foreach(GameObject obj in objDict[roadName]) { Destroy(obj); } //清空已有道具 /*foreach (GameObject obj in objDict1[roadName]) { Destroy(obj); }*/ objDict[roadName].Clear(); //objDict1[roadName].Clear(); // 添加障碍物 foreach (Transform pos in bornPosList_Obstacle[index]) { GameObject prefab = objObstacleList[Random.Range(0, objObstacleList.Count)]; Vector3 eulerAngle = new Vector3(0, Random.Range(0, 360), 0); GameObject obj = Instantiate(prefab, pos.position, Quaternion.EulerAngles(eulerAngle)) as GameObject; obj.tag = "Obstacle"; objDict[roadName].Add(obj); } //添加道具 foreach (Transform pos in bornPosList_Tool[index]) { GameObject prefab = objToolList[Random.Range(0, objToolList.Count)]; Vector3 eulerAngle = new Vector3(0, Random.Range(0, 360), 0); GameObject obj = Instantiate(prefab, pos.position, Quaternion.EulerAngles(eulerAngle)) as GameObject; obj.tag = "Tool"; objDict[roadName].Add(obj); } } }