Esempio n. 1
0
    /// <summary>
    /// Retrieves all the neighbors of this cell and adds them to the neighbors list
    /// </summary>
    private void GetNeighbors()
    {
        //The coordinates of this cell
        IntVector2 position = gameObject.GetComponent <ForestCell>().coordinates;
        //The forest this cell is in
        ForestGenerator forest = gameObject.GetComponentInParent <ForestGenerator>();

        //Check every direction
        for (int i = 0; i < 4; i++)
        {
            //Calculate the coordinates of each direction
            IntVector2 cellToGet = position + ForestDirections.ToIntVector2((Direction)i);

            //If the coordinates calculated are part of the forest, retrieve that cell and add it to the list
            if (forest.ContainsCoordinates(cellToGet))
            {
                ForestCell temp = forest.GetCell(cellToGet);
                neighbors.Add(temp);
            }
        }

        neighborsRetrieved = true;
    }