bfs算法在c#in unity中不起作用

bfs算法在c#in unity中不起作用,c#,unity3d,breadth-first-search,C#,Unity3d,Breadth First Search,我有点分散在地图上我想以最快的方式从一点到另一点我有一个代码可以找到从一点到另一点的最短方式但我有一个问题我不明白为什么它不起作用 代码 void FindPath() { Path.Clear(); TargetNode = GetClosestNodeTo(Target); ClosestNode = GetClosestNodeTo(transform); if (TargetNode == null || ClosestNode == null)

我有点分散在地图上我想以最快的方式从一点到另一点我有一个代码可以找到从一点到另一点的最短方式但我有一个问题我不明白为什么它不起作用

代码

void FindPath()
{
    Path.Clear();
    TargetNode = GetClosestNodeTo(Target);
    ClosestNode = GetClosestNodeTo(transform);
    if (TargetNode == null || ClosestNode == null)
    {
        return;
    }
    HashSet<NodeScript> VisetedNodes = new HashSet<NodeScript>();
    Queue<NodeScript> Q = new Queue<NodeScript>();
    Dictionary<NodeScript, NodeScript> nodeAndParent = new 
    Dictionary<NodeScript, NodeScript>();
    Q.Enqueue(ClosestNode);
    while (Q.Count > 0)
    {
        Debug.Log("2");
        NodeScript n = Q.Dequeue();
        if(n.Equals(TargetNode))
        {
            Debug.Log("3");
            MakePath(nodeAndParent);
            return;
        }
        foreach(var node in n.connectedTo)
        {
            if(! VisetedNodes.Contains(node))
            {
                    VisetedNodes.Add(node);
                    nodeAndParent.Add(node, n);
                    Q.Enqueue(node);
            }
        }
    }
}
void FindPath()
{
Path.Clear();
TargetNode=GetClosestNodeTo(目标);
ClosestNode=GetClosestNodeTo(转换);
if(TargetNode==null | | ClosestNode==null)
{
返回;
}
HashSet VisetedNodes=新HashSet();
队列Q=新队列();
Dictionary nodeAndParent=新建
字典();
Q.排队(ClosestNode);
而(Q.Count>0)
{
Debug.Log(“2”);
NodeScript n=Q.Dequeue();
if(n.Equals(TargetNode))
{
Debug.Log(“3”);
生成路径(nodeAndParent);
返回;
}
foreach(n.connectedTo中的var节点)
{
如果(!VisetedNodes.Contains(node))
{
添加(节点);
添加(节点,n);
排队(节点);
}
}
}
}
GetClosestPointTo函数查找最接近特定对象的点

MakePath函数将节点添加到路径列表中

路径列表包含玩家从一点到另一点必须通过的点


我试图找出问题所在,发现代码没有在第一个节点中输入if,而实际上在哪里向每个节点添加连接?目前,我看不到连接到节点的
设置位置。这在检查员的房间里吗?另外,如果没有特别输入哪个if语句?我想目前还没有人报名。