C#实现U3D简单寻路
2017-06-19 20:57
288 查看
继续学习c#。。
简单的寻路,用的是U3D自带的算法,代码如下
和之前的相机跟随一块的效果
因为没有障碍物所以并没有完全体现出寻路的效果
简单的寻路,用的是U3D自带的算法,代码如下
using System.Collections; public class Player : MonoBehaviour { public NavMeshAgent agent; Vector3 point; Ray aray; RaycastHit ahit; public GameObject targetPoint; void Start() { targetPoint.active=false; } void Update () { if(Input.GetMouseButtonDown (0)) { aray=Camera.main.ScreenPointToRay(Input.mousePosition); if(Physics.Raycast(aray,out ahit)) { point=ahit.point; //Instantiate(targetPoint,point,transform.rotation); targetPoint.active=true; targetPoint.transform.position=point; } } agent.SetDestination(point); } }
和之前的相机跟随一块的效果
因为没有障碍物所以并没有完全体现出寻路的效果
相关文章推荐
- Command模式的C#简单实现
- [C#]简单XP菜单的实现(一)
- 一个简单的AJAX实现,基于C#的ASP.Net,包括服务器端的程序代码
- 如何用C#在winform中实现简单的查找功能
- 用C#实现简单的控件数组
- 内容分页简单实现代码及祥解(C#)
- xmlHTTP xmlDOC 与 C#中DataSet的结合 实现AJAX简单示例
- 在C#中实现托盘是多么简单
- C#的附件上传的简单实现
- 自定义线程池-c#的简单实现
- c# 中实现 winxp 风格的控件(超简单-zz)
- 用C#实现简单下载 (原创)
- C#2.0 - Object Pool 简单实现
- 一个简单的AJAX实现,基于C#的ASP.Net,包括服务器端的程序代码
- 用C#简单实现主表与子表的联动关系
- 用C#实现的简单PL0 to C 编译器
- C#实现简单WEB服务器
- 用C#实现简单的字幕动态叠加效果
- 一个C#实现的最简单的委托例子
- xmlHTTP xmlDOC 与 C#中DataSet的结合 实现AJAX简单示例