Problem with an animation transition

by velaskus   Last Updated October 09, 2019 16:13 PM - source

I'm working with a 3D avatar and it's my first time working with animations, but I have already done one which goes from the idle animation to another animation. It does the transition when the value of a slidebar is below 40, here is the code:

 Animator anim;
 public Slider barraAlimento;
 void Start()
 {
     anim = GetComponent<Animator>();
 }
 void Update()
 {
     if (barraAlimento.value <= 40)
     {
         anim.SetBool("IrHambriento", true);
     }
     else
     {
         anim.SetBool("IrHambriento", false);
     }
 }

This works correctly, but my problem is that now I want to do another transition. When I click a button, the value of the slidebar increases (that's how is triggered the previous animation), so I want a transition between the previous animation and the new one when the button is pressed. I have tried this, but it doesn't work:

Animator anim;
 public Button botonManzana;
 void Start()
 {
     anim = GetComponent<Animator>();
     botonManzana.onClick.AddListener(ButtonManzanaClicked);
 }
 void ButtonManzanaClicked()
 {
     anim.SetBool("IrComiendo", true);
     anim.SetBool("IrComiendo", false);
 }

The boxes and arrows are like this, if that's useful information.enter image description here



Related Questions




Animation Not Play Second time?

Updated August 09, 2019 14:13 PM

Convert the animation inside FBX into Unity

Updated November 24, 2017 01:13 AM

Unity Blend Tree Animations wont trigger

Updated December 26, 2018 07:13 AM