美文网首页
5.10导航系统

5.10导航系统

作者: 胤醚貔貅 | 来源:发表于2017-05-10 16:20 被阅读29次

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<NavMeshAgent>( );

}

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导航系统

    Nav Mesh Agent 自动寻路(添加在移动的物体上) Off Mesh Link分离路面(添加在跳跃的起始...

  • 基于GPS和INS组合导航软硬件系统设计 毕业论文+项目源码

    摘要 单独的GPS或者INS导航系统,都存在自己的固有缺陷。GPS/INS组合导航系统以GPS导航系统为主,INS...

  • Qml动态语言切换

    此方法需要在Qt5.10或更高版本实现, 在Qt5.10或更高版本实现, 在Qt5.10或更高版本实现重要的事情说...

  • what i have done for saving and

    5.10 buy the cheapest vegetable in the market and cook by...

  • 5.10

    今天是第六天了 爱上了食堂的茶叶蛋和糯玉米,不过玉米也不能多吃呀。发现一餐的玉米比二餐贵五毛,哼唧。 10点,从工...

  • 5.10

    今天又被拉去做实验了,很幸运,这次实验很成功,然后就是不断的测试数据,做实验是件很严谨的事情,要不断的去验证,一定...

  • 5.10

    一恨海棠无香 二恨鲫鱼多刺 三恨红楼梦未完

  • 5.10

  • 5.10

    中午跟同事吃饭,讨论了一些业务问题,还是比较容易开展,明天可以在准备一些。 明天参加正面管教的讲座,晚上回去预习一下书。

  • 5.10

    上午一起讨论了如何聊天,回想自己以前聊天方式,就是很公式化,没有很多赞美,客户问啥答啥。 首先不敏感的问题可以回答...

网友评论

      本文标题:5.10导航系统

      本文链接:https://www.haomeiwen.com/subject/axdgtxtx.html