Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections.Generic;
- using System.Linq;
- using System.Collections;
- public class AIEn : MonoBehaviour
- {
- public List<GameObject> open_list = new List<GameObject>(); //lista dei nodes che devono essere considerati per trovare il percorso
- public List<GameObject> closed_list = new List<GameObject>(); //lista dei nodes giĆ considerati
- public List<GameObject> adjacent_nodes = new List<GameObject>();
- public List<GameObject> path_nodes = new List<GameObject>(); //i nodes nella path finale
- public GameObject target;
- public GameObject my_node;
- GetClosestNode targ_node;
- GetClosestNode actual_node;
- NodeManager node_manager;
- EnemyVars en_vars;
- RaycastHit2D ray_dx;
- RaycastHit2D ray_sx;
- RaycastHit2D ray_up;
- RaycastHit2D ray_down;
- public int current_node = 0;
- float node_dist;
- Vector3 dest;
- void Update()
- {
- ....
- //found a way
- if (closed_list.Contains(targ_node.my_node))
- {
- BackTracePath();
- FollowPath();
- }
- ....
- }
- #region path follow
- void FollowPath()
- {
- dest = GetNodePos(current_node);
- node_dist = Vector2.Distance(transform.position, dest);
- if (node_dist>0.3f)
- {
- Debug.Log(node_dist);
- transform.position = Vector3.MoveTowards(transform.position, dest, en_vars.speed * Time.deltaTime);
- transform.rotation= UtilityFunctions.FaceTo(GetNodePos(current_node), transform.position);
- }
- else
- {
- ChangePathNode();
- }
- }
- Vector3 GetNodePos(int n_node)
- {
- return path_nodes[n_node].transform.position;
- }
- void ChangePathNode()
- {
- current_node++;
- if(current_node>=path_nodes.Count)
- {
- current_node = 0;
- }
- }
- #endregion
- }
Advertisement
Add Comment
Please, Sign In to add comment