Grid Color is not the same

Hi

My grid is not showing the change in color the same way.

As you can see from my console there is nothing being printed to go on. I have added the Debug’s to my create label as per the below

Assuming my gridsize is weird I created the debug there aswell and nothing pops up in the console. I have retyped Gary’s code as well for all three scripts

I am not sure why the color is not the same and my debug’s are not even displaying my gridSize var

Any ideas ?

public class Pathfinder : MonoBehaviour

{

[SerializeField] Node currentSearchNode;
Vector2Int[] directions = { Vector2Int.right, Vector2Int.left, Vector2Int.up, Vector2Int.down };
Gridmanager gridmanager;
Dictionary<Vector2Int, Node> grid;

void Awake()
{
gridmanager = FindObjectOfType();
if(gridmanager != null )
{
grid = gridmanager.Grid;

    }
}

void Start()
{
    ExploreNeighbors();
  


}

void ExploreNeighbors()
{
    List<Node> neighbors = new List<Node>();

    foreach (Vector2Int direction in directions)
    {
        var neighborCoords = currentSearchNode.coordinates + direction;

        
    }
}

}

Grid Manager

public class Gridmanager : MonoBehaviour
{

[SerializeField] Vector2Int gridSize;
Dictionary<Vector2Int, Node> grid = new Dictionary<Vector2Int, Node>();
public Dictionary<Vector2Int , Node > Grid { get { return grid; } }

 void Awake()
{
    CreateGrid();
    Debug.Log(gridSize);
}





public Node GetNode(Vector2Int coordinates)
{
    if(grid.ContainsKey(coordinates))
    {
        return grid[coordinates]; 
    }
    return null;

}








void CreateGrid()
{

    for(int x = 0; x < gridSize.x; x++)
    {
       
        for(int y = 0; y < gridSize.y; y++)
        {
            Vector2Int coordinates = new Vector2Int(x, y);
            grid.Add(coordinates, new Node(coordinates, true));
            Debug.Log(grid[coordinates].coordinates + " = " + grid[coordinates].isWalkable);


        }

    }

    Debug.Log(gridSize);
}

Hi Andries,

In the CreateGrid() method, we create an “imaginary” grid starting at (x = 0, y = 0). We use that “imaginary” grid for our game. That’s why the coordinates in the scene must match that grid. No coordinate must be lower than 0.

Move your “Environment” game object, so its bottom left corner is at (0, 0).

Did this fix the problem?


See also:

Hi Ok

So my pivit is way off where 0,0 starts

How do I get the mesh to center on the transform ?

I created a empty object and parented my Path and world tiles to it but they are way below the actual point in the scene.

As you can see from the picture the pivot is at the castle and the mesh despite being on 0.0.0 is noware close

Also I need to make sure that 0,0 is the lowest tile. So -1,0 is bad out of grid create right

I almost feel like I need to set everything to a single Global origin if you understand my meaning

First of all, set the position of the GameObject to (0, 0, 0). Then select all children and move them until the bottom left waypoint is at (0, 0, 0).

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms