Я хотел добавить условие, если в мою корутину, и это сломало его < /p>
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Water"))
{
isSwimming = true;
rb.useGravity = false;
rb.velocity = Vector3.zero;
isUnderwater = true;
isFallingToSurface = true; // Start falling to the water surface
}
}
< /code>
IEnumerator decreaseOxygen()
{
while(true)
{
currentOxygenPercent -= 1;
yield return new WaitForSeconds(1);
}
}
// Update is called once per frame
void Update()
{
if (pC.isUnderwater == true)
{
StartCoroutine(decreaseOxygen());
}
else
{
StopCoroutine(decreaseOxygen());
}
< /code>
the first code is the condition for when isUnderwater is active and the second code is how i tried to implement an if condition to start the coroutine, im fairly new to coding so feedback and criticism is welcome
I tried many ways to the best of my ability to fix the problem but i feel like to coroutine is constantly starting in a nanosecond loop which is the reason why the value of the oxygen is depleting so fast
Подробнее здесь: https://stackoverflow.com/questions/794 ... alue-of-ox
Когда я добавляю условие, если в мою коратую, которая запускает снижение значения кислорода, это делает его действительн ⇐ C#
Место общения программистов C#
1738853596
Anonymous
Я хотел добавить условие, если в мою корутину, и это сломало его < /p>
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Water"))
{
isSwimming = true;
rb.useGravity = false;
rb.velocity = Vector3.zero;
isUnderwater = true;
isFallingToSurface = true; // Start falling to the water surface
}
}
< /code>
IEnumerator decreaseOxygen()
{
while(true)
{
currentOxygenPercent -= 1;
yield return new WaitForSeconds(1);
}
}
// Update is called once per frame
void Update()
{
if (pC.isUnderwater == true)
{
StartCoroutine(decreaseOxygen());
}
else
{
StopCoroutine(decreaseOxygen());
}
< /code>
the first code is the condition for when isUnderwater is active and the second code is how i tried to implement an if condition to start the coroutine, im fairly new to coding so feedback and criticism is welcome
I tried many ways to the best of my ability to fix the problem but i feel like to coroutine is constantly starting in a nanosecond loop which is the reason why the value of the oxygen is depleting so fast
Подробнее здесь: [url]https://stackoverflow.com/questions/79418378/when-i-add-a-if-condition-to-my-coroutine-which-starts-a-decrease-in-value-of-ox[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия