0
\$\begingroup\$

I am trying to make an animtion for my Sword so that when I click with my left mouse button, the sword gets swung. I watched a tutorial video and tried to follow all the steps but whats happening is that the Sword animtion gets played automatically in a loop

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Sword : MonoBehaviour {

    void Update () {
        if (Input.GetButtonDown("Fire1"))
        {
            GetComponent<Animation>().Play("Attack");
        }
    }
}

I know this isn't much to work with but maybe someone knows what I could have done wrong in the previous steps

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

Try to go to your animation's asset and set Loop Time value to false. Depending on the type of animation asset, it might be called Wrap Mode, set it to Once in this case.

\$\endgroup\$
3
  • \$\begingroup\$ hey my teacher told me the same thing so I think it'll work, thanks \$\endgroup\$ Commented Sep 18, 2017 at 15:35
  • \$\begingroup\$ ok It did something, it stopped the animation from getting played all the time, but now when I press "Fire", the game pauses \$\endgroup\$ Commented Sep 18, 2017 at 15:54
  • \$\begingroup\$ That's really weird. I don't think it's caused by this script. \$\endgroup\$ Commented Sep 18, 2017 at 22:16
0
\$\begingroup\$

I got it to work now. The game pausing everytime I swung the sword, was because in the console, error pause was on, so everytime an error occurs, the game pauses.

And one of the errors was telling me something about it having to be marked as legacy and how to change that is by setting the inspector of the animation to "debug" as shown in the picture

enter image description here

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.