Я разрабатываю 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#
Место общения программистов C#
1750513516
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.
Подробнее здесь: [url]https://stackoverflow.com/questions/79674436/switch-case-error-no-enclosing-loop-out-of-which-to-break-or-continue[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия