Unity之 - 导航网格寻路
2016-03-17 00:06
507 查看
地板、箱子、斜坡等行走路面设置,设置完点Bake。
挂上NavMeshAgent 和 脚本
SmartPlayer 物体行至鼠标所点位置
Follower 物体行至target所在位置
挂上NavMeshAgent 和 脚本
SmartPlayer 物体行至鼠标所点位置
using UnityEngine; using System.Collections; public class SmartPlayer : MonoBehaviour { NavMeshAgent agent; void Start() { agent = GetComponent<NavMeshAgent>(); } void Update() { RaycastHit hit; if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) agent.SetDestination(hit.point); } } }
Follower 物体行至target所在位置
using UnityEngine; using System.Collections; public class Follower : MonoBehaviour { public Transform target; private NavMeshAgent agent; // Use this for initialization void Start() { agent = GetComponent<NavMeshAgent>(); } // Update is called once per frame void Update() { if (target != null) agent.destination = target.position; } }
相关文章推荐
- unity实现多点触控代码
- 在Unity中实现动画的正反播放代码
- unity实现摄像头跟随
- Unity3D上路_01-2D太空射击游戏
- Unity3D上路_02-第一视角射击游戏
- Unity3D上路_03-塔防游戏
- Unity3D上路_04-基础资源介绍
- Unity3D上路_05-网络相关
- [软件资讯]Unity已支持将3D游戏导出成Flash
- Unity 武器拖尾效果
- unity常见问题之20题
- Unity3D动画存储插件
- unity 赛车相机跟随物体移动
- uLua中遇到的问题
- Unity3d 协程、调用函数、委托
- Unity3d摄像机Camera参数详解
- Unity3d多线程
- 猫都能学会的Unity3D Shader入门指南(一)
- iTween基础之Move(移动)
- Unity3d之Http通讯GET方法和POST方法