0
\$\begingroup\$

I've created an animation to animate a swinging mace.

To do this I select the mace object in the scene pane, open the animation pane, and key it at a certain position at 0:00.

I'm prompted to save this animation in my assets folder, which I do, as maceswing

I then rotate the mace, move the slider through time and key it in a different position. I move the slider through time again, move the object to the original position and key it.

There are now three things in my assets folder:

assets folder

maceswing appears to be my animation, but I have no idea what Mace Mace 1 and Mace 2 are. (I've been mucking around trying to get this working so it's possible Mace 1 and Mace 2 are just duplicates of Mace. I still want to know what they are though)

When I play my game, the mace is constantly swinging, even though I didn't apply maceswing to it. I can't stop it. People say there's some kind of tick box to stop it constantly animating but I can't find it.

My mace object only has an Animator component:

enter image description here

Unticking this component doesn't stop the animation playing so I have no idea where the animation is coming from. Or what the Animator component actually does.

I don't want this animation constantly playing. I only want it to play once when someone clicks a certain button:

variable set through GUI

var Mace : Transform;
if(Input.GetButtonDown('Fire1')){
    Mace.animation.Play('maceswing');
};

Upon clicking the 'Fire1' button, I get this error:

MissingComponentException: There is no 'Animation' attached to the "Mace" game object, but a script is trying to access it.
You probably need to add a Animation to the game object "Mace". Or your script needs to check if the component is attached before using it.

There is no 'Animation' attached to the "Mace" game object, and yet I can see it swinging away constantly. Infact I can't stop it! So what's causing the animation if the game object doesn't have an 'Animation' attached to it?

My maceswing animation object:

animation screen

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

When you select a maceswing object you should see an Animation Import Settings in your Inspector. There should be an option called Wrap Mode, which selects a default animation mode:

  • Default - I think it doesn't start the animation, until you do. It's probably what you need now.
  • Once - Runs the animation once and sets it back to start.
  • Loop - runs your animation as looped.
  • Ping Pong - runs your animation as ping-ponged (start->end, then end->start).
  • Clamp Forever - Runs your animation once, but it stays at the end.
\$\endgroup\$
2
  • \$\begingroup\$ Updated question, the maceswing object does not have a wrap mode option, or at least doesn't appear to... \$\endgroup\$
    – Starkers
    Commented Jun 2, 2014 at 20:43
  • \$\begingroup\$ There seems to be some problem with Mecanim animations, try this solution: forum.unity3d.com/threads/… (I didn't test it personally) \$\endgroup\$
    – kolenda
    Commented Jun 3, 2014 at 10:26
0
\$\begingroup\$

To stop the mace from looping (and only swing once when the animation is played), in your last picture there's a checkbox called "Loop Time" (first checkbox). Unclick that.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .