zoukankan      html  css  js  c++  java
  • 《Unity3D-自动寻路功能的实现》

    //思路:自动寻路是根据场景中NavMeshAgent的功能,来自于AI的引用集。利用渲染以后的目标的位置设置来跟踪目标的位置

    //注意点:此方法中旧的stop和resume方法已经弃用了

    代码:

    // 1.设置追踪点

    private NavMeshAgent agent;

    private Transform player;   //2.设置目标点

    void Awake(){

      agent=this.GetComponent<NavMeshAgent>();  //3.初始化追踪点

    }

    void Start(){

      player=GameObject.FindGameObjectWithTag("Player").transform;  //4.初始化目标点

    }

    void Updata(){

      if(Vector3.Distance(transform.position,palyer.position)<3f){  //6.判断如果目标点的位置小鱼2f的时候

      agent.isStop=true;  //6.1追踪点停止追踪

    }else{

      agent,isStop=false;  //6.2追踪点开始追踪

      agent.SetDestination(palyer.position);  //5.设置追踪点的目标位置

    }

    }

  • 相关阅读:
    51nod1260
    51nod1327
    51nod1342
    51nod1479
    LOJ6088
    51nod1634
    51nod1778
    JAVA循环结构学校上机经常遇到的几题 笔记
    B. The Number of Products(Codeforces Round #585 (Div. 2))
    A. Yellow Cards ( Codeforces Round #585 (Div. 2) 思维水题
  • 原文地址:https://www.cnblogs.com/ylllove/p/7266006.html
Copyright © 2011-2022 走看看