5.10导航系统

Nav Mesh Agent 自动寻路(添加在移动的物体上)

Off Mesh Link分离路面(添加在跳跃的起始点的其中一个点上)

Nav Mesh Obstacle动态障碍(添加在障碍物上)

运动的物体都不能设置为Static

usingUnityEngine;

usingSystem.Collections;

publicclassNavigationScript:MonoBehaviour{

private NavMeshAgent  agent;

public  Transform[ ]  targetTransform;

float time;

private  int  TargetIndex=1;

voidStart( ){

agent=GetComponent( );

}

voidUpdate( ){

//走到鼠标点击的位置

//if(Input.GetMouseButtonDown(0)){

//  agent.destination = targetTransform.position;


物体移动到鼠标点击的位置

//   RaycastHit   hit;

//if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition),out  hit)){

//if(hit.collider.name.Contains("Plane")){

////设置目标点

//agent.destination=hit.point;

//}

//}

//}

//if(Input.GetKeyDown(KeyCode.Alpha1)){

//agent.areaMask=9;

//GameObject.Find("Road2").SetActive(false);

//}

//if(Input.GetKeyDown(KeyCode.Alpha2)){

//agent.areaMask=17;

//GameObject.Find("Road1").SetActive(false);

//}



//巡逻

if(agent.remainingDistance==0){

time+=Time.deltaTime;

if(time>=3.0f){

TargetIndex++;

//目标点循环更改

TargetIndex=TargetIndex%targetTransform.Length;

//设置目标点

agent.destination=targetTransform[TargetIndex].position;

time=0.0f;

}

}else{

agent.destination=targetTransform[TargetIndex].position;

}

//if(Input.GetMouseButtonDown(0)){

//if(gameObject.name=="Player1"){

//agent.destination=targetTransform[1].position;

//}else{

//agent.destination=targetTransform[0].position;

//}

//}

}

}

你可能感兴趣的:(5.10导航系统)