You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
3.2 KiB

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class GameManager : MonoBehaviour {
// 生成障碍物点列表
public List<Transform> bornPosList_Obstacle = new List<Transform>();
//生成道具点列表
public List<Transform> bornPosList_Tool = new List<Transform>();
// 道路列表
public List<Transform> roadList = new List<Transform>();
// 抵达点列表
public List<Transform> arrivePosList = new List<Transform>();
// 障碍物列表
public List<GameObject> objObstacleList = new List<GameObject>();
//道具列表
public List<GameObject> objToolList = new List<GameObject>();
// 目前的障碍物
Dictionary<string, List<GameObject>> objDict = new Dictionary<string, List<GameObject>>();
//目前的道具
Dictionary<string, List<GameObject>> objDict1 = new Dictionary<string, List<GameObject>>();
public int roadDistance;
public bool isEnd = false;
// Use this for initialization
[System.Obsolete]
void Start () {
foreach(Transform road in roadList)
{
List<GameObject> objList = new List<GameObject>();
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);
}
}
}