Search Unity

Bug Unity Crashes when I write this code- why won't it work?

Discussion in 'Animation' started by GooseInShoe, Jul 16, 2022.

  1. GooseInShoe

    GooseInShoe

    Joined:
    Jul 12, 2022
    Posts:
    3
    Essentially, what I want to do is make sure my "take damage" animation to play fully before it stops. So here I'm trying to wait until the hurt animation ends before I set the took_damage to false. However, whenever I run this, and the thing takes damage, it just crashes the editor. Ideas? Help? upload_2022-7-16_13-35-14.png
     
  2. GooseInShoe

    GooseInShoe

    Joined:
    Jul 12, 2022
    Posts:
    3
    If you need any other info- just ask. :)
     
  3. renem

    renem

    Joined:
    Sep 19, 2014
    Posts:
    3
    Hi, your code will get stuck in the while loop. Make your takeDamage method a coroutine and add "yield return new WaitForSeconds" to your while loop. With best regards
     
  4. GooseInShoe

    GooseInShoe

    Joined:
    Jul 12, 2022
    Posts:
    3
    what's a coroutine