导航网格寻路
2016-01-15 07:51
232 查看
静态烘培
添加NavMeshAgent组件
让角色添加脚本控制
public Transform TraGoals; //寻路目标
private NavMeshAgent _Agent; //寻路代理
void
Start ()
{
//得到寻路代理
_Agent =
this.gameObject.GetComponent<NavMeshAgent>();
}//Start_end
void
Update ()
{
if(TraGoals)
{
if (_Agent)
{
//寻找目标
_Agent.SetDestination(TraGoals.transform.position);
}
}
斜坡与跳跃
使用Off-Mesh Link组件
添加脚本如下
using UnityEngine;
using
System.Collections;
public class
Tan_Finding : MonoBehaviour {
public Transform Destnation;
private NavMeshAgent _NavAgent;
//
Use this for initialization
void
Start () {
_NavAgent=gameObject.GetComponent<NavMeshAgent>
();
}
//
Update is called once per frame
void
Update () {
if (Destnation&&_NavAgent)
{
_NavAgent.SetDestination(Destnation.transform.position);
}
}
}
网格分层与Navmesh Obstacle组件
只允许通过红桥或者蓝桥
下图没有勾选Bridge_Blue ,代表选择Bridge_Blue通过
网格导航障碍物实验
脚本控制障碍物如下代码:
private NavMeshObstacle _Obstacle;
//
Use this for initialization
void
Start () {
_Obstacle =
this.GetComponent<NavMeshObstacle>();
}
//
Update is called once per frame
void
Update () {
if (_Obstacle)
{
if (Input.GetMouseButtonDown(0))
{
_Obstacle.enabled = false;
this.renderer.material.color =
Color.green;
}
if (Input.GetMouseButtonUp(0))
{
_Obstacle.enabled = true;
this.renderer.material.color =
Color.red;
}
}
}
来自为知笔记(Wiz)
添加NavMeshAgent组件
让角色添加脚本控制
public Transform TraGoals; //寻路目标
private NavMeshAgent _Agent; //寻路代理
void
Start ()
{
//得到寻路代理
_Agent =
this.gameObject.GetComponent<NavMeshAgent>();
}//Start_end
void
Update ()
{
if(TraGoals)
{
if (_Agent)
{
//寻找目标
_Agent.SetDestination(TraGoals.transform.position);
}
}
斜坡与跳跃
使用Off-Mesh Link组件
添加脚本如下
using UnityEngine;
using
System.Collections;
public class
Tan_Finding : MonoBehaviour {
public Transform Destnation;
private NavMeshAgent _NavAgent;
//
Use this for initialization
void
Start () {
_NavAgent=gameObject.GetComponent<NavMeshAgent>
();
}
//
Update is called once per frame
void
Update () {
if (Destnation&&_NavAgent)
{
_NavAgent.SetDestination(Destnation.transform.position);
}
}
}
网格分层与Navmesh Obstacle组件
只允许通过红桥或者蓝桥
下图没有勾选Bridge_Blue ,代表选择Bridge_Blue通过
网格导航障碍物实验
脚本控制障碍物如下代码:
private NavMeshObstacle _Obstacle;
//
Use this for initialization
void
Start () {
_Obstacle =
this.GetComponent<NavMeshObstacle>();
}
//
Update is called once per frame
void
Update () {
if (_Obstacle)
{
if (Input.GetMouseButtonDown(0))
{
_Obstacle.enabled = false;
this.renderer.material.color =
Color.green;
}
if (Input.GetMouseButtonUp(0))
{
_Obstacle.enabled = true;
this.renderer.material.color =
Color.red;
}
}
}
来自为知笔记(Wiz)
相关文章推荐
- AngularJS学习之directive自定义指令
- rails分段查询
- 开发者必知的几款App快速开发工具
- AngularJS学习之$digest循环和$apply
- 机器学习-非监督学习(Unüberwachte Lernverfahren)+大型数据库:Clustering-1
- ES6学习——集合(Collections):Set API
- 关于高级语言编译、操作系统、硬件的关系思考(二)
- OSChina 周五乱弹 —— 牛和鸡哪个贵?
- Akka TestKit测试包的使用
- PCB布局技巧
- web打印
- 再论sklearn分类器
- L3G4200陀螺仪学习
- 关于PEiD 0.95在Win7 Ultimate x64下崩溃的解决
- ADXL345知识学习总结
- 如何实现切换ViewController
- [LA] Orthogonal contrasts
- Akka框架基本要点介绍
- Akka Cluster原理与应用
- 到底该如何看待谭浩强的“C程序设计”