Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Dead Animation

Discussion in 'Getting Started' started by badassgamer, Jun 22, 2015.

  1. badassgamer

    badassgamer

    Joined:
    Apr 26, 2015
    Posts:
    140


    1. Code (JavaScript):
      1. #pragma strict
      2. var Health = 100;
      3. function Update ()
      4. {
      5. if(Health <= 0)
      6. {
      7.   Dead();
      8. }
      9. }
      10. function ApplyDammage (TheDammage : int)
      11. {
      12. Health = Health - TheDammage;
      13. }
      14. function Dead()
      15. {
      16. Destroy (gameObject);
      17. }
      18. [*]
      19. I created a dead animation for the enemy model now when i start the game my enemys fells down (Performing dead Animation)but i want to play it when his health comes to 0 so how to write that script? and also my previous script was just destroy game object like just making enemy disaapear after his health comes to 0 but i want to replace it with dead animation . at the top is my previous script. and people recommed me to use code tag so i tried to add tag on insert icon. if its wrong iam sorry
      20. [/LIST]
     
  2. badassgamer

    badassgamer

    Joined:
    Apr 26, 2015
    Posts:
    140
    i wrote my message here cause it only allow me to write script in code tag and I created a dead animation for the enemy model now when i start the game my enemy fells down (Performing dead Animation)but i want to play it when his health comes to 0 so how to write that script? and also my previous script was just destroy game object like just making enemy disaapear after his health comes to 0 but i want to replace it with dead animation . at the top is my previous script. and people recommed me to use code tag so i tried to add tag on insert icon so if its wrong iam sorry
     
  3. Junglebiscuit

    Junglebiscuit

    Joined:
    Mar 21, 2015
    Posts:
    6
    Something like this:

    Code (JavaScript):
    1. #pragma strict
    2. var Health = 100;
    3. var animationDie : AnimationClip; // Drag your animation from the project view in here (to inspector)
    4.  
    5. function ApplyDammage (TheDammage : int)
    6. {
    7.      Health -= TheDammage;
    8.      if(Health <= 0)
    9.     {
    10.         Dead();
    11.      }
    12. }
    13. function Dead()
    14. {
    15.      animation.Play(animationDie.name);
    16.      Destroy(this.gameObject, animationDie.length);
    17. }
    18.  
     
    badassgamer likes this.
  4. badassgamer

    badassgamer

    Joined:
    Apr 26, 2015
    Posts:
    140
    Code (CSharp):
    1. #pragma strict
    2. var Health = 100;
    3. var animationDie : AnimationClip; // dead animation 1;
    4. function Update ()
    5. {
    6. if(Health <= 0)
    7. {
    8.   Dead();
    9. }
    10. }
    11. function ApplyDammage (TheDammage : int)
    12. {
    13. Health = Health - TheDammage;
    14. }
    15. function Dead()
    16. {
    17. animation.Play(animationDie).("dead animation1");
    18.      Destroy(this.gameObject, animationDie.length);
    19. }
    so i got 2 errors after this code . is my code right? the errors are
    "Assets/enemyshealth.js(17,31): UCE0001: ';' expected. Insert a semicolon at the end."
    "Assets/enemyshealth.js(17,30): BCE0043: Unexpected token: .".
     
  5. Junglebiscuit

    Junglebiscuit

    Joined:
    Mar 21, 2015
    Posts:
    6
    You didn't need to add any code to it, just drag in your animation on the inspector
     
    badassgamer likes this.
  6. badassgamer

    badassgamer

    Joined:
    Apr 26, 2015
    Posts:
    140
    thank you your code worked and one more thing after playing death animation the enemy diappeared but i do like to make him lie on the floor dead instead if dissapearing
     
  7. Junglebiscuit

    Junglebiscuit

    Joined:
    Mar 21, 2015
    Posts:
    6
    Try commenting out the destroy line 16 of my original post.
    If it loops then just stop the animation instead of destroying the object.
     
  8. badassgamer

    badassgamer

    Joined:
    Apr 26, 2015
    Posts:
    140
    Code (JavaScript):
    1. #pragma strict
    2. var Health = 100;
    3. var animationDie : AnimationClip; // Drag your animation from the project view in here (to inspector)
    4. function ApplyDammage (TheDammage : int)
    5. {
    6.      Health -= TheDammage;
    7.      if(Health <= 0)
    8.     {
    9.         Dead();
    10.      }
    11. }
    12. function Dead()
    13. {
    14.      GetComponent.<Animation>().Play(animationDie.name);
    15. GetComponent.<Animation>().Stop(this.gameObject, animationDie.length);
    16. }
    17.  
    well i removed destroy from code but got error and so added stop at the last line but still didnt work . got errors.