Unity: Shooter 2D-Character animation only runs once2019 Community Moderator ElectionRun 2 animations at onceHow to get my animation to play in unity when my character jumpsHow to access animation parameters in Unity C#?Maya keyframe animation to unityHow can I stop an animator playing in UnityNot able to Shoot in the direction of the handHow do I delay an animation using my character movement script?Unity character controller script and animatorUnity Play animation after setActive on a hidden layerUnity Animator.Play how to transition to another animation at the same time

Why do phishing e-mails use faked e-mail addresses instead of the real one?

Can I negotiate a patent idea for a raise, under French law?

Is "cogitate" used appropriately in "I cogitate that success relies on hard work"?

PTIJ: Sport in the Torah

Has a sovereign Communist government ever run, and conceded loss, on a fair election?

What can I do if someone tampers with my SSH public key?

std::string vs const std::string& vs std::string_view

Why does a car's steering wheel get lighter with increasing speed

How can I portion out frozen cookie dough?

Giving a talk in my old university, how prominently should I tell students my salary?

Having the player face themselves after the mid-game

Can I challenge the interviewer to give me a proper technical feedback?

Paper published similar to PhD thesis

Can Witch Sight see through Mirror Image?

Is there a math expression equivalent to the conditional ternary operator?

Why would /etc/passwd be used every time someone executes `ls -l` command?

How to distinguish easily different soldier of ww2?

If nine coins are tossed, what is the probability that the number of heads is even?

Unfamiliar notation in Diabelli's "Duet in D" for piano

Precision notation for voltmeters

How would an energy-based "projectile" blow up a spaceship?

ESPP--any reason not to go all in?

How to install "rounded" brake pads

Why isn't P and P/poly trivially the same?



Unity: Shooter 2D-Character animation only runs once



2019 Community Moderator ElectionRun 2 animations at onceHow to get my animation to play in unity when my character jumpsHow to access animation parameters in Unity C#?Maya keyframe animation to unityHow can I stop an animator playing in UnityNot able to Shoot in the direction of the handHow do I delay an animation using my character movement script?Unity character controller script and animatorUnity Play animation after setActive on a hidden layerUnity Animator.Play how to transition to another animation at the same time










0















I wanted my animation to play whenever my character shoots the gun but currently the animation runs only when it fires the first time and not the others. I have the impression that it will be something very simple in the code but I have been around here and still have not found a solution. Can someone give me a hint, please?



Here is the animation part in the code:



private Animator myAnimator;
private bool isFire;
private string FireAnimHash = "isFire";

void Awake()

spriteRend = GetComponent<SpriteRenderer>();


void Start()

myAnimator = GetComponent<Animator>();
myAnimator.enabled =true;
myAnimator.SetBool (FireAnimHash ,isFire);


