Example #1
0
    void Start()
    {
        // Get map points
        for (int i = 0; i < nav_map_points_parent.transform.childCount; i++)
        {
            GameObject current_point_go = nav_map_points_parent.transform.GetChild(i).gameObject;

            NavigationPoint np = current_point_go.GetComponent <NavigationPoint>();
            np.nav_map = this;

            List <GameObject> nb = np.GetNeighbours();

            for (int y = 0; y < nb.Count; y++)
            {
                NavigationPoint npn = nb[y].GetComponent <NavigationPoint>();

                if (!npn.IsNeighbour(current_point_go))
                {
                    npn.AddBeighbour(current_point_go);
                }
            }

            points.Add(current_point_go);
        }

        grid = TransformMapToGrid(GetPoints(), size_x, size_y);
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        Debug.DrawLine(new Vector3(transform.position.x + (tile_size / 2), transform.position.y, transform.position.z + (tile_size / 2)),
                       new Vector3(transform.position.x + (tile_size / 2), transform.position.y, transform.position.z - (tile_size / 2)), Color.green);

        Debug.DrawLine(new Vector3(transform.position.x - (tile_size / 2), transform.position.y, transform.position.z + (tile_size / 2)),
                       new Vector3(transform.position.x - (tile_size / 2), transform.position.y, transform.position.z - (tile_size / 2)), Color.green);

        Debug.DrawLine(new Vector3(transform.position.x + (tile_size / 2), transform.position.y, transform.position.z - (tile_size / 2)),
                       new Vector3(transform.position.x - (tile_size / 2), transform.position.y, transform.position.z - (tile_size / 2)), Color.green);

        Debug.DrawLine(new Vector3(transform.position.x + (tile_size / 2), transform.position.y, transform.position.z + (tile_size / 2)),
                       new Vector3(transform.position.x - (tile_size / 2), transform.position.y, transform.position.z + (tile_size / 2)), Color.green);

        List <GameObject> neig = GetNeighbours();

        for (int i = 0; i < neig.Count; i++)
        {
            NavigationPoint np = neig[i].GetComponent <NavigationPoint>();

            if (!np.IsNeighbour(gameObject))
            {
                return;
            }

            Debug.DrawLine(new Vector3(transform.position.x, transform.position.y, transform.position.z),
                           new Vector3(neig[i].transform.position.x, neig[i].transform.position.y, neig[i].transform.position.z), Color.red);
        }
    }