首页 > 编程语言 > 详细

Unity (三) NavMeshAgent之:分层路面导航(王者荣耀,英雄联盟中小兵分三路进攻敌方)

时间:2017-08-23 19:44:56      阅读:1456      评论:0      收藏:0      [点我收藏+]

效果:

 

 

技术分享

 

运用分层路面导航让角色走不同的导航路线

 

1、新建一个静态地图

 

 技术分享

 

 

 

2、设置3个不同的层

 技术分享

 

 

 

3、给不同的路面设置不同的导航层

 技术分享

 

4、在导航组件里给角色设置Area Mask,设置角色可以走哪些层

 

1)设置char_ethan不能走Sap(下路),middle(中路)层

技术分享

 

 

 

 

 

2)设置SapphiArtchan不能走Char(上路),middle(中)层

 技术分享

 

 

 

 

5、给SapphiArtchan和char_ethan添加脚本:

 

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.AI;

public class NavigationTest : MonoBehaviour {

  private Animator animator; //行走动画

  private NavMeshAgent agent; //导航组件

  private Transform target; //目标位置

  void Start () {

  animator = GetComponent<Animator>();

  agent = GetComponent<NavMeshAgent>();

  target = GameObject.Find("target").transform;

  }

void Update () {

  if (Input.GetKeyDown(KeyCode.Space)) //按空格键

  {

  agent.SetDestination(target.position); //开始导航

  animator.SetBool("walk", true); //行走动画开启

  }

  if (Vector3.Distance(target.position,transform.position)<=1.5f) //如果到达目标1.5m

  {

  agent.isStopped = true; //结束

  animator.SetBool("walk", false); //结束行走

 

  }

}

}

 


 

 

 

 

Unity (三) NavMeshAgent之:分层路面导航(王者荣耀,英雄联盟中小兵分三路进攻敌方)

原文:http://www.cnblogs.com/yugejuhao/p/7419773.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!