Я разрабатываю 2D -игру Unity, и у меня возникает проблема, связанная с оператором C#Switch. У меня есть два примера операторов коммутатора, используемых в моей игре: < /p>
switch (itemActions[selectedItem])
{
case "raftPart" :
{
GridPlacement(raftPartGrid, raftPartHighlight, 0, 2, 0);
break;
}
case "consumable" :
{
GridPlacement(consumableGrid, consumableHighlight, -1, 4, 1);
break;
}
}
< /code>
switch (itemType)
{
case "raftPart":
{
itemId = item.GetComponent().raftPartData.id;
//Makes a new collumn if raft isn't placed on an existing collumn
if (-gridPos.x >= raftComposition.Count)
{
raftComposition.Add(new string[] {null, null, null});
}
//Debug.Log($"New part grid position: {gridPos.x}, {gridPos.y}");
raftComposition[-gridPos.x][-gridPos.y] = itemId;
break;
}
case "consumable":
{
itemId = item.GetComponent().consumableData.id;
break;
}
default:
{
Debug.LogError("itemId not assigned because itemType doesn't correspond to any known type");
break;
}
}
< /code>
The difference between these two is that the first one works perfectly fine, while the second one returns this error in the unity console:
Assets\Scripts\Player\RaftMenu.cs(68,112): error CS0139: No enclosing loop out of which to break or continue
< /code>
I seriously can't tell the difference in structure between the two switch statements. I tried removing the braces from the case blocks, removing the breaks themselves which (expectedly) gave a different error and removing the default case. Nothing happened.
Sorry in advance if this is actually really obvious and I wasted your time.
Подробнее здесь: https://stackoverflow.com/questions/796 ... r-continue
Ошибка переключения корпуса: без вложения цикла, из которого можно сломаться или продолжить ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Неустранимая ошибка: «продолжить» не в контексте «цикла» или «переключения».
Anonymous » » в форуме Php - 0 Ответы
- 6 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Httppost: inputdispatcher: «Канал невозможно сломаться и будет утилизироваться!» на Nexus 7
Anonymous » » в форуме JAVA - 0 Ответы
- 5 Просмотры
-
Последнее сообщение Anonymous
-