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

                      Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

                      Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

                      How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page