private void Update()
{

AimArmAtMouse();


if (Input.GetButtonDown("Fire1"))

isFire = true;
myAnimator.SetBool (FireAnimHash ,isFire);










share|improve this question






















  • Did you mean to have two opening braces under your Update method?

    – Eliasar
    2 days ago











  • Eliasar, that s not all the code of this script ...only the Animation parte...i have other functions in the same script...

    – tigrev
    2 days ago















0















I wanted my animation to play whenever my character shoots the gun but currently the animation runs only when it fires the first time and not the others. I have the impression that it will be something very simple in the code but I have been around here and still have not found a solution. Can someone give me a hint, please?



Here is the animation part in the code:



private Animator myAnimator;
private bool isFire;
private string FireAnimHash = "isFire";

void Awake()

spriteRend = GetComponent<SpriteRenderer>();


void Start()

myAnimator = GetComponent<Animator>();
myAnimator.enabled =true;
myAnimator.SetBool (FireAnimHash ,isFire);


private void Update()
{

AimArmAtMouse();


if (Input.GetButtonDown("Fire1"))

isFire = true;
myAnimator.SetBool (FireAnimHash ,isFire);










share|improve this question






















  • Did you mean to have two opening braces under your Update method?

    – Eliasar
    2 days ago











  • Eliasar, that s not all the code of this script ...only the Animation parte...i have other functions in the same script...

    – tigrev
    2 days ago













0












0








0








I wanted my animation to play whenever my character shoots the gun but currently the animation runs only when it fires the first time and not the others. I have the impression that it will be something very simple in the code but I have been around here and still have not found a solution. Can someone give me a hint, please?



Here is the animation part in the code:



private Animator myAnimator;
private bool isFire;
private string FireAnimHash = "isFire";

void Awake()

spriteRend = GetComponent<SpriteRenderer>();


void Start()

myAnimator = GetComponent<Animator>();
myAnimator.enabled =true;
myAnimator.SetBool (FireAnimHash ,isFire);


private void Update()
{

AimArmAtMouse();


if (Input.GetButtonDown("Fire1"))

isFire = true;
myAnimator.SetBool (FireAnimHash ,isFire);










share|improve this question














I wanted my animation to play whenever my character shoots the gun but currently the animation runs only when it fires the first time and not the others. I have the impression that it will be something very simple in the code but I have been around here and still have not found a solution. Can someone give me a hint, please?



Here is the animation part in the code:



private Animator myAnimator;
private bool isFire;
private string FireAnimHash = "isFire";

void Awake()

spriteRend = GetComponent<SpriteRenderer>();


void Start()

myAnimator = GetComponent<Animator>();
myAnimator.enabled =true;
myAnimator.SetBool (FireAnimHash ,isFire);


private void Update()
{

AimArmAtMouse();


if (Input.GetButtonDown("Fire1"))

isFire = true;
myAnimator.SetBool (FireAnimHash ,isFire);







unity3d animation unityscript animator






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 2 days ago









tigrevtigrev

75




75












  • Did you mean to have two opening braces under your Update method?

    – Eliasar
    2 days ago











  • Eliasar, that s not all the code of this script ...only the Animation parte...i have other functions in the same script...

    – tigrev
    2 days ago

















  • Did you mean to have two opening braces under your Update method?

    – Eliasar
    2 days ago











  • Eliasar, that s not all the code of this script ...only the Animation parte...i have other functions in the same script...

    – tigrev
    2 days ago
















Did you mean to have two opening braces under your Update method?

– Eliasar
2 days ago





Did you mean to have two opening braces under your Update method?

– Eliasar
2 days ago













Eliasar, that s not all the code of this script ...only the Animation parte...i have other functions in the same script...

– tigrev
2 days ago





Eliasar, that s not all the code of this script ...only the Animation parte...i have other functions in the same script...

– tigrev
2 days ago












3 Answers
3






active

oldest

votes


















-1














Actually, you use Triggers, not bools, when animating these types of animations, which become true and then false.
Copy the below script and change the variable type to trigger from bool in animator tab in unity.
It should work.



 private Animator myAnimator;
private string FireAnimHash = "isFire";

void Awake()

spriteRend = GetComponent<SpriteRenderer>();


void Start()

myAnimator = GetComponent<Animator>();
myAnimator.enabled = true;


private void Update()

AimArmAtMouse();

if (Input.GetButtonDown("Fire1"))

myAnimator.SetTrigger(FireAnimHash);







share|improve this answer










New contributor




Naresh Bisht is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Sorry, this game its my hobby...im working late last night...i only tried this code now....but now its not shooting at all...i have to get more closer to the code to see my mistake...

    – tigrev
    yesterday











  • you have to change the variable to trigger from bool

    – Naresh Bisht
    yesterday











  • Go to animator tab and add a trigger variable in properties tab of animator and rename that variable to isFire. Delete the already created bool isFire and then run the script it should work. Suppose u want to go to Fire state from ideal state when FireAnimHash Trigger is pulled then make transistion from ideal to Fire and set the condition to isFire and make anathor transition from Fire to ideal state with no condition in it and dont edit HasExitTime. HasExitTime has to be checked. Try this it will work.

    – Naresh Bisht
    yesterday












  • Thank you , @Naresh Bisht. I Will try in my lunch hour and give feedback...

    – tigrev
    yesterday











  • .i did like you said and change the variable but now he plays the animation only once and before i click the mouse...and nothing more....when i click the mouse there is no animation now...

    – tigrev
    yesterday


















0














I don't know if your isFire is set to false after playing the shooting animation. If it has been true, and you have not transitioned it to other animations in the mecanim and did not set the animation to loop.






share|improve this answer






























    0














    You either need to set isFire = false somewhere in your code, or you need to use Animator.SetTrigger.




    From Unity's Documentation



    //Attach this script to a GameObject with an Animator component attached.
    //For this example, create parameters in the Animator and name them “Crouch” and
    // “Jump”

    //Apply these parameters to your transitions between states

    //This script allows you to trigger an Animator parameter and reset the other that
    // could possibly still be active. Press the up and down arrow keys to do this.

    using UnityEngine;

    public class Example : MonoBehaviour

    Animator m_Animator;

    void Start()

    //Get the Animator attached to the GameObject you are intending to animate.
    m_Animator = gameObject.GetComponent<Animator>();


    void Update()

    //Press the up arrow button to reset the trigger and set another one
    if (Input.GetKey(KeyCode.UpArrow))

    //Reset the "Crouch" trigger
    m_Animator.ResetTrigger("Crouch");

    //Send the message to the Animator to activate the trigger parameter named "Jump"
    m_Animator.SetTrigger("Jump");


    if (Input.GetKey(KeyCode.DownArrow))

    //Reset the "Jump" trigger
    m_Animator.ResetTrigger("Jump");

    //Send the message to the Animator to activate the trigger parameter named "Crouch"
    m_Animator.SetTrigger("Crouch");








    share|improve this answer






















      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55021966%2funity-shooter-2d-character-animation-only-runs-once%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      -1














      Actually, you use Triggers, not bools, when animating these types of animations, which become true and then false.
      Copy the below script and change the variable type to trigger from bool in animator tab in unity.
      It should work.



       private Animator myAnimator;
      private string FireAnimHash = "isFire";

      void Awake()

      spriteRend = GetComponent<SpriteRenderer>();


      void Start()

      myAnimator = GetComponent<Animator>();
      myAnimator.enabled = true;


      private void Update()

      AimArmAtMouse();

      if (Input.GetButtonDown("Fire1"))

      myAnimator.SetTrigger(FireAnimHash);







      share|improve this answer










      New contributor




      Naresh Bisht is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















      • Sorry, this game its my hobby...im working late last night...i only tried this code now....but now its not shooting at all...i have to get more closer to the code to see my mistake...

        – tigrev
        yesterday











      • you have to change the variable to trigger from bool

        – Naresh Bisht
        yesterday











      • Go to animator tab and add a trigger variable in properties tab of animator and rename that variable to isFire. Delete the already created bool isFire and then run the script it should work. Suppose u want to go to Fire state from ideal state when FireAnimHash Trigger is pulled then make transistion from ideal to Fire and set the condition to isFire and make anathor transition from Fire to ideal state with no condition in it and dont edit HasExitTime. HasExitTime has to be checked. Try this it will work.

        – Naresh Bisht
        yesterday












      • Thank you , @Naresh Bisht. I Will try in my lunch hour and give feedback...

        – tigrev
        yesterday











      • .i did like you said and change the variable but now he plays the animation only once and before i click the mouse...and nothing more....when i click the mouse there is no animation now...

        – tigrev
        yesterday















      -1














      Actually, you use Triggers, not bools, when animating these types of animations, which become true and then false.
      Copy the below script and change the variable type to trigger from bool in animator tab in unity.
      It should work.



       private Animator myAnimator;
      private string FireAnimHash = "isFire";

      void Awake()

      spriteRend = GetComponent<SpriteRenderer>();


      void Start()

      myAnimator = GetComponent<Animator>();
      myAnimator.enabled = true;


      private void Update()

      AimArmAtMouse();

      if (Input.GetButtonDown("Fire1"))

      myAnimator.SetTrigger(FireAnimHash);







      share|improve this answer










      New contributor




      Naresh Bisht is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















      • Sorry, this game its my hobby...im working late last night...i only tried this code now....but now its not shooting at all...i have to get more closer to the code to see my mistake...

        – tigrev
        yesterday











      • you have to change the variable to trigger from bool

        – Naresh Bisht
        yesterday











      • Go to animator tab and add a trigger variable in properties tab of animator and rename that variable to isFire. Delete the already created bool isFire and then run the script it should work. Suppose u want to go to Fire state from ideal state when FireAnimHash Trigger is pulled then make transistion from ideal to Fire and set the condition to isFire and make anathor transition from Fire to ideal state with no condition in it and dont edit HasExitTime. HasExitTime has to be checked. Try this it will work.

        – Naresh Bisht
        yesterday












      • Thank you , @Naresh Bisht. I Will try in my lunch hour and give feedback...

        – tigrev
        yesterday











      • .i did like you said and change the variable but now he plays the animation only once and before i click the mouse...and nothing more....when i click the mouse there is no animation now...

        – tigrev
        yesterday













      -1












      -1








      -1







      Actually, you use Triggers, not bools, when animating these types of animations, which become true and then false.
      Copy the below script and change the variable type to trigger from bool in animator tab in unity.
      It should work.



       private Animator myAnimator;
      private string FireAnimHash = "isFire";

      void Awake()

      spriteRend = GetComponent<SpriteRenderer>();


      void Start()

      myAnimator = GetComponent<Animator>();
      myAnimator.enabled = true;


      private void Update()

      AimArmAtMouse();

      if (Input.GetButtonDown("Fire1"))

      myAnimator.SetTrigger(FireAnimHash);







      share|improve this answer










      New contributor




      Naresh Bisht is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      Actually, you use Triggers, not bools, when animating these types of animations, which become true and then false.
      Copy the below script and change the variable type to trigger from bool in animator tab in unity.
      It should work.



       private Animator myAnimator;
      private string FireAnimHash = "isFire";

      void Awake()

      spriteRend = GetComponent<SpriteRenderer>();


      void Start()

      myAnimator = GetComponent<Animator>();
      myAnimator.enabled = true;


      private void Update()

      AimArmAtMouse();

      if (Input.GetButtonDown("Fire1"))

      myAnimator.SetTrigger(FireAnimHash);








      share|improve this answer










      New contributor




      Naresh Bisht is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this answer



      share|improve this answer








      edited 7 hours ago









      Supa Mega Ducky Momo da Waffle

      2,00441129




      2,00441129






      New contributor




      Naresh Bisht is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      answered 2 days ago









      Naresh BishtNaresh Bisht

      667




      667




      New contributor




      Naresh Bisht is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Naresh Bisht is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Naresh Bisht is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      • Sorry, this game its my hobby...im working late last night...i only tried this code now....but now its not shooting at all...i have to get more closer to the code to see my mistake...

        – tigrev
        yesterday











      • you have to change the variable to trigger from bool

        – Naresh Bisht
        yesterday











      • Go to animator tab and add a trigger variable in properties tab of animator and rename that variable to isFire. Delete the already created bool isFire and then run the script it should work. Suppose u want to go to Fire state from ideal state when FireAnimHash Trigger is pulled then make transistion from ideal to Fire and set the condition to isFire and make anathor transition from Fire to ideal state with no condition in it and dont edit HasExitTime. HasExitTime has to be checked. Try this it will work.

        – Naresh Bisht
        yesterday












      • Thank you , @Naresh Bisht. I Will try in my lunch hour and give feedback...

        – tigrev
        yesterday











      • .i did like you said and change the variable but now he plays the animation only once and before i click the mouse...and nothing more....when i click the mouse there is no animation now...

        – tigrev
        yesterday

















      • Sorry, this game its my hobby...im working late last night...i only tried this code now....but now its not shooting at all...i have to get more closer to the code to see my mistake...

        – tigrev
        yesterday











      • you have to change the variable to trigger from bool

        – Naresh Bisht
        yesterday











      • Go to animator tab and add a trigger variable in properties tab of animator and rename that variable to isFire. Delete the already created bool isFire and then run the script it should work. Suppose u want to go to Fire state from ideal state when FireAnimHash Trigger is pulled then make transistion from ideal to Fire and set the condition to isFire and make anathor transition from Fire to ideal state with no condition in it and dont edit HasExitTime. HasExitTime has to be checked. Try this it will work.

        – Naresh Bisht
        yesterday












      • Thank you , @Naresh Bisht. I Will try in my lunch hour and give feedback...

        – tigrev
        yesterday











      • .i did like you said and change the variable but now he plays the animation only once and before i click the mouse...and nothing more....when i click the mouse there is no animation now...

        – tigrev
        yesterday
















      Sorry, this game its my hobby...im working late last night...i only tried this code now....but now its not shooting at all...i have to get more closer to the code to see my mistake...

      – tigrev
      yesterday





      Sorry, this game its my hobby...im working late last night...i only tried this code now....but now its not shooting at all...i have to get more closer to the code to see my mistake...

      – tigrev
      yesterday













      you have to change the variable to trigger from bool

      – Naresh Bisht
      yesterday





      you have to change the variable to trigger from bool

      – Naresh Bisht
      yesterday













      Go to animator tab and add a trigger variable in properties tab of animator and rename that variable to isFire. Delete the already created bool isFire and then run the script it should work. Suppose u want to go to Fire state from ideal state when FireAnimHash Trigger is pulled then make transistion from ideal to Fire and set the condition to isFire and make anathor transition from Fire to ideal state with no condition in it and dont edit HasExitTime. HasExitTime has to be checked. Try this it will work.

      – Naresh Bisht
      yesterday






      Go to animator tab and add a trigger variable in properties tab of animator and rename that variable to isFire. Delete the already created bool isFire and then run the script it should work. Suppose u want to go to Fire state from ideal state when FireAnimHash Trigger is pulled then make transistion from ideal to Fire and set the condition to isFire and make anathor transition from Fire to ideal state with no condition in it and dont edit HasExitTime. HasExitTime has to be checked. Try this it will work.

      – Naresh Bisht
      yesterday














      Thank you , @Naresh Bisht. I Will try in my lunch hour and give feedback...

      – tigrev
      yesterday





      Thank you , @Naresh Bisht. I Will try in my lunch hour and give feedback...

      – tigrev
      yesterday













      .i did like you said and change the variable but now he plays the animation only once and before i click the mouse...and nothing more....when i click the mouse there is no animation now...

      – tigrev
      yesterday





      .i did like you said and change the variable but now he plays the animation only once and before i click the mouse...and nothing more....when i click the mouse there is no animation now...

      – tigrev
      yesterday













      0














      I don't know if your isFire is set to false after playing the shooting animation. If it has been true, and you have not transitioned it to other animations in the mecanim and did not set the animation to loop.






      share|improve this answer



























        0














        I don't know if your isFire is set to false after playing the shooting animation. If it has been true, and you have not transitioned it to other animations in the mecanim and did not set the animation to loop.






        share|improve this answer

























          0












          0








          0







          I don't know if your isFire is set to false after playing the shooting animation. If it has been true, and you have not transitioned it to other animations in the mecanim and did not set the animation to loop.






          share|improve this answer













          I don't know if your isFire is set to false after playing the shooting animation. If it has been true, and you have not transitioned it to other animations in the mecanim and did not set the animation to loop.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 2 days ago









          GrapesGrapes

          63




          63





















              0














              You either need to set isFire = false somewhere in your code, or you need to use Animator.SetTrigger.




              From Unity's Documentation



              //Attach this script to a GameObject with an Animator component attached.
              //For this example, create parameters in the Animator and name them “Crouch” and
              // “Jump”

              //Apply these parameters to your transitions between states

              //This script allows you to trigger an Animator parameter and reset the other that
              // could possibly still be active. Press the up and down arrow keys to do this.

              using UnityEngine;

              public class Example : MonoBehaviour

              Animator m_Animator;

              void Start()

              //Get the Animator attached to the GameObject you are intending to animate.
              m_Animator = gameObject.GetComponent<Animator>();


              void Update()

              //Press the up arrow button to reset the trigger and set another one
              if (Input.GetKey(KeyCode.UpArrow))

              //Reset the "Crouch" trigger
              m_Animator.ResetTrigger("Crouch");

              //Send the message to the Animator to activate the trigger parameter named "Jump"
              m_Animator.SetTrigger("Jump");


              if (Input.GetKey(KeyCode.DownArrow))

              //Reset the "Jump" trigger
              m_Animator.ResetTrigger("Jump");

              //Send the message to the Animator to activate the trigger parameter named "Crouch"
              m_Animator.SetTrigger("Crouch");








              share|improve this answer



























                0














                You either need to set isFire = false somewhere in your code, or you need to use Animator.SetTrigger.




                From Unity's Documentation



                //Attach this script to a GameObject with an Animator component attached.
                //For this example, create parameters in the Animator and name them “Crouch” and
                // “Jump”

                //Apply these parameters to your transitions between states

                //This script allows you to trigger an Animator parameter and reset the other that
                // could possibly still be active. Press the up and down arrow keys to do this.

                using UnityEngine;

                public class Example : MonoBehaviour

                Animator m_Animator;

                void Start()

                //Get the Animator attached to the GameObject you are intending to animate.
                m_Animator = gameObject.GetComponent<Animator>();


                void Update()

                //Press the up arrow button to reset the trigger and set another one
                if (Input.GetKey(KeyCode.UpArrow))

                //Reset the "Crouch" trigger
                m_Animator.ResetTrigger("Crouch");

                //Send the message to the Animator to activate the trigger parameter named "Jump"
                m_Animator.SetTrigger("Jump");


                if (Input.GetKey(KeyCode.DownArrow))

                //Reset the "Jump" trigger
                m_Animator.ResetTrigger("Jump");

                //Send the message to the Animator to activate the trigger parameter named "Crouch"
                m_Animator.SetTrigger("Crouch");








                share|improve this answer

























                  0












                  0








                  0







                  You either need to set isFire = false somewhere in your code, or you need to use Animator.SetTrigger.




                  From Unity's Documentation



                  //Attach this script to a GameObject with an Animator component attached.
                  //For this example, create parameters in the Animator and name them “Crouch” and
                  // “Jump”

                  //Apply these parameters to your transitions between states

                  //This script allows you to trigger an Animator parameter and reset the other that
                  // could possibly still be active. Press the up and down arrow keys to do this.

                  using UnityEngine;

                  public class Example : MonoBehaviour

                  Animator m_Animator;

                  void Start()

                  //Get the Animator attached to the GameObject you are intending to animate.
                  m_Animator = gameObject.GetComponent<Animator>();


                  void Update()

                  //Press the up arrow button to reset the trigger and set another one
                  if (Input.GetKey(KeyCode.UpArrow))

                  //Reset the "Crouch" trigger
                  m_Animator.ResetTrigger("Crouch");

                  //Send the message to the Animator to activate the trigger parameter named "Jump"
                  m_Animator.SetTrigger("Jump");


                  if (Input.GetKey(KeyCode.DownArrow))

                  //Reset the "Jump" trigger
                  m_Animator.ResetTrigger("Jump");

                  //Send the message to the Animator to activate the trigger parameter named "Crouch"
                  m_Animator.SetTrigger("Crouch");








                  share|improve this answer













                  You either need to set isFire = false somewhere in your code, or you need to use Animator.SetTrigger.




                  From Unity's Documentation



                  //Attach this script to a GameObject with an Animator component attached.
                  //For this example, create parameters in the Animator and name them “Crouch” and
                  // “Jump”

                  //Apply these parameters to your transitions between states

                  //This script allows you to trigger an Animator parameter and reset the other that
                  // could possibly still be active. Press the up and down arrow keys to do this.

                  using UnityEngine;

                  public class Example : MonoBehaviour

                  Animator m_Animator;

                  void Start()

                  //Get the Animator attached to the GameObject you are intending to animate.
                  m_Animator = gameObject.GetComponent<Animator>();


                  void Update()

                  //Press the up arrow button to reset the trigger and set another one
                  if (Input.GetKey(KeyCode.UpArrow))

                  //Reset the "Crouch" trigger
                  m_Animator.ResetTrigger("Crouch");

                  //Send the message to the Animator to activate the trigger parameter named "Jump"
                  m_Animator.SetTrigger("Jump");


                  if (Input.GetKey(KeyCode.DownArrow))

                  //Reset the "Jump" trigger
                  m_Animator.ResetTrigger("Jump");

                  //Send the message to the Animator to activate the trigger parameter named "Crouch"
                  m_Animator.SetTrigger("Crouch");









                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 2 days ago









                  EliasarEliasar

                  718616




                  718616



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55021966%2funity-shooter-2d-character-animation-only-runs-once%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

                      Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

                      List of MPs elected to the English parliament in 1640 (April) Contents List of constituencies and members See also Notes References Navigation menueNational Archives – The Glynde Place ArchivesCobbett's Parliamentary history of England, from the Norman Conquest in 1066 to the year 1803'Aldermen in Parliament', The Aldermen of the City of London: Temp. Henry III – 1912onepage&q&f&#61, false 229