|
|
@ -10,10 +10,9 @@ using UnityEngine.AI;
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public class CarSys : MonoBehaviour
|
|
|
|
public class CarSys : MonoBehaviour
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
//计时器
|
|
|
|
//计时器
|
|
|
|
private float timer = 0f;
|
|
|
|
private float timer = 0f;
|
|
|
|
//车辆生成间隔
|
|
|
|
|
|
|
|
public float bornTime = 10;
|
|
|
|
|
|
|
|
//车辆种类列表
|
|
|
|
//车辆种类列表
|
|
|
|
public GameObject[] carList;
|
|
|
|
public GameObject[] carList;
|
|
|
|
|
|
|
|
|
|
|
@ -59,8 +58,10 @@ public class CarSys : MonoBehaviour
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (lineName != "" && agent != null)
|
|
|
|
if (lineName != "" && agent != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
Transform moveListParent = null;
|
|
|
|
Transform moveListParent = null;
|
|
|
|
MoveList.TryGetValue(lineName,out moveListParent);
|
|
|
|
MoveList.TryGetValue(lineName,out moveListParent);
|
|
|
|
|
|
|
|
|
|
|
|
if (moveListParent != null)
|
|
|
|
if (moveListParent != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Transform[] moveList=new Transform[moveListParent.childCount];
|
|
|
|
Transform[] moveList=new Transform[moveListParent.childCount];
|
|
|
@ -70,6 +71,7 @@ public class CarSys : MonoBehaviour
|
|
|
|
moveList[i] = moveListParent.GetChild(i);
|
|
|
|
moveList[i] = moveListParent.GetChild(i);
|
|
|
|
if (moveList[i] != null)
|
|
|
|
if (moveList[i] != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
//向移动列表支点移动
|
|
|
|
//向移动列表支点移动
|
|
|
|
agent.speed = 20;
|
|
|
|
agent.speed = 20;
|
|
|
|
agent.SetDestination(moveList[i].position);
|
|
|
|
agent.SetDestination(moveList[i].position);
|
|
|
@ -77,8 +79,9 @@ public class CarSys : MonoBehaviour
|
|
|
|
while (true)
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//*********************//
|
|
|
|
//*********************//
|
|
|
|
yield return new WaitForEndOfFrame();
|
|
|
|
yield return new WaitForSeconds(0.02f);
|
|
|
|
float distance = Vector3.Distance(agent.transform.position, moveList[i].position);
|
|
|
|
float distance = Vector3.Distance(agent.transform.position, moveList[i].position);
|
|
|
|
|
|
|
|
|
|
|
|
if(distance <= 40f)
|
|
|
|
if(distance <= 40f)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
agent.speed = 10;
|
|
|
|
agent.speed = 10;
|
|
|
@ -124,8 +127,11 @@ public class CarSys : MonoBehaviour
|
|
|
|
if (parent != null)
|
|
|
|
if (parent != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int carIndex = Random.Range(0, carList.Length-1);
|
|
|
|
int carIndex = Random.Range(0, carList.Length-1);
|
|
|
|
|
|
|
|
//实例化车辆
|
|
|
|
GameObject car = GameObject.Instantiate(carList[carIndex],parent.position,Quaternion.identity,parent);
|
|
|
|
GameObject car = GameObject.Instantiate(carList[carIndex],parent.position,Quaternion.identity,parent);
|
|
|
|
car.transform.localEulerAngles = parent.localEulerAngles;
|
|
|
|
car.transform.localEulerAngles = parent.localEulerAngles;
|
|
|
|
|
|
|
|
//统计数量更新
|
|
|
|
|
|
|
|
GameRoot.Instance.infoWnd.SetCarText(1);//+1
|
|
|
|
//执行寻路AI
|
|
|
|
//执行寻路AI
|
|
|
|
NavMeshAgent agent = car.GetComponent<NavMeshAgent>();
|
|
|
|
NavMeshAgent agent = car.GetComponent<NavMeshAgent>();
|
|
|
|
if (agent != null)
|
|
|
|
if (agent != null)
|
|
|
|