Функция While, проверяющая, работает ли анимация, приводит к сбою UnityC#

Место общения программистов C#
Ответить Пред. темаСлед. тема
Anonymous
 Функция While, проверяющая, работает ли анимация, приводит к сбою Unity

Сообщение Anonymous »


I'm working on a two player fighting game, where one player can hit the other player. All hits are marked as a strike or a grab, and when an opponent is hit with a grab I want the opponent to follow the position of the first player for as long as the grab animation is playing(think a seismic toss where one player jumps and comes down, and the other is forced to follow). However, when I try that, Unity crashes (as in "the animations stop running, I can't interact with the editor, and I have to use task manager to close the editor" crashes). If a grab hitbox interacts with a player, the player being hit calls this code:

int grabAnimation = opponent.GetComponent().playerAnim.GetCurrentAnimatorStateInfo(0).shortNameHash; while (opponent.GetComponent().playerAnim.GetCurrentAnimatorStateInfo(0).shortNameHash == grabAnimation) { transform.position = opponent.transform.position + new Vector3(3f * whichSide, 0, 0); stopMoving = true; } TakeDamage(damage); DealKnockback(angle, magnitude); hitstun = damage * 10; comboCounter++; If I replace the while loop with a for loop that goes based on the length of the animation, everything works fine, so I know it's the while loop that's the problem. I could potentially switch this to a for loop, but I need it to stop if the animation gets interrupted, which could be caused by a number of different things.It would be easier to not need to add functionality to a bunch of different areas if I can get this sorted out.

Additionally, I can put anything inside the while loop and it will crash, as I previously commented out everything in the middle and just did Debug.Log("Test") and the game stopped working. (stopMoving just turns off the players movement controls, it doesn't lock them in place, so that shouldn't be an issue).

Finally, the OnCollision that calls this is on a hitbox that is only activated on the player that is performing the attack, so it shouldn't be something where the player who is attacking is also calling this.

Any help is appreciated.


Источник: https://stackoverflow.com/questions/780 ... hing-unity
Реклама
Ответить Пред. темаСлед. тема

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

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

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

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

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • Функция While, проверяющая, работает ли анимация, приводит к сбою Unity
    Anonymous » » в форуме C#
    0 Ответы
    19 Просмотры
    Последнее сообщение Anonymous
  • Свободная проверка, не проверяющая по запросу
    Anonymous » » в форуме C#
    0 Ответы
    19 Просмотры
    Последнее сообщение Anonymous
  • Почему while(end > Begin) не сработало, а while(begin <= end) сработало? [закрыто]
    Anonymous » » в форуме JAVA
    0 Ответы
    121 Просмотры
    Последнее сообщение Anonymous
  • Что означает «делать while (...) {...} while (...)»?
    Anonymous » » в форуме C#
    0 Ответы
    19 Просмотры
    Последнее сообщение Anonymous
  • Что означает «делать while (...) {...} while (...)»?
    Anonymous » » в форуме C#
    0 Ответы
    26 Просмотры
    Последнее сообщение Anonymous

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