Ошибка переключения корпуса: без вложения цикла, из которого можно сломаться или продолжитьC#

Место общения программистов C#
Ответить Пред. темаСлед. тема
Anonymous
 Ошибка переключения корпуса: без вложения цикла, из которого можно сломаться или продолжить

Сообщение Anonymous »

Я разрабатываю 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
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C#»