好的,所以我在循环中有一个循环,我想告诉第一个循环在第二个循环中的if语句为真时继续。以下代码不起作用,但如何使其添加最少的代码。提前致谢!我在Unity3D btw工作。
public void AssignNearby(List<GameObject> _nodeList, GameObject _current)
{
nearby.Clear();
foreach(GameObject node in _nodeList)
{
int nodeId = node.GetComponent<NodeScript>()._ID;
foreach(int allergie in allergies)
{
if(nodeId == allergie || nodeId == identity)
{
continue;
}
}
Vector3 curPos = _current.transform.position;
Vector3 nearPos = node.transform.position;
switch(identity)
{
case 1:
if(nodeId == 5)
{
node.renderer.material.color = Color.black;
nearby.Add(node);
goto case 2;
}
break;
case 2: case 3: case 4: case 6:
if(Mathf.Abs(curPos.x - nearPos.x) + Mathf.Abs(curPos.y - nearPos.y) + Mathf.Abs(curPos.z - nearPos.z) < 2)
{
node.renderer.material.color = Color.black;
nearby.Add(node);
}
break;
case 5:
if(nodeId == 1)
{
node.renderer.material.color = Color.black;
nearby.Add(node);
}
break;
}
}
}
答案 0 :(得分:1)
foreach(GameObject node in _nodeList)
{
int nodeId = node.GetComponent<NodeScript>()._ID;
foreach(int allergie in allergies)
{
if(nodeId != allergie && nodeId != identity)
{
Your code here
}
}
}