Inconsistency with UI button starting anim

Hi all,

Not sure if this goes more under animations or UI since it incorporates both. I’m getting some inconsistency without doing anything different between runtimes. I’m trying to have the user click a UI button (LeftButton), which then rotates the player to face the left. I’ll go through everything I have set up in hopes that someone might be able to point out what I’m doing wrong.

-On the LeftButton inspector, I have the OnClick() menu activated with Player(UI Manager) in the dialog box and then the function UIManager.LeftButton selected.

-On the Player inspector, I have UI manager script as a component with the Anim object as PlayerTurnAnim (Animator).

-Also on the Player inspector, I have an Animator component with controller being PlayerTurn and the rest of the settings default.

-I have an empty object in which I have put the PlayerTurnAnim animator with the PlayerTurn being the controller.

-When looking at the Animator for PlayerTurn, I have the state PlayerStraight as the default, with a transition to LeftTurnPlayer. This transition occurs when the LeftTurnBool is true (it starts off as false). The LeftTurnPlayer does have the animation to actually turn the player left attached.

-Here is my UIManager script:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class UIManager : MonoBehaviour {

    public Animator PlayerTurn;


    void Start () {
        PlayerTurn.GetComponent<Animator>();
   
    }
   

    void Update () {
   
    }

    public void LeftButton()
    {
        PlayerTurn.SetBool("LeftTurnBool", true);
    }
}

OK so here’s what I’m seeing – 3 independent problems, one of which occurs when all of the above are set up like I described:

  1. When watching the animator, the PlayerStraight default state does not even start running at the beginning of the runtime. This seems to be able to be fixed by clicking on a couple of things in the hierarchy and trying again.
    After I “fix” the above (maybe by giving it more time before trying to run it?), either 2 or 3 occurs.
  2. Animation works, button does not: The animator loops on the PlayerStraight state even when I click the LeftButton. If I manually click the LeftTurnBool within the animator, the animation works and the player turns left.
  3. Button works, animation does not: The animator loops on PlayerStraight until I click LeftButton, at which point LeftTurnBool becomes checked and the state transitions to LeftTurnPlayer. However, the animation does not work and the player stays straight.

This has stumped me for quite a while. I would really appreciate any help. Please let me know if you need any more information. Thanks!

… so you have 3 animators trying to control this? that doesn’t sound right at all. Generally you have a single Animator controlling multiple states which each have the various animationClips assigned to them…

As far as I can tell there is only one animator, which is PlayerTurnAnim. The controller assigned to it is PlayerTurn. PlayerStraight and LeftTurnPlayer are the two states I have so far. Does that seem right to you or can I simplify the animation further?