C# 尝试检查列表中是否存在坐标,以便我可以忽略
我和一个团队试图进行俄罗斯方块攻击/小组讨论。我做了调试,看到C# 尝试检查列表中是否存在坐标,以便我可以忽略,c#,unity3d,C#,Unity3d,我和一个团队试图进行俄罗斯方块攻击/小组讨论。我做了调试,看到debug.Log(“匹配?”)不可执行。在foreach(vector2不存在)调试工作之前 我怎样才能改变我的剧本 在这部分代码中,我试图获得水平和垂直匹配的单元格 private List<Vector2Int> FindCellNeighbor(int x, int y, List<Vector2Int> matching) { matching.Add(new Vector2I
debug.Log(“匹配?”)代码>不可执行。在foreach(vector2不存在)
调试工作之前
我怎样才能改变我的剧本
在这部分代码中,我试图获得水平和垂直匹配的单元格
private List<Vector2Int> FindCellNeighbor(int x, int y, List<Vector2Int> matching)
{
matching.Add(new Vector2Int(x, y));
List<Vector2Int> exist = new List<Vector2Int>();
foreach (Vector2Int n in exist)
{
if (!n.Equals(matching))
{
Debug.Log("Match?");
if (x >= 0 && x <= height && y >= 0 && y <= width) // checks if cell coordiantes hits the borders
{
if (data[x, y] == data[x + 1, y])
{
matching.AddRange(FindCellNeighbor(x + 1, y, matching));
exist = matching;
Debug.Log("x + 1");
}
if (data[x, y] == data[x - 1, y])
{
matching.AddRange(FindCellNeighbor(x - 1, y, matching));
exist = matching;
Debug.Log("x - 1");
}
if (data[x, y] == data[x, y + 1])
{
matching.AddRange(FindCellNeighbor(x, y + 1, matching));
exist = matching;
Debug.Log("y + 1");
}
if (data[x, y] == data[x, y - 1])
{
matching.AddRange(FindCellNeighbor(x, y - 1, matching));
exist = matching;
Debug.Log("y - 1");
}
}
}
}
return matching;
}
私有列表FindCellNeighbor(int x,int y,列表匹配)
{
添加(新向量2int(x,y));
List exist=新列表();
foreach(矢量2不存在)
{
如果(!n.Equals(匹配))
{
Log(“匹配?”);
如果(x>=0&&x=0&&y)只是一个疑问:它是正确的“x@Andrea它是正确的。(在我试图检查列表中是否有重复项之前它产生了溢出)。这样写对我来说更容易。请注意,这是一个针对Unity.UnityScript!=C#的JavaScript派生。这显然是C#代码。你期望的是什么!n.Equals(匹配)
要做什么?@JohnWu我应该检查exist列表中是否已经存在匹配列表中的任何值。