How do I fix animation from autoplaying when I press play?

I have went through this lesson multiple times, and am unable to catch what I am doing wrong. The animation auto plays and doesn’t work with the left mouse button that I set as the trigger. How do I fix this?

Things I have done:

  1. Set Binding to Left Button Mouse
  2. Unchecked Has Exit Time and 0 Duration for three transitions
  3. Added Conditions
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Sword : MonoBehaviour
{

    private PlayerControls playerControls;
    private Animator myAnimator;

    private void Awake()
    {
        myAnimator = GetComponent<Animator>();
        playerControls = new PlayerControls();


    }

    private void OnEnable()
    {
        playerControls.Enable();
    }
    void Start()
    {
        playerControls.Combat.Attack.started += _ => Attack();
    }

    private void Attack()
    {
        //fire our sword animation
        myAnimator.SetTrigger("Attack");
    }
}

What does the animator look like? If you have the animation set as the default it will play immediately.

1 Like

When I have the Sword game object selected it only shows the Base Layer. After I add another layer and put the base layer with all of the animation elements under it, it doesn’t auto play, but then it also doesn’t work when I click the left mouse button. So possibly progress.

What does the animator look like? You character has the animations. Can you share a screenshot?

Sorry didn’t see the option to add a screenshot at first.



Can you share the inspector on the transition from the Entry State (the orange one) to the Swing Down animation? Additionally, set’s see the Parameters tab of the Animator rather than the Layers tab. We really won’t be using the Layers tab in this animator as the Layers are really more suited for working with 3d Skinned Mesh skeletons.


Here you go. Thanks to both of you for looking into this for me.

image
This is already triggered. Unset the trigger and try again

I did try that previously which does stop it from auto playing but the left mouse button won’t trigger it.

This indicates a new issue. Do you have the Sword script on the Sword?

I do.

I have switched the binding to my spacebar and that is working! So looks like it has something to do with the Left Mouse binding that is not working.

Last update: I figured out the mouse issue. Since I was in Simulator and chose phone it wasn’t registering a mouse because phones don’t have one facepalm

Thank you for the trigger information as that fixed the first issue. Appreciate y’all taking your time again with this.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms