예제 #1
0
 void OnEnable()
 {
     if (script == null)
     {
         script = (TopDown2DNavMeshBaker)target;
     }
 }
예제 #2
0
        /// <summary>
        /// Set the target position of the agent.
        /// </summary>
        public void setTarget(Vector3 target)
        {
            this.target = target;
            target.z    = 0;
            // find the path
            if (TopDown2DNavMeshBaker.navMeshNodes == null)
            {
                TopDown2DNavMeshBaker.init();
            }
            NavMesh2DNode closestStart       = TopDown2DNavMeshBaker.navMeshNodes.findNearestNode(transform.position);
            NavMesh2DNode closestGoal        = TopDown2DNavMeshBaker.navMeshNodes.findNearestNode(target);
            List <IAStarable <Vector3> > map = new List <IAStarable <Vector3> > ();

            for (int i = 0; i < TopDown2DNavMeshBaker.navMeshNodes.nodes.Count; i++)
            {
                IAStarable <Vector3> newNode = (IAStarable <Vector3>)TopDown2DNavMeshBaker.navMeshNodes.nodes [i];
                newNode.heuristicFunction = () => {
                    return(Vector3.Distance(newNode.value, closestGoal.position));
                };
                map.Add(newNode);
            }
            StartCoroutine(AStarAlgorithm.findPath <Vector3> (map, (IAStarable <Vector3>)closestStart, (IAStarable <Vector3>)closestGoal, pathHandler));
        